@@ -56,8 +56,8 @@ bool ws_conn = false;
56
56
void greetings_ (){
57
57
StaticJsonDocument<200 > doc;
58
58
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 () ;
61
61
doc[" version" ] = version;
62
62
doc[" name" ] = name;
63
63
doc[" chip" ] = chip;
@@ -70,7 +70,7 @@ void greetings_(){
70
70
void register_ (){
71
71
StaticJsonDocument<200 > doc;
72
72
doc[" type" ] = " register" ;
73
- doc[" mac" ] = WiFi.macAddress ();
73
+ doc[" mac" ] = WiFi.macAddress (). c_str () ;
74
74
75
75
char data[200 ];
76
76
serializeJson (doc, data);
@@ -87,9 +87,8 @@ typedef struct {
87
87
88
88
void OTA_RESPONSES (JsonDocument &msg){
89
89
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" ) {
93
92
USE_SERIAL.print (F (" go\n " ));
94
93
SketchSize = int (msg[" size" ]);
95
94
maxSketchSpace = (ESP.getFreeSketchSpace () - 0x1000 ) & 0xFFFFF000 ;
@@ -100,12 +99,12 @@ void OTA_RESPONSES(JsonDocument &msg){
100
99
Update.printError (Serial);
101
100
ESP.restart ();
102
101
}
103
- } else if (strncmp ( msg[ " value " ], ok, strlen (ok)) == 0 ) {
102
+ } else if (val == " ok " ) {
104
103
USE_SERIAL.print (F (" OK\n " ));
105
104
register_ ();
106
105
} else {
107
106
USE_SERIAL.print (F (" unknown value : " ));
108
- USE_SERIAL.print (msg[ " value " ]. as < char >() );
107
+ USE_SERIAL.print (val );
109
108
USE_SERIAL.print (F (" \n " ));
110
109
}
111
110
}
@@ -146,9 +145,10 @@ void text(uint8_t * payload, size_t length){
146
145
// Handle each TYPE of message
147
146
int b = 0 ;
148
147
148
+ String t = doc_in[" type" ];
149
149
for ( b=0 ; b<nrOfResponses ; b++ )
150
150
{
151
- if ( strncmp (doc_in[ " type " ], responses[b].type , strlen (responses[b]. type )) == 0 ) {
151
+ if (t == responses[b].type ) {
152
152
responses[b].func (doc_in);
153
153
}
154
154
}
0 commit comments