hi everyone
it me nischal ...i m getting some problem regarding json data parsing using arduino and gsm module with module number sim800l. complete code to parse json data from url mentioned in code is shown in attached images. also i have attached respective output that appeared on serial monitor of arduino IDE software. for clear understanding i have point out error which are listed below.
-
when i make comment in line number 69 and 70 shown in attached figure 1, then i got successfully parsed data of id and engine igintion value.... output of this is attached number 3
-
when i make all free(uncomment) then all parsed data that is output becomes null(0) and sometimes it gives error as parsed fail...for this output is shown in attached figure 4
-
i tried to find errors and get some little hints as
please help me little help will be appreciated
[code]#include <SoftwareSerial.h>
SoftwareSerial http(11, 12);
#include <ArduinoJson.h>
String apn = "ntnet";
void setup()
{
//StaticJsonBuffer<200> jsonBuffer;
Serial.flush();
http.begin(4800);
Serial.begin(9600);
http.println("AT+IPR=4800");
http.println("ATE0");
http.println("AT+CTZU=1\r\n ");
delay(500);
//printSerialData();
http.println("AT+CCLK?\r\n");
delay(500);
printSerialData();
http.println("AT+CREG?");
delay(500);
printSerialData();
http.println("AT+SAPBR=3,1,Contype,GPRS");
delay(800);
printSerialData();
//printSerialData();
http.println("AT+SAPBR=3,1,APN," + apn);
delay(800);
printSerialData();
http.println("AT+SAPBR =1,1");
delay(800);
printSerialData();
http.println("AT+SAPBR=2,1");
delay(800);
printSerialData();
http.println("AT+HTTPINIT");
delay(800);
printSerialData();
http.println("AT+HTTPPARA=?");
printSerialData();
http.println("AT+HTTPPARA=CID,1");
delay(800);
printSerialData();
http.println("AT+HTTPPARA=URL, amc.trenzynepal.com/wp-json/wp/v2/device/3828");
delay(2000);
printSerialData();
http.println("AT+HTTPACTION=0");
delay(5000); //variable for no data recieve
printSerialData();
Serial.println("....................................................\n");
http.println("AT+HTTPREAD");
delay(9000);
String data = http.readString();
int len = data.length();
data.remove(0, 17);
Serial.println(len);
data.remove(len - 23, 22);
Serial.println(data);
const size_t capacity = JSON_OBJECT_SIZE(4) + 70;
DynamicJsonBuffer jsonBuffer(capacity);
JsonObject& root = jsonBuffer.parseObject(data);
delay(5000);
if (!root.success())
{
Serial.print("failed");
return;
}
int id = root["id"]; // 3828
bool engine_ignition = root["engine_ignition"]; // true
bool engine_start = root["engine_start"]; // true
bool head_light = root["head_light"]; // true
// Serial.print(".............data.................................................");
// Serial.print("\n");
Serial.print("device id: ");
Serial.println(id);
Serial.flush();
// Serial.print("\n");
Serial.print("engine ignition state: ");
Serial.println(engine_ignition);
Serial.print("\n");
Serial.flush();
// Serial.print("engine start state: ");
// Serial.println(engine_start);
// // // Serial.print("\n");
// // Serial.print("head light state: ");
// Serial.println(head_light);
Serial.print("..................completed......................................");
}
/*********************************************************************************************************************************************************
loop
***********************************************************************************************************************************************************/
void loop()
{
}
/*********************************************************************************************************************************************************
function for disply AT command echo
***********************************************************************************************************************************************************/
void printSerialData()
{
while ((http.available()) != 0)
Serial.write(http.read());
}
[/code]