10000 make OTA work with ArduinoJson 6.x · smartcoder00/arduinoWebSockets@22dff65 · GitHub
[go: up one dir, main page]

Skip to content

Commit 22dff65

Browse files
committed
make OTA work with ArduinoJson 6.x
1 parent a4f13a1 commit 22dff65

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

examples/esp8266_pico/WebSocketClientOTA/WebSocketClientOTA.ino

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ bool ws_conn = false;
5656
void greetings_(){
5757
StaticJsonDocument<200> doc;
5858
doc["type"] = "greetings";
59-
doc["mac"] = WiFi.macAddress();
60-
doc["ip"] = WiFi.localIP().toString();
59+
doc["mac"] = WiFi.macAddress().c_str();
60+
doc["ip"] = WiFi.localIP().toString().c_str();
6161
doc["version"] = version;
6262
doc["name"] = name;
6363
doc["chip"] = chip;
@@ -70,7 +70,7 @@ void greetings_(){
7070
void register_(){
7171
StaticJsonDocument<200> doc;
7272
doc["type"] = "register";
73-
doc["mac"] = WiFi.macAddress();
73+
doc["mac"] = WiFi.macAddress().c_str();
7474

7575
char data[200];
7676
serializeJson(doc, data);
@@ -87,9 +87,8 @@ typedef struct {
8787

8888
void OTA_RESPONSES(JsonDocument &msg){
8989
USE_SERIAL.print(F("[WSc] OTA mode: "));
90-
const char* go = "go";
91-
const char* ok = "ok";
92-
if(strncmp( msg["value"], go, strlen(go)) == 0 ) {
90+
String val = msg["value"];
91+
if(val == "go") {
9392
USE_SERIAL.print(F("go\n"));
9493
SketchSize = int(msg["size"]);
9594
maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
@@ -100,12 +99,12 @@ void OTA_RESPONSES(JsonDocument &msg){
10099
Update.printError(Serial);
101100
ESP.restart();
102101
}
103-
} else if (strncmp( msg["value"], ok, strlen(ok)) == 0) {
102+
} else if (val == "ok") {
104103
USE_SERIAL.print(F("OK\n"));
105104
register_();
106105
} else {
107106
USE_SERIAL.print(F("unknown value : "));
108-
USE_SERIAL.print(msg["value"].as<char>());
107+
USE_SERIAL.print(val);
109108
USE_SERIAL.print(F("\n"));
110109
}
111110
}
@@ -146,9 +145,10 @@ void text(uint8_t * payload, size_t length){
146145
// Handle each TYPE of message
147146
int b = 0;
148147

148+
String t = doc_in["type"];
149149
for( b=0 ; b<nrOfResponses ; b++ )
150150
{
151-
if( strncmp(doc_in["type"], responses[b].type, strlen(responses[b].type)) == 0 ) {
151+
if(t == responses[b].type) {
152152
responses[b].func(doc_in);
153153
}
154154
}

0 commit comments

Comments
 (0)
0