I’m pretty new to Arduino programming, and am trying to parse data from an HTTP Get request from a CC3000. I’ve found several other forum posts elsewhere with a similar subject, but none of them resolves my particular problem. Which is...
I connect to the server fine, it displays the results of the request fin the Serial window, and I can even capture the whole output as a string… But that’s the problem, I don’t know how to capture just the results of the request (which will be a two- or three-digit int) rather than capturing all the HTTP garbage that gets sent also. (such as "HTTP/1.1 200 OK Date: Tue, 07 Jan 2014 10:02:05 GMT Server: Apache”, etc. etc.)
If it helps, the PHP script on the server is here: http://faludidesign.com/TEMP/thermostat/record.php .
The Arduino sends it some variables in the following form: http://faludidesign.com/TEMP/thermostat/record.php?rf=700&af=705&ot=704&h=0&c=1&sh=22
And then the server responds with a number, which is a 2- or 3-digit int. Nothing else. You can see by going to the URL in a browser.
I’m currently getting each character as it comes from the server, and concatenating them into a string (which works), and then trying to read just the last three characters of that string and convert it to an int (which isn’t working). I’ve tried endsWith, toCharArray, strncopy, memcpy, getBytes, none of it works. I’ll get errors like ‘function not declared’, or ‘invalid conversion from ‘int’ to const char*’, or ‘invalid conversion from ‘const char’ to const char*’ or ‘no matching function call to String::toCharArray(String&, int)’, etc.
I’m flailing here. Please help!
If there’s a way to just get the few characters the PHP script on the server sends to the CC3000, that’d be ideal. If not, what’s the best way to get the last three characters of the string & make them an int?
Here’s this section of the code:
while (www.connected()) {
while (www.available()) {
char c = www.read(); //Reads the output of the HTTP Get Request
Serial.print(c);
HTTPoutputString += c; //concatenates each character onto the end of the string as it comes
}
}
www.close();
String Buf;
Buf = HTTPoutputString.substring(60,20);
char Foo = HTTPoutputString.charAt(3);
// DIDN'T WORK: Buf = HTTPoutputString.endswith(6);
// DIDN'T WORK: HTTPoutputString.toCharArray(Buf, 3);
// DIDN'T WORK: strncopy(HTTPoutputString, Buf, 3);
// DIDN'T WORK: HTTPoutputString.getBytes(Buf,1);
// DOESNT'T WORK: memcpy( HTTPoutputString, readString, strlen(readString)+1 ); ;
//HTTPoutputString = readString;
//SetpointHeat = HTTPoutputString;
Serial.print("\nHTTPoutputString: "); Serial.print(HTTPoutputString); Serial.print("\n");
Serial.print("\n\nBuf: "); Serial.print(Buf); Serial.print("\n");
Serial.print("\n\nFoo: "); Serial.print(Foo); Serial.print("\n");
Serial.println(F("-------------------------------------"));
HTTPoutputString = "";
Buf = "";
/* You need to make sure to clean up after yourself or the CC3000 can freak out */
/* the next time your try to connect ... */
Serial.println(F("\n\nDisconnecting"));
cc3000.disconnect();