Skip to content

Commit 01b58bd

Browse files
committed
#11 Adjustments for arduinojson 6
1 parent 3cc5558 commit 01b58bd

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

WifiRGB/WifiRGB.ino

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,14 @@ void handleApiRequest() {
140140
*/
141141

142142
const size_t bufferSize = JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(4) + 70;
143-
DynamicJsonBuffer jsonBuffer(bufferSize);
144-
JsonObject& root = jsonBuffer.parseObject(server.arg("plain"));
143+
DynamicJsonDocument jsonDocument(bufferSize);
144+
deserializeJson(jsonDocument, server.arg("plain"));
145145

146146
Serial.println("JSON Body: ");
147-
root.printTo(Serial);
147+
serializeJson(jsonDocument, Serial);
148148
Serial.println();
149149

150+
JsonObject root = jsonDocument.as<JsonObject>();
150151
const char* state = root["state"]; // "ON" or "OFF"
151152
if(strcmp("OFF", state) == 0) {
152153
Serial.println("State OFF found: switching off");
@@ -165,12 +166,12 @@ void handleApiRequest() {
165166

166167
// DEBUG: color
167168
Serial.print("Color: ");
168-
root["color"].printTo(Serial);
169+
serializeJson(root["color"], Serial);
169170
Serial.println();
170171

171172
RGB rgb = {0, 0, 0};
172-
JsonObject& color = root["color"];
173173

174+
JsonObject color = root["color"];
174175
// If RGB mode: Parse RGB values
175176
if(color["mode"] == "rgb") {
176177
// Indeed, the JsonVariant returned by root["..."] has a special implementation of the == operator that knows how to compare string safely.

0 commit comments

Comments
 (0)