@@ -127,9 +127,7 @@ void ArduinoOTAClass::begin() {
127127 }
128128 _initialized = true ;
129129 _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);
133131}
134132
135133int ArduinoOTAClass::parseInt (){
@@ -173,6 +171,7 @@ void ArduinoOTAClass::_onRx(){
173171 _md5 = readStringUntil (' \n ' );
174172 _md5.trim ();
175173 if (_md5.length () != 32 ){
174+ log_e (" bad md5 length" );
176175 return ;
177176 }
178177
@@ -198,13 +197,15 @@ void ArduinoOTAClass::_onRx(){
198197 } else if (_state == OTA_WAITAUTH) {
199198 int cmd = parseInt ();
200199 if (cmd != U_AUTH) {
200+ log_e (" %d was expected. got %d instead" , U_AUTH, cmd);
201201 _state = OTA_IDLE;
202202 return ;
203203 }
204204 _udp_ota.read ();
205205 String cnonce = readStringUntil (' ' );
206206 String response = readStringUntil (' \n ' );
207207 if (cnonce.length () != 32 || response.length () != 32 ) {
208+ log_e (" auth param fail" );
208209 _state = OTA_IDLE;
209210 return ;
210211 }
@@ -225,6 +226,7 @@ void ArduinoOTAClass::_onRx(){
225226 } else {
226227 _udp_ota.beginPacket (_udp_ota.remoteIP (), _udp_ota.remotePort ());
227228 _udp_ota.print (" Authentication Failed" );
229+ log_w (" Authentication Failed" );
228230 _udp_ota.endPacket ();
229231 if (_error_callback) _error_callback (OTA_AUTH_ERROR);
230232 _state = OTA_IDLE;
@@ -234,9 +236,9 @@ void ArduinoOTAClass::_onRx(){
234236
235237void ArduinoOTAClass::_runUpdate () {
236238 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+
240242 if (_error_callback) {
241243 _error_callback (OTA_BEGIN_ERROR);
242244 }
@@ -272,21 +274,15 @@ void ArduinoOTAClass::_runUpdate() {
272274 }
273275 if (!waited){
274276 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);
278278 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" );
282280 _state = OTA_IDLE;
283281 break ;
284282 }
285283 continue ;
286284 }
287- #ifdef OTA_DEBUG
288- OTA_DEBUG.printf (" Receive Failed\n " );
289- #endif
285+ log_e (" Receive Failed" );
290286 if (_error_callback) {
291287 _error_callback (OTA_RECEIVE_ERROR);
292288 }
@@ -295,9 +291,7 @@ void ArduinoOTAClass::_runUpdate() {
295291 return ;
296292 }
297293 if (!available){
298- #ifdef OTA_DEBUG
299- OTA_DEBUG.printf (" No Data: %u\n " , waited);
300- #endif
294+ log_e (" No Data: %u" , waited);
301295 _state = OTA_IDLE;
302296 break ;
303297 }
@@ -317,18 +311,14 @@ void ArduinoOTAClass::_runUpdate() {
317311 log_w (" didn't write enough! %u != %u" , written, r);
318312 }
319313 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" );
323315 }
324316 total += written;
325317 if (_progress_callback) {
326318 _progress_callback (total, _size);
327319 }
328320 } else {
329- #ifdef OTA_DEBUG
330- Update.printError (OTA_DEBUG);
331- #endif
321+ log_e (" Write ERROR: %s" , Update.errorString ());
332322 }
333323 }
334324
@@ -351,10 +341,7 @@ void ArduinoOTAClass::_runUpdate() {
351341 Update.printError (client);
352342 client.stop ();
353343 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 ());
358345 _state = OTA_IDLE;
359346 }
360347}
@@ -366,9 +353,7 @@ void ArduinoOTAClass::end() {
366353 MDNS.end ();
367354 }
368355 _state = OTA_IDLE;
369- #ifdef OTA_DEBUG
370- OTA_DEBUG.println (" OTA server stopped." );
371- #endif
356+ log_i (" OTA server stopped." );
372357}
373358
374359void ArduinoOTAClass::handle () {
@@ -395,4 +380,4 @@ void ArduinoOTAClass::setTimeout(int timeoutInMillis) {
395380
396381#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_ARDUINOOTA)
397382ArduinoOTAClass ArduinoOTA;
398- #endif
383+ #endif
0 commit comments