I send a GET http request to a server and get following data back.
HTTP/1.1 200
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Fri, 16 Nov 2018 16:30:05 GMT
Connection: close
35
{
"uuid" : "13b29524-7e12-48fb-bbf9-4396aefff45d"
}
0
with the following code I get the header info and the body.
void parseResponse() {
boolean headerEnd = false;
byte lineCount = 0;
String line;
char endOfLine[] = "\r\n";
while (1) {
if (client.available()) {
char inChar = client.read();
if (!headerEnd && line.endsWith(endOfLine)) {
// Just save the first then headers
if (lineCount == 10) {
headerEnd = true;
} else {
headers[lineCount] = line;
line = "";
lineCount++;
}
}
if (line.endsWith("close")) {
line = "";
headerEnd = true;
}
if (headerEnd && line.endsWith("}")) {
line.toCharArray(response, sizeof(response));
client.stop();
break;
}
line += inChar;
}
}
}
this thakes 60 - 70ms to parse. Is there a faster way to parse? I think that's slow, for so little text, in the world of AVRs.
boolean
andbyte
forbool
andunsigned char
respectively. Please retag your question.char lastChar = "";
should bechar lastChar = '';
.""
is a string, not a char.lastChar
variable is never used for anything, why do you keep assigning it?