make a copy of cmd, ArudinoJson alters original one

This commit is contained in:
Nicu Hodos 2022-10-24 15:48:34 +02:00
parent d232bc4ffa
commit 389242f493

View File

@ -122,7 +122,8 @@ void runRcSwitchCommand(JsonVariant jsonDoc) {
// blink();
}
void runJsonCommands(String cmd) {
void runJsonCommands(const char* cmd) {
String origCmd = String(cmd);
StaticJsonDocument<512> jsonArray;
DeserializationError err = deserializeJson(jsonArray, cmd);
if (err == DeserializationError::Ok) {
@ -133,7 +134,9 @@ void runJsonCommands(String cmd) {
}
}
} else {
Serial.println(String(err.c_str()) + ": " + cmd);
Serial.print(err.c_str());
Serial.print(": ");
Serial.println(origCmd);
}
}
@ -150,6 +153,6 @@ void readCommand() {
cmd = cmd.substring(0, cmd.lastIndexOf(','));
}
cmd = "[" + cmd + "]";
runJsonCommands(cmd);
runJsonCommands(cmd.c_str());
}
}