Skip to content

Commit 137c507

Browse files
committed
add OTA debug level
1 parent 995f02f commit 137c507

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

boards.txt

+6-2
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,14 @@ generic.menu.DebugLevel.HTTPUpdate3=HTTPClient + HTTPUpdate + Updater
197197
generic.menu.DebugLevel.HTTPUpdate3.build.debug_level=-DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_UPDATER
198198
generic.menu.DebugLevel.HTTPServer=HTTPServer
199199
generic.menu.DebugLevel.HTTPServer.build.debug_level=-DDEBUG_ESP_HTTP_SERVER
200-
generic.menu.DebugLevel.UPDATER=Updater (OTA)
200+
generic.menu.DebugLevel.UPDATER=Updater
201201
generic.menu.DebugLevel.UPDATER.build.debug_level=-DDEBUG_ESP_UPDATER
202+
generic.menu.DebugLevel.OTA=OTA
203+
generic.menu.DebugLevel.OTA.build.debug_level=-DDEBUG_ESP_OTA
204+
generic.menu.DebugLevel.OTA2=OTA + Updater
205+
generic.menu.DebugLevel.OTA2.build.debug_level=-DDEBUG_ESP_OTA -DDEBUG_ESP_UPDATER
202206
generic.menu.DebugLevel.all=All
203-
generic.menu.DebugLevel.all.build.debug_level=-DDEBUG_ESP_CORE -DDEBUG_ESP_SSL -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_UPDATER
207+
generic.menu.DebugLevel.all.build.debug_level=-DDEBUG_ESP_CORE -DDEBUG_ESP_SSL -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_UPDATER -DDEBUG_ESP_OTA
204208

205209
# disabled because espressif's bootloader refuses to write above 4M
206210
# generic.menu.FlashSize.8M=8M (7M SPIFFS)

libraries/ArduinoOTA/ArduinoOTA.cpp

+18-13
Original file line numberDiff line numberDiff line change
@@ -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

2328
ArduinoOTAClass::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

227232
void 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\nRebooting...\n");
296+
#ifdef OTA_DEBUG
297+
OTA_DEBUG.printf("Update Success\nRebooting...\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

Comments
 (0)