diff --git a/gateway/src/gateway.cpp b/gateway/src/gateway.cpp index 49228f4..04fd607 100644 --- a/gateway/src/gateway.cpp +++ b/gateway/src/gateway.cpp @@ -49,7 +49,7 @@ void readRcSwitch() { unsigned long value = mySwitch.getReceivedValue(); mySwitch.resetAvailable(); - StaticJsonDocument<200> jsonDoc; + StaticJsonDocument<128> jsonDoc; Protocol* p = findProtocol(mySwitch.getReceivedProtocol()); p->toJson(value, jsonDoc); delete p; @@ -61,7 +61,6 @@ void readRcSwitch() { } void runJsonCommands(const char* cmd) { - String origCmd = String(cmd); StaticJsonDocument<512> jsonArray; DeserializationError err = deserializeJson(jsonArray, cmd); if (err == DeserializationError::Ok) { @@ -77,9 +76,13 @@ void runJsonCommands(const char* cmd) { } } } else { - Serial.print(err.c_str()); - Serial.print(": "); - Serial.println(origCmd); + StaticJsonDocument<128> jsonError; + JsonObject error = jsonError.createNestedObject("error"); + error["message"] = err.c_str(); + error["original_cmd"] = cmd; + serializeJson(jsonError, Serial); + Serial.println(); + } } @@ -95,7 +98,7 @@ void readCommand() { if (cmd.endsWith(",")) { cmd = cmd.substring(0, cmd.lastIndexOf(',')); } - char buffer[cmd.length()+2]; + char buffer[cmd.length()+3]; sprintf(buffer, "[%s]", cmd.c_str()); runJsonCommands(buffer); }