Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ The circuit uses an LD1117V33 voltage regulator with two capacitors as specified
## Code
### Dependencies
The mentioned versions are tested, other may work as well but may lead to compile issues.
* [esp8266 v.2.4.2](https://github.com/esp8266/Arduino)
* [ArduinoJSON v.5.13.3](https://github.com/bblanchon/ArduinoJson)
* [esp8266 v.2.4.2](https://github.com/esp8266/Arduino)
* [ArduinoJSON v.6.13.0](https://github.com/bblanchon/ArduinoJson)

### Configuration

Expand Down
11 changes: 6 additions & 5 deletions WifiRGB/WifiRGB.ino
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,14 @@ void handleApiRequest() {
*/

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

Serial.println("JSON Body: ");
root.printTo(Serial);
serializeJson(jsonDocument, Serial);
Serial.println();

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

// DEBUG: color
Serial.print("Color: ");
root["color"].printTo(Serial);
serializeJson(root["color"], Serial);
Serial.println();

RGB rgb = {0, 0, 0};
JsonObject& color = root["color"];

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