@@ -18,7 +18,12 @@ extern "C" {
1818#include " include/UdpContext.h"
1919#include < ESP8266mDNS.h>
2020
21- // #define OTA_DEBUG 1
21+
22+ #ifdef DEBUG_ESP_OTA
23+ #ifdef DEBUG_ESP_PORT
24+ #define OTA_DEBUG DEBUG_ESP_PORT
25+ #endif
26+ #endif
2227
2328ArduinoOTAClass::ArduinoOTAClass ()
2429: _port(0 )
@@ -109,8 +114,8 @@ void ArduinoOTAClass::begin() {
109114 }
110115 _initialized = true ;
111116 _state = OTA_IDLE;
112- #if OTA_DEBUG
113- Serial .printf (" OTA server at: %s.local:%u\n " , _hostname.c_str (), _port);
117+ #ifdef OTA_DEBUG
118+ OTA_DEBUG .printf (" OTA server at: %s.local:%u\n " , _hostname.c_str (), _port);
114119#endif
115120}
116121
@@ -226,8 +231,8 @@ void ArduinoOTAClass::_onRx(){
226231
227232void ArduinoOTAClass::_runUpdate () {
228233 if (!Update.begin (_size, _cmd)) {
229- #if OTA_DEBUG
230- Serial .println (" Update Begin Error" );
234+ #ifdef OTA_DEBUG
235+ OTA_DEBUG .println (" Update Begin Error" );
231236#endif
232237 if (_error_callback) {
233238 _error_callback (OTA_BEGIN_ERROR);
@@ -249,8 +254,8 @@ void ArduinoOTAClass::_runUpdate() {
249254
250255 WiFiClient client;
251256 if (!client.connect (_ota_ip, _ota_port)) {
252- #if OTA_DEBUG
253- Serial .printf (" Connect Failed\n " );
257+ #ifdef OTA_DEBUG
258+ OTA_DEBUG .printf (" Connect Failed\n " );
254259#endif
255260 _udp_ota->listen (*IP_ADDR_ANY, _port);
256261 if (_error_callback) {
@@ -265,8 +270,8 @@ void ArduinoOTAClass::_runUpdate() {
265270 while (!client.available () && waited--)
266271 delay (1 );
267272 if (!waited){
268- #if OTA_DEBUG
269- Serial .printf (" Receive Failed\n " );
273+ #ifdef OTA_DEBUG
274+ OTA_DEBUG .printf (" Receive Failed\n " );
270275#endif
271276 _udp_ota->listen (*IP_ADDR_ANY, _port);
272277 if (_error_callback) {
@@ -288,8 +293,8 @@ void ArduinoOTAClass::_runUpdate() {
288293 client.print (" OK" );
289294 client.stop ();
290295 delay (10 );
291- #if OTA_DEBUG
292- Serial .printf (" Update Success\n Rebooting...\n " );
296+ #ifdef OTA_DEBUG
297+ OTA_DEBUG .printf (" Update Success\n Rebooting...\n " );
293298#endif
294299 if (_end_callback) {
295300 _end_callback ();
@@ -301,8 +306,8 @@ void ArduinoOTAClass::_runUpdate() {
301306 _error_callback (OTA_END_ERROR);
302307 }
303308 Update.printError (client);
304- #if OTA_DEBUG
305- Update.printError (Serial );
309+ #ifdef OTA_DEBUG
310+ Update.printError (OTA_DEBUG );
306311#endif
307312 _state = OTA_IDLE;
308313 }
0 commit comments