#include <ArduinoJson.h>
int itoa(int number) {
return '0' + number;
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
char json[] = "{\"status\":0,\"data\":[{\"id\":\"52932aaf-5788-11ee-adc4-e2273de3c509\",\"patientId\":\"968166e6-f604-11ed-ba14-0242ac110007\",\"country\":\"CZ\",\"status\":2,\"firstName\":\"David\",\"lastName\":\"Baierle\",\"targetLow\":70,\"targetHigh\":180,\"uom\":0,\"sensor\":{\"deviceId\":\"\",\"sn\":\"MH00QACE6H\",\"a\":1698221033,\"w\":60,\"pt\":3,\"s\":true,\"lj\":false},\"alarmRules\":{\"c\":true,\"h\":{\"on\":true,\"th\":360,\"thmm\":20,\"d\":1440,\"f\":0.1},\"f\":{\"th\":55,\"thmm\":3,\"d\":30,\"tl\":10,\"tlmm\":0.6},\"l\":{\"on\":true,\"th\":65,\"thmm\":3.5,\"d\":1440,\"tl\":10,\"tlmm\":0.6},\"nd\":{\"on\":true,\"i\":10,\"r\":5,\"l\":6},\"p\":5,\"r\":5,\"std\":{}},\"glucoseMeasurement\":{\"FactoryTimestamp\":\"11/3/2023 8:37:13 AM\",\"Timestamp\":\"11/3/2023 9:37:13 AM\",\"type\":1,\"ValueInMgPerDl\":286,\"TrendArrow\":3,\"TrendMessage\":null,\"MeasurementColor\":3,\"GlucoseUnits\":0,\"Value\":15.9,\"isHigh\":false,\"isLow\":false},\"glucoseItem\":{\"FactoryTimestamp\":\"11/3/2023 8:37:13 AM\",\"Timestamp\":\"11/3/2023 9:37:13 AM\",\"type\":1,\"ValueInMgPerDl\":286,\"TrendArrow\":3,\"TrendMessage\":null,\"MeasurementColor\":3,\"GlucoseUnits\":0,\"Value\":15.9,\"isHigh\":false,\"isLow\":false},\"glucoseAlarm\":null,\"patientDevice\":{\"did\":\"b2cc44c9-f604-11ed-8a42-0242ac110002\",\"dtid\":40066,\"v\":\"2.10.1\",\"l\":true,\"ll\":70,\"hl\":365,\"u\":1696578988,\"fixedLowAlarmValues\":{\"mgdl\":60,\"mmoll\":3.3},\"alarms\":true,\"fixedLowThreshold\":0},\"created\":1695195350}],\"ticket\":{\"token\":\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImEzYzk0NGY4LTU3ODMtMTFlZS1hNjI3LTc2MzU2MjBjYTIzYyIsImZpcnN0TmFtZSI6IkRhdmlkIiwibGFzdE5hbWUiOiJCYWllcmxlIDIiLCJjb3VudHJ5IjoiQ1oiLCJyZWdpb24iOiJldSIsInJvbGUiOiJwYXRpZW50IiwidW5pdHMiOjAsInByYWN0aWNlcyI6W10sImMiOjEsInMiOiJsbHUuYW5kcm9pZCIsImV4cCI6MTcxNDU1MjY4NH0.QnzCrsA2iyn26Xi3p0nFj3eM9wlf7fRy6PzlUUaOnz4\",\"expires\":1714552684,\"duration\":15552000000}}";
DynamicJsonDocument doc(10240);
DeserializationError err = deserializeJson(doc, json);
if (err) {
Serial.print(F("deserializeJson() failed with code "));
Serial.println(err.f_str());
}
// JsonObject data_0 = doc["data"][0];
// const char* info = data_0["id"];
const char* info = doc["data"][0]["id"];
Serial.print("ID: ");
Serial.println(info);
const char* info2 = doc["data"][0]["patientId"];
Serial.print("Patient ID: ");
Serial.println(info2);
const char* fn = doc["data"][0]["firstName"];
const char* ln = doc["data"][0]["lastName"];
const char* country = doc["data"][0]["country"];
Serial.printf("Name: %s %s (%s)\n", fn, ln, country);
float tl = doc["data"][0]["targetLow"];
float th = doc["data"][0]["targetHigh"];
Serial.printf("Target: %.1f - %.1f mmol/l\n", tl / 18, th / 18);
const char* sensorID = doc["data"][0]["sensor"]["sn"];
uint sensorActivated = doc["data"][0]["sensor"]["a"];
Serial.printf("Sensor ID: %s, activated %i\n", sensorID, sensorActivated);
const char* dateTime = doc["data"][0]["glucoseMeasurement"]["Timestamp"];
float value = doc["data"][0]["glucoseMeasurement"]["Value"];
Serial.printf("Glucose measurement: %.1f at %s\n", value, dateTime);
const char* token = doc["ticket"]["token"];
Serial.print("Token: ");
Serial.println(token);
uint expir = doc["ticket"]["expires"];
Serial.print("Expiration: ");
Serial.println(expir);
/*
JsonObject obj = doc.as<JsonObject>();
// Loop through all the key-value pairs in obj
for (JsonPair p : obj) {
p.key(); // is a JsonString
p.value(); // is a JsonVariant
if (p.value().is<const char*>()) {
Serial.printf("%s=%s\n", p.key().c_str(), p.value().as<const char*>());
} else if (p.value().is<int>()) {
Serial.printf("%s=%i\n", p.key().c_str(), p.value().as<int>());
} else if (p.value().is<JsonObject>()) {
Serial.printf("%s=%s\n", p.key().c_str(), "Object");
} else if (p.value().is<JsonArray>()) {
Serial.printf("%s=%s\n", p.key().c_str(), "Array");
}
}
*/
}
void loop() {
// put your main code here, to run repeatedly:
delay(1000000); // this speeds up the simulation
}