Skip to content

Commit 2b23b00

Browse files
committed
allow control of enabling debug and debug level from IDE
1 parent bcfa5c8 commit 2b23b00

File tree

9 files changed

+84
-34
lines changed

9 files changed

+84
-34
lines changed

boards.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ menu.FlashFreq=Flash Frequency
66
menu.UploadTool=Upload Using
77
menu.ResetMethod=Reset Method
88
menu.ESPModule=Module
9+
menu.Debug=Debug port
10+
menu.DebugLevel=Debug Level
911

1012
##############################################################
1113
generic.name=Generic ESP8266 Module
@@ -26,6 +28,8 @@ generic.build.core=esp8266
2628
generic.build.variant=generic
2729
generic.build.flash_mode=qio
2830
generic.build.spiffs_pagesize=256
31+
generic.build.debug_port=
32+
generic.build.debug_level=
2933

3034
generic.menu.UploadTool.esptool=Serial
3135
generic.menu.UploadTool.esptool.upload.tool=esptool
@@ -166,6 +170,28 @@ generic.menu.ResetMethod.ck.upload.resetmethod=ck
166170
generic.menu.ResetMethod.nodemcu=nodemcu
167171
generic.menu.ResetMethod.nodemcu.upload.resetmethod=nodemcu
168172

173+
generic.menu.Debug.Disabled=Disabled
174+
generic.menu.Debug.Disabled.build.debug_port=
175+
generic.menu.Debug.Serial=Serial
176+
generic.menu.Debug.Serial.build.debug_port=-DDEBUG_ESP_PORT=Serial
177+
generic.menu.Debug.Serial1=Serial1
178+
generic.menu.Debug.Serial1.build.debug_port=-DDEBUG_ESP_PORT=Serial1
179+
180+
generic.menu.DebugLevel.None=None
181+
generic.menu.DebugLevel.None.build.debug_level=
182+
generic.menu.DebugLevel.Core=Core
183+
generic.menu.DebugLevel.Core.build.debug_level=-DDEBUG_ESP_CORE
184+
generic.menu.DebugLevel.SSL=Core + SSL
185+
generic.menu.DebugLevel.SSL.build.debug_level=-DDEBUG_ESP_CORE -DDEBUG_ESP_SSL
186+
generic.menu.DebugLevel.HTTPClient=HTTPClient
187+
generic.menu.DebugLevel.HTTPClient.build.debug_level=-DDEBUG_ESP_HTTP_CLIENT
188+
generic.menu.DebugLevel.HTTPUpdate=HTTPUpdate
189+
generic.menu.DebugLevel.HTTPUpdate.build.debug_level=-DDEBUG_ESP_HTTP_UPDATE
190+
generic.menu.DebugLevel.HTTPUpdate2=HTTPClient + HTTPUpdate
191+
generic.menu.DebugLevel.HTTPUpdate2.build.debug_level=-DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_UPDATE
192+
generic.menu.DebugLevel.HTTPServer=HTTPServer
193+
generic.menu.DebugLevel.HTTPServer.build.debug_level=-DDEBUG_ESP_HTTP_SERVER
194+
169195
# disabled because espressif's bootloader refuses to write above 4M
170196
# generic.menu.FlashSize.8M=8M (7M SPIFFS)
171197
# generic.menu.FlashSize.8M.build.flash_size=1M

cores/esp8266/core_esp8266_main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ static void loop_wrapper() {
101101
preloop_update_frequency();
102102
if(!setup_done) {
103103
setup();
104+
#ifdef DEBUG_ESP_PORT
105+
DEBUG_ESP_PORT.setDebugOutput(true);
106+
#endif
104107
setup_done = true;
105108
}
106109
loop();

cores/esp8266/debug.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#include <stddef.h>
55
#include <stdint.h>
66

7-
//#define DEBUGV(...) ets_printf(__VA_ARGS__)
7+
#ifdef DEBUG_ESP_CORE
8+
#define DEBUGV(...) ets_printf(__VA_ARGS__)
9+
#endif
810

911
#ifndef DEBUGV
1012
#define DEBUGV(...)

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
#ifndef ESP8266HTTPClient_H_
2626
#define ESP8266HTTPClient_H_
2727

28-
//#define DEBUG_HTTPCLIENT(...) Serial1.printf( __VA_ARGS__ )
28+
#ifdef DEBUG_ESP_HTTP_CLIENT
29+
#ifdef DEBUG_ESP_PORT
30+
#define DEBUG_HTTPCLIENT(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ )
31+
#endif
32+
#endif
2933

3034
#ifndef DEBUG_HTTPCLIENT
3135
#define DEBUG_HTTPCLIENT(...)

libraries/ESP8266WebServer/src/ESP8266WebServer.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@
2828
#include "ESP8266WebServer.h"
2929
#include "FS.h"
3030
#include "detail/RequestHandlersImpl.h"
31-
// #define DEBUG
31+
32+
//#define DEBUG_ESP_HTTP_SERVER
33+
#ifdef DEBUG_ESP_PORT
34+
#define DEBUG_OUTPUT DEBUG_ESP_PORT
35+
#else
3236
#define DEBUG_OUTPUT Serial
37+
#endif
3338

3439
const char * AUTHORIZATION_HEADER = "Authorization";
3540

@@ -155,7 +160,7 @@ void ESP8266WebServer::handleClient() {
155160
return;
156161
}
157162

158-
#ifdef DEBUG
163+
#ifdef DEBUG_ESP_HTTP_SERVER
159164
DEBUG_OUTPUT.println("New client");
160165
#endif
161166

@@ -416,13 +421,13 @@ void ESP8266WebServer::onNotFound(THandlerFunction fn) {
416421
void ESP8266WebServer::_handleRequest() {
417422
bool handled = false;
418423
if (!_currentHandler){
419-
#ifdef DEBUG
424+
#ifdef DEBUG_ESP_HTTP_SERVER
420425
DEBUG_OUTPUT.println("request handler not found");
421426
#endif
422427
}
423428
else {
424429
handled = _currentHandler->handle(*this, _currentMethod, _currentUri);
425-
#ifdef DEBUG
430+
#ifdef DEBUG_ESP_HTTP_SERVER
426431
if (!handled) {
427432
DEBUG_OUTPUT.println("request handler failed to handle request");
428433
}

libraries/ESP8266WebServer/src/Parsing.cpp

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@
2424
#include "WiFiClient.h"
2525
#include "ESP8266WebServer.h"
2626

27-
//#define DEBUG
27+
//#define DEBUG_ESP_HTTP_SERVER
28+
#ifdef DEBUG_ESP_PORT
29+
#define DEBUG_OUTPUT DEBUG_ESP_PORT
30+
#else
2831
#define DEBUG_OUTPUT Serial
32+
#endif
2933

3034
bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
3135
// Read the first line of HTTP request
@@ -41,7 +45,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
4145
int addr_start = req.indexOf(' ');
4246
int addr_end = req.indexOf(' ', addr_start + 1);
4347
if (addr_start == -1 || addr_end == -1) {
44-
#ifdef DEBUG
48+
#ifdef DEBUG_ESP_HTTP_SERVER
4549
DEBUG_OUTPUT.print("Invalid request: ");
4650
DEBUG_OUTPUT.println(req);
4751
#endif
@@ -72,7 +76,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
7276
}
7377
_currentMethod = method;
7478

75-
#ifdef DEBUG
79+
#ifdef DEBUG_ESP_HTTP_SERVER
7680
DEBUG_OUTPUT.print("method: ");
7781
DEBUG_OUTPUT.print(methodStr);
7882
DEBUG_OUTPUT.print(" url: ");
@@ -111,7 +115,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
111115
headerValue.trim();
112116
_collectHeader(headerName.c_str(),headerValue.c_str());
113117

114-
#ifdef DEBUG
118+
#ifdef DEBUG_ESP_HTTP_SERVER
115119
DEBUG_OUTPUT.print("headerName: ");
116120
DEBUG_OUTPUT.println(headerName);
117121
DEBUG_OUTPUT.print("headerValue: ");
@@ -142,7 +146,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
142146
char *plainBuf = (char*)malloc(plainLen+1);
143147
client.readBytes(plainBuf, plainLen);
144148
plainBuf[plainLen] = '\0';
145-
#ifdef DEBUG
149+
#ifdef DEBUG_ESP_HTTP_SERVER
146150
DEBUG_OUTPUT.print("Plain: ");
147151
DEBUG_OUTPUT.println(plainBuf);
148152
#endif
@@ -177,7 +181,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
177181
headerValue = req.substring(headerDiv + 2);
178182
_collectHeader(headerName.c_str(),headerValue.c_str());
179183

180-
#ifdef DEBUG
184+
#ifdef DEBUG_ESP_HTTP_SERVER
181185
DEBUG_OUTPUT.print("headerName: ");
182186
DEBUG_OUTPUT.println(headerName);
183187
DEBUG_OUTPUT.print("headerValue: ");
@@ -192,7 +196,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
192196
}
193197
client.flush();
194198

195-
#ifdef DEBUG
199+
#ifdef DEBUG_ESP_HTTP_SERVER
196200
DEBUG_OUTPUT.print("Request: ");
197201
DEBUG_OUTPUT.println(url);
198202
DEBUG_OUTPUT.print(" Arguments: ");
@@ -213,7 +217,7 @@ bool ESP8266WebServer::_collectHeader(const char* headerName, const char* header
213217
}
214218

215219
void ESP8266WebServer::_parseArguments(String data) {
216-
#ifdef DEBUG
220+
#ifdef DEBUG_ESP_HTTP_SERVER
217221
DEBUG_OUTPUT.print("args: ");
218222
DEBUG_OUTPUT.println(data);
219223
#endif
@@ -233,7 +237,7 @@ void ESP8266WebServer::_parseArguments(String data) {
233237
++i;
234238
++_currentArgCount;
235239
}
236-
#ifdef DEBUG
240+
#ifdef DEBUG_ESP_HTTP_SERVER
237241
DEBUG_OUTPUT.print("args count: ");
238242
DEBUG_OUTPUT.println(_currentArgCount);
239243
#endif
@@ -244,7 +248,7 @@ void ESP8266WebServer::_parseArguments(String data) {
244248
for (iarg = 0; iarg < _currentArgCount;) {
245249
int equal_sign_index = data.indexOf('=', pos);
246250
int next_arg_index = data.indexOf('&', pos);
247-
#ifdef DEBUG
251+
#ifdef DEBUG_ESP_HTTP_SERVER
248252
DEBUG_OUTPUT.print("pos ");
249253
DEBUG_OUTPUT.print(pos);
250254
DEBUG_OUTPUT.print("=@ ");
@@ -253,7 +257,7 @@ void ESP8266WebServer::_parseArguments(String data) {
253257
DEBUG_OUTPUT.println(next_arg_index);
254258
#endif
255259
if ((equal_sign_index == -1) || ((equal_sign_index > next_arg_index) && (next_arg_index != -1))) {
256-
#ifdef DEBUG
260+
#ifdef DEBUG_ESP_HTTP_SERVER
257261
DEBUG_OUTPUT.print("arg missing value: ");
258262
DEBUG_OUTPUT.println(iarg);
259263
#endif
@@ -265,7 +269,7 @@ void ESP8266WebServer::_parseArguments(String data) {
265269
RequestArgument& arg = _currentArgs[iarg];
266270
arg.key = data.substring(pos, equal_sign_index);
267271
arg.value = urlDecode(data.substring(equal_sign_index + 1, next_arg_index));
268-
#ifdef DEBUG
272+
#ifdef DEBUG_ESP_HTTP_SERVER
269273
DEBUG_OUTPUT.print("arg ");
270274
DEBUG_OUTPUT.print(iarg);
271275
DEBUG_OUTPUT.print(" key: ");
@@ -279,7 +283,7 @@ void ESP8266WebServer::_parseArguments(String data) {
279283
pos = next_arg_index + 1;
280284
}
281285
_currentArgCount = iarg;
282-
#ifdef DEBUG
286+
#ifdef DEBUG_ESP_HTTP_SERVER
283287
DEBUG_OUTPUT.print("args count: ");
284288
DEBUG_OUTPUT.println(_currentArgCount);
285289
#endif
@@ -308,7 +312,7 @@ uint8_t ESP8266WebServer::_uploadReadByte(WiFiClient& client){
308312

309313
bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t len){
310314

311-
#ifdef DEBUG
315+
#ifdef DEBUG_ESP_HTTP_SERVER
312316
DEBUG_OUTPUT.print("Parse Form: Boundary: ");
313317
DEBUG_OUTPUT.print(boundary);
314318
DEBUG_OUTPUT.print(" Length: ");
@@ -346,14 +350,14 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
346350
argFilename = argName.substring(nameStart+2, argName.length() - 1);
347351
argName = argName.substring(0, argName.indexOf('"'));
348352
argIsFile = true;
349-
#ifdef DEBUG
353+
#ifdef DEBUG_ESP_HTTP_SERVER
350354
DEBUG_OUTPUT.print("PostArg FileName: ");
351355
DEBUG_OUTPUT.println(argFilename);
352356
#endif
353357
//use GET to set the filename if uploading using blob
354358
if (argFilename == "blob" && hasArg("filename")) argFilename = arg("filename");
355359
}
356-
#ifdef DEBUG
360+
#ifdef DEBUG_ESP_HTTP_SERVER
357361
DEBUG_OUTPUT.print("PostArg Name: ");
358362
DEBUG_OUTPUT.println(argName);
359363
#endif
@@ -366,7 +370,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
366370
client.readStringUntil('\r');
367371
client.readStringUntil('\n');
368372
}
369-
#ifdef DEBUG
373+
#ifdef DEBUG_ESP_HTTP_SERVER
370374
DEBUG_OUTPUT.print("PostArg Type: ");
371375
DEBUG_OUTPUT.println(argType);
372376
#endif
@@ -378,7 +382,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
378382
if (argValue.length() > 0) argValue += "\n";
379383
argValue += line;
380384
}
381-
#ifdef DEBUG
385+
#ifdef DEBUG_ESP_HTTP_SERVER
382386
DEBUG_OUTPUT.print("PostArg Value: ");
383387
DEBUG_OUTPUT.println(argValue);
384388
DEBUG_OUTPUT.println();
@@ -389,7 +393,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
389393
arg.value = argValue;
390394

391395
if (line == ("--"+boundary+"--")){
392-
#ifdef DEBUG
396+
#ifdef DEBUG_ESP_HTTP_SERVER
393397
DEBUG_OUTPUT.println("Done Parsing POST");
394398
#endif
395399
break;
@@ -401,7 +405,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
401405
_currentUpload.type = argType;
402406
_currentUpload.totalSize = 0;
403407
_currentUpload.currentSize = 0;
404-
#ifdef DEBUG
408+
#ifdef DEBUG_ESP_HTTP_SERVER
405409
DEBUG_OUTPUT.print("Start File: ");
406410
DEBUG_OUTPUT.print(_currentUpload.filename);
407411
DEBUG_OUTPUT.print(" Type: ");
@@ -450,7 +454,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
450454
_currentUpload.status = UPLOAD_FILE_END;
451455
if(_currentHandler && _currentHandler->canUpload(_currentUri))
452456
_currentHandler->upload(*this, _currentUri, _currentUpload);
453-
#ifdef DEBUG
457+
#ifdef DEBUG_ESP_HTTP_SERVER
454458
DEBUG_OUTPUT.print("End File: ");
455459
DEBUG_OUTPUT.print(_currentUpload.filename);
456460
DEBUG_OUTPUT.print(" Type: ");
@@ -461,7 +465,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
461465
line = client.readStringUntil(0x0D);
462466
client.readStringUntil(0x0A);
463467
if (line == "--"){
464-
#ifdef DEBUG
468+
#ifdef DEBUG_ESP_HTTP_SERVER
465469
DEBUG_OUTPUT.println("Done Parsing POST");
466470
#endif
467471
break;
@@ -507,7 +511,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
507511
if (postArgs) delete[] postArgs;
508512
return true;
509513
}
510-
#ifdef DEBUG
514+
#ifdef DEBUG_ESP_HTTP_SERVER
511515
DEBUG_OUTPUT.print("Error: line: ");
512516
DEBUG_OUTPUT.println(line);
513517
#endif

libraries/ESP8266WiFi/src/WiFiClientSecure.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ extern "C"
4141
#include "include/ClientContext.h"
4242
#include "c_types.h"
4343

44-
//#define DEBUG_SSL
44+
#ifdef DEBUG_ESP_SSL
45+
#define DEBUG_SSL
46+
#endif
4547

4648
#ifdef DEBUG_SSL
4749
#define SSL_DEBUG_OPTS SSL_DISPLAY_STATES

libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@
3232
#include <WiFiUdp.h>
3333
#include <ESP8266HTTPClient.h>
3434

35-
//#define DEBUG_HTTP_UPDATE(...) Serial1.printf( __VA_ARGS__ )
35+
#ifdef DEBUG_ESP_HTTP_UPDATE
36+
#ifdef DEBUG_ESP_PORT
37+
#define DEBUG_HTTP_UPDATE(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ )
38+
#endif
39+
#endif
3640

3741
#ifndef DEBUG_HTTP_UPDATE
3842
#define DEBUG_HTTP_UPDATE(...)

platform.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ compiler.objcopy.eep.extra_flags=
6161
compiler.elf2hex.extra_flags=
6262

6363
## Compile c files
64-
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.c.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
64+
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.c.flags} -DF_CPU={build.f_cpu} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
6565

6666
## Compile c++ files
67-
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpreprocessor.flags} {compiler.cpp.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
67+
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpreprocessor.flags} {compiler.cpp.flags} -DF_CPU={build.f_cpu} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
6868

6969
## Compile S files
70-
recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.S.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
70+
recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.S.flags} -DF_CPU={build.f_cpu} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
7171

7272
## Create archives
7373
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/arduino.ar" "{object_file}"

0 commit comments

Comments
 (0)