#include <ArduinoJson.h> // https://arduinojson.org/
// uncomment for debugging
#define DEBUG 1
#ifdef DEBUG
#define DEBUG_PRINT(x) Serial.print (x)
#define DEBUG_PRINTDEC(x) Serial.print (x, DEC)
#define DEBUG_PRINTLN(x) Serial.println (x)
#else
#define DEBUG_PRINT(x)
#define DEBUG_PRINTDEC(x)
#define DEBUG_PRINTLN(x)
#endif
// setup
void setup() {
// serial for debugging
#ifdef DEBUG
Serial.begin(115200);
#endif
// define JSON document
StaticJsonDocument<1024> doc;
// primjer JSON poruke
char payload[] = "{\"msg\":[[\"3.9$\",1,25,1900,2,2,0],[\"22895\",1,25,2100,2,2,1],[\"Good morning\",1,25,2000,2,2,0],[\"Today is a sunny day\",1,25,2000,2,2,0],[\"Hi guys\",1,25,2000,2,2,0],[\"Cheers :)\",1,25,2000,2,2,0],[\"17:19\",1,25,31000,2,2,0]],\"ts\":\"2023-01-24 17:23:37\"}";
// get payload length
unsigned int length = strlen(payload);
DeserializationError error = deserializeJson(doc, payload, length);
if (error) {
DEBUG_PRINTLN("deserializeJson() failed: ");
DEBUG_PRINTLN(error.f_str());
return;
}
// msg JSON array from JSON document
JsonArray msg = doc["msg"];
// open loop
for (unsigned int i = 0; i < msg.size(); i++) {
// get data
const char* text = msg[i][0]; // "22895"
int pos = msg[i][1]; // 1
int speed = msg[i][2]; // 25
int pause = msg[i][3]; // 2100
int effect1 = msg[i][4]; // 2
int effect2 = msg[i][5]; // 2
int smallFont = msg[i][6]; // 1
// print debug
DEBUG_PRINT(text);
DEBUG_PRINT(" ");
DEBUG_PRINT(pos);
DEBUG_PRINT(" ");
DEBUG_PRINT(speed);
DEBUG_PRINT(" ");
DEBUG_PRINT(pause);
DEBUG_PRINT(" ");
DEBUG_PRINT(effect1);
DEBUG_PRINT(" ");
DEBUG_PRINT(effect2);
DEBUG_PRINT(" ");
DEBUG_PRINTLN(smallFont);
}
}
// loop
void loop() {
}