I need to read JSON data from here and then I have to parse it. I have to extract an Ajax response from this REST API but I'm kinda stuck here. Kindly help me out.
So, I've given my code below. Do have a look at it and tell me how can i read a JSON response for the url. Also, How can I parse it in a string?
enter code here
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ArduinoJson.h>
const char* ssid = "ssid";
const char* password = "password";
const char* host = "tutor4study.com";
const int httpsPort = 80;
WiFiClient client;
WiFiClient readClient;
String sensorValue1 = "5555";
String sensorValue2 = "9999";
String readUrl = "";
char readLine;
String readResponse ="";
String readJsonResponse ="";
void setup() {
Serial.begin(115200);
Serial.println();
Serial.print("connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("connecting to ");
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
// yield();
}
StaticJsonBuffer<200> jsonBuffer;
void readConnect(){
if(!readClient.connect(host,httpsPort)){
Serial.println("connection failed for readCLient");
ESP.reset();
return;
}
readUrl = "/forms/ajaxDeviceValue";
Serial.print("requesting URL: ");
Serial.println(readUrl);
readClient.print(String("GET ")+readUrl+" HTTP/1.1\r\n"+
"Host: "+host+"\r\n"+
"Connection: close\r\n\r\n");
while(readClient.connected()){
readLine = readClient.read();
Serial.print(readLine);
readResponse += readLine;
}
JsonObject& root = jsonBuffer.parseObject(readResponse);
if (!root.success()) {
Serial.println("parseObject() failed");
return;
}
}
void loop() {
readConnect();
}
Thanks!