#include <ArduinoJson.h>
#include <Arduino_JSON.h>
uint8_t brightness0 = 50;
uint8_t hue0 = 92;
uint8_t brightness1 = 20;
uint8_t hue1 = 180;
uint8_t brightness2 = 20;
uint8_t hue2 = 180;
String jsonString = "";
char* message = "{\"strip\":\"1\",\"hue\":\"77\",\"sat\":0,\"val\":0}";
// char message2 = "{"strip":"1","hue":"77","sat":0,"val":0}";
// String str1 = "";
// String str2 = "";
JSONVar obj = JSON.parse((char *)message);
JSONVar keys;
JSONVar values;
char k[10][10];
int v[10];
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32-S2!");
}
void loop() {
Serial.print("JSON Type: ");
Serial.println(JSON.typeof(obj));
Serial.print("Object = ");
Serial.println(obj);
keys = obj.keys();
// WORKS - captures the incoming key:value pairs
for(int i = 0; i < keys.length(); i++) {
values = obj[keys[i]];
strcpy(k[i], obj.keys()[i]);
v[i] = (int)values;
Serial.print(k[i]);
Serial.print(":");
Serial.println(v[i]);
}
delay(10000);
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}
// WORKLS
// Serial.println("Objhect type = ");
// Serial.println(JSON.typeof(obj));
// Serial.println("keys[0]: ");
// Serial.println(obj.keys()[0]);
// Serial.println("keys[1]: ");
// Serial.println(obj.keys()[1]);
// WORKS - but does not capture the input
// for(int i = 0; i < keys.length(); i++) {
// values = obj[keys[i]];
// Serial.print(keys[i]);
// Serial.print(":");
// Serial.println(values);
// }
Loading
esp32-s2-devkitm-1
esp32-s2-devkitm-1