Now get one json once. I want to pull values all the time.
Code :
#include <ArduinoJson.h>
#include <Ethernet.h>
#include <SPI.h>
#define RBUFFSIZE 600
boolean startCapture;
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
byte ip[] = { 192,168,1,56 };
byte server[] = { 192,168,1,38 };
char responseBuffer[RBUFFSIZE];
int rbindex = 0;
char c;
EthernetClient client;
void setup() {
Ethernet.begin(mac, ip);
Serial.begin(9600);
delay(1000);
Serial.println("connecting...");
int res = client.connect(server, 80);
if (res) {
Serial.println("connected");
client.println("GET /project/send_data.php");
client.println();
} else {
Serial.println("connection failed");
}
}
void loop() {
recive();
}
void recive(){
if(client.connected()){
c = client.read();
if(c == '{') {
startCapture=true;
}
const size_t bufferSize = JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE(8) + 370;
DynamicJsonBuffer jsonBuffer(bufferSize);
if(startCapture && rbindex < RBUFFSIZE) {
responseBuffer[rbindex] = c;
rbindex++;
}
if (!client.connected()) {
Serial.println("Received bytes");
//Serial.print(strlen(responseBuffer));
Serial.println(responseBuffer);
StaticJsonBuffer<500> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(responseBuffer);
Serial.println((char*)root["a1"]);
Serial.println((char*)root["a20"]);
delay(2000);
Serial.println(rbindex);
jsonBuffer.clear();
}
}
}