@@ -127,9 +127,7 @@ void ArduinoOTAClass::begin() {
127
127
}
128
128
_initialized = true ;
129
129
_state = OTA_IDLE;
130
- #ifdef OTA_DEBUG
131
- OTA_DEBUG.printf (" OTA server at: %s.local:%u\n " , _hostname.c_str (), _port);
132
- #endif
130
+ log_i (" OTA server at: %s.local:%u" , _hostname.c_str (), _port);
133
131
}
134
132
135
133
int ArduinoOTAClass::parseInt (){
@@ -173,6 +171,7 @@ void ArduinoOTAClass::_onRx(){
173
171
_md5 = readStringUntil (' \n ' );
174
172
_md5.trim ();
175
173
if (_md5.length () != 32 ){
174
+ log_e (" bad md5 length" );
176
175
return ;
177
176
}
178
177
@@ -198,13 +197,15 @@ void ArduinoOTAClass::_onRx(){
198
197
} else if (_state == OTA_WAITAUTH) {
199
198
int cmd = parseInt ();
200
199
if (cmd != U_AUTH) {
200
+ log_e (" %d was expected. got %d instead" , U_AUTH, cmd);
201
201
_state = OTA_IDLE;
202
202
return ;
203
203
}
204
204
_udp_ota.read ();
205
205
String cnonce = readStringUntil (' ' );
206
206
String response = readStringUntil (' \n ' );
207
207
if (cnonce.length () != 32 || response.length () != 32 ) {
208
+ log_e (" auth param fail" );
208
209
_state = OTA_IDLE;
209
210
return ;
210
211
}
@@ -225,6 +226,7 @@ void ArduinoOTAClass::_onRx(){
225
226
} else {
226
227
_udp_ota.beginPacket (_udp_ota.remoteIP (), _udp_ota.remotePort ());
227
228
_udp_ota.print (" Authentication Failed" );
229
+ log_w (" Authentication Failed" );
228
230
_udp_ota.endPacket ();
229
231
if (_error_callback) _error_callback (OTA_AUTH_ERROR);
230
232
_state = OTA_IDLE;
@@ -234,9 +236,9 @@ void ArduinoOTAClass::_onRx(){
234
236
235
237
void ArduinoOTAClass::_runUpdate () {
236
238
if (!Update.begin (_size, _cmd)) {
237
- # ifdef OTA_DEBUG
238
- Update.printError (OTA_DEBUG );
239
- # endif
239
+
240
+ log_e ( " Begin ERROR: %s " , Update.errorString () );
241
+
240
242
if (_error_callback) {
241
243
_error_callback (OTA_BEGIN_ERROR);
242
244
}
@@ -272,21 +274,15 @@ void ArduinoOTAClass::_runUpdate() {
272
274
}
273
275
if (!waited){
274
276
if (written && tried++ < 3 ){
275
- #ifdef OTA_DEBUG
276
- OTA_DEBUG.printf (" Try[%u]: %u\n " , tried, written);
277
- #endif
277
+ log_i (" Try[%u]: %u" , tried, written);
278
278
if (!client.printf (" %u" , written)){
279
- #ifdef OTA_DEBUG
280
- OTA_DEBUG.printf (" failed to respond\n " );
281
- #endif
279
+ log_e (" failed to respond" );
282
280
_state = OTA_IDLE;
283
281
break ;
284
282
}
285
283
continue ;
286
284
}
287
- #ifdef OTA_DEBUG
288
- OTA_DEBUG.printf (" Receive Failed\n " );
289
- #endif
285
+ log_e (" Receive Failed" );
290
286
if (_error_callback) {
291
287
_error_callback (OTA_RECEIVE_ERROR);
292
288
}
@@ -295,9 +291,7 @@ void ArduinoOTAClass::_runUpdate() {
295
291
return ;
296
292
}
297
293
if (!available){
298
- #ifdef OTA_DEBUG
299
- OTA_DEBUG.printf (" No Data: %u\n " , waited);
300
- #endif
294
+ log_e (" No Data: %u" , waited);
301
295
_state = OTA_IDLE;
302
296
break ;
303
297
}
@@ -317,18 +311,14 @@ void ArduinoOTAClass::_runUpdate() {
317
311
log_w (" didn't write enough! %u != %u" , written, r);
318
312
}
319
313
if (!client.printf (" %u" , written)){
320
- #ifdef OTA_DEBUG
321
- OTA_DEBUG.printf (" failed to respond\n " );
322
- #endif
314
+ log_w (" failed to respond" );
323
315
}
324
316
total += written;
325
317
if (_progress_callback) {
326
318
_progress_callback (total, _size);
327
319
}
328
320
} else {
329
- #ifdef OTA_DEBUG
330
- Update.printError (OTA_DEBUG);
331
- #endif
321
+ log_e (" Write ERROR: %s" , Update.errorString ());
332
322
}
333
323
}
334
324
@@ -351,10 +341,7 @@ void ArduinoOTAClass::_runUpdate() {
351
341
Update.printError (client);
352
342
client.stop ();
353
343
delay (10 );
354
- #ifdef OTA_DEBUG
355
- OTA_DEBUG.print (" Update ERROR: " );
356
- Update.printError (OTA_DEBUG);
357
- #endif
344
+ log_e (" Update ERROR: %s" , Update.errorString ());
358
345
_state = OTA_IDLE;
359
346
}
360
347
}
@@ -366,9 +353,7 @@ void ArduinoOTAClass::end() {
366
353
MDNS.end ();
367
354
}
368
355
_state = OTA_IDLE;
369
- #ifdef OTA_DEBUG
370
- OTA_DEBUG.println (" OTA server stopped." );
371
- #endif
356
+ log_i (" OTA server stopped." );
372
357
}
373
358
374
359
void ArduinoOTAClass::handle () {
@@ -395,4 +380,4 @@ void ArduinoOTAClass::setTimeout(int timeoutInMillis) {
395
380
396
381
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_ARDUINOOTA)
397
382
ArduinoOTAClass ArduinoOTA;
398
- #endif
383
+ #endif
0 commit comments