#include <ArduinoJson.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
const char* json = "{\"dht\":[{\"t\":24,\"h\":18},{\"t\":23.13,\"h\":59}],\"ntc\":[{\"t\":23.8},{\"t\":24.1},{\"t\":24.18},{\"t\":23.58}]}";
const int capacity = 80 * 10; // sensors
DynamicJsonDocument doc(capacity);
DeserializationError err = deserializeJson(doc, json);
if (err) {
Serial.print(F("deserializeJson() returned "));
Serial.println(err.f_str());
return;
}
//JsonObject repo0 = doc;
float t = doc["dht"][0]["t"];
float h = doc["dht"][0]["h"];
Serial.println(t);
Serial.println(h);
JsonArray arr = doc["dht"].as<JsonArray>();
int count = arr.size();
Serial.println(count);
int memoryUsed = doc.memoryUsage();
Serial.printf("mem:%d\n",memoryUsed);
//JsonArray& myArray = doc["dht"];
for (int i=0; i<arr.size(); i++) {
JsonObject repo = arr[i];
float t2 = repo["t"];
float h2 = repo["h"];
Serial.printf(" t->%.2f",t2);
Serial.printf(" h->%.2f\n",h2);
// etc.
}
arr = doc["ntc"].as<JsonArray>();
for (int i=0; i<arr.size(); i++) {
JsonObject repo = arr[i];
float t3 = repo["t"];
Serial.printf(" ntc t->%.2f\n",t3);
// etc.
}
/*
JsonArray& scheduleArray = doc["dht"];
for (int i=0; i < scheduleArray.size(); i++){
JsonObject &t = (scheduleArray.get<JsonVariant>(i)).as<JsonObject&>();
float t2 = t["t"]; //doc["dht"][0]["t"];
float h2 = t["h"];
Serial.println(t2);
Serial.println(h2);
}
*/
}//setup
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}