Hello,
I did quite some googling on this but not able to find out what's going wrong. I followed the guidelines in this post:
http://forum.arduino.cc/index.php?topic=44890.0 I have this function that extracts the HTTP-status and -version from a GET-response that I received from a webserver.
This is the actual parse-function (which is in a CPP-file where the rest of the class is also defined):
void xBee::parseHTTPResponse(struct httpresponse* response) {
char* statusLine;
char* cr = "\13";
// First, extract only the part until the first CRLF
statusLine = strtok(_respBuffer, cr);
char* httpVersion;
httpVersion = strtok(statusLine, " "); // This is like "HTTP/1.1"
response->status = atoi(strtok(NULL, " ")); // This should be like 200, 403 or such
// Parse the version
strtok(httpVersion, "/"); // This is "HTTP", ignore
strcpy(response->version, strtok(NULL, "/")); // Get the version
}
The struct is defined in a H-file with the same name as the CPP-file.
The struct is defined as:
typedef struct httpresponse {
char version[3];
int status;
}
Everything compiles OK.
When I put debug-breaks in I get the right results (inside the function), eg. status=200 and version="1.1". However, the calling program gets only zero's.
(The variable "_respBuffer" is a private 64-char in the class where the response from the webserver is stored).
In the calling program I have:
httpresponse httpResult;
and the actual call:
xb->parseHTTPResponse(&httpResult);
After the call a Serial.println(httpResult.status) will always return "0" (although, as said, in the function 'response->status' was 200, which is correct).
Any thoughts?