Sending HTTP GET and parse json
Posted:
Wed Jun 24, 2015 3:38 am
by helpme
I would like to use Arduino IDE to use a standalone ESP8266 to send a HTTP GET. The webpage will return json and ESP8266 needs to parse the json to extract certain values.
How can this be done using Arduino IDE? Any sample code as a start?
Re: Sending HTTP GET and parse json
Posted:
Wed Jun 24, 2015 10:23 pm
by Stephen
Here's a small snippet, the JSON "detection" is pretty simplistic in this case.
Code: Select all client.println("POST /index.php HTTP/1.1");
client.println("Host: post.mofuckr.com");
client.println("User-Agent: Arduino/1.0");
client.println("Connection: close");
client.println("Content-Type: application/x-www-form-urlencoded;");
client.print("Content-Length: ");
client.println(PostData.length());
client.println();
client.println(PostData);
while(client.available())
{
String line = client.readStringUntil('\r');
if (line.indexOf("state\":\"TRUE")) {
Serial.println("Submission Sucessful");
return true;
} else {
Serial.println("Submission Error:");
Serial.println("Error On Server!");
Serial.print(line);
return false;
}
}
}