Skip to content

Commit

Permalink
Merge pull request esp8266#1350 from Links2004/debug
Browse files Browse the repository at this point in the history
allow control of enabling debug and debug level from IDE
  • Loading branch information
Links2004 committed Jan 2, 2016
2 parents bcfa5c8 + 137c507 commit 119f2cd
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 49 deletions.
40 changes: 40 additions & 0 deletions boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ menu.FlashFreq=Flash Frequency
menu.UploadTool=Upload Using
menu.ResetMethod=Reset Method
menu.ESPModule=Module
menu.Debug=Debug port
menu.DebugLevel=Debug Level

##############################################################
generic.name=Generic ESP8266 Module
Expand All @@ -26,6 +28,8 @@ generic.build.core=esp8266
generic.build.variant=generic
generic.build.flash_mode=qio
generic.build.spiffs_pagesize=256
generic.build.debug_port=
generic.build.debug_level=

generic.menu.UploadTool.esptool=Serial
generic.menu.UploadTool.esptool.upload.tool=esptool
Expand Down Expand Up @@ -166,6 +170,42 @@ generic.menu.ResetMethod.ck.upload.resetmethod=ck
generic.menu.ResetMethod.nodemcu=nodemcu
generic.menu.ResetMethod.nodemcu.upload.resetmethod=nodemcu

generic.menu.Debug.Disabled=Disabled
generic.menu.Debug.Disabled.build.debug_port=
generic.menu.Debug.Serial=Serial
generic.menu.Debug.Serial.build.debug_port=-DDEBUG_ESP_PORT=Serial
generic.menu.Debug.Serial1=Serial1
generic.menu.Debug.Serial1.build.debug_port=-DDEBUG_ESP_PORT=Serial1

generic.menu.DebugLevel.None=None
generic.menu.DebugLevel.None.build.debug_level=
generic.menu.DebugLevel.Core=Core
generic.menu.DebugLevel.Core.build.debug_level=-DDEBUG_ESP_CORE
generic.menu.DebugLevel.SSL=Core + SSL
generic.menu.DebugLevel.SSL.build.debug_level=-DDEBUG_ESP_CORE -DDEBUG_ESP_SSL
generic.menu.DebugLevel.WiFic=Core + WiFi
generic.menu.DebugLevel.WiFic.build.debug_level=-DDEBUG_ESP_CORE -DDEBUG_ESP_WIFI
generic.menu.DebugLevel.WiFi=WiFi
generic.menu.DebugLevel.WiFi.build.debug_level=-DDEBUG_ESP_WIFI
generic.menu.DebugLevel.HTTPClient=HTTPClient
generic.menu.DebugLevel.HTTPClient.build.debug_level=-DDEBUG_ESP_HTTP_CLIENT
generic.menu.DebugLevel.HTTPUpdate=HTTPUpdate
generic.menu.DebugLevel.HTTPUpdate.build.debug_level=-DDEBUG_ESP_HTTP_UPDATE
generic.menu.DebugLevel.HTTPUpdate2=HTTPClient + HTTPUpdate
generic.menu.DebugLevel.HTTPUpdate2.build.debug_level=-DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_UPDATE
generic.menu.DebugLevel.HTTPUpdate3=HTTPClient + HTTPUpdate + Updater
generic.menu.DebugLevel.HTTPUpdate3.build.debug_level=-DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_UPDATER
generic.menu.DebugLevel.HTTPServer=HTTPServer
generic.menu.DebugLevel.HTTPServer.build.debug_level=-DDEBUG_ESP_HTTP_SERVER
generic.menu.DebugLevel.UPDATER=Updater
generic.menu.DebugLevel.UPDATER.build.debug_level=-DDEBUG_ESP_UPDATER
generic.menu.DebugLevel.OTA=OTA
generic.menu.DebugLevel.OTA.build.debug_level=-DDEBUG_ESP_OTA
generic.menu.DebugLevel.OTA2=OTA + Updater
generic.menu.DebugLevel.OTA2.build.debug_level=-DDEBUG_ESP_OTA -DDEBUG_ESP_UPDATER
generic.menu.DebugLevel.all=All
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

# disabled because espressif's bootloader refuses to write above 4M
# generic.menu.FlashSize.8M=8M (7M SPIFFS)
# generic.menu.FlashSize.8M.build.flash_size=1M
Expand Down
6 changes: 5 additions & 1 deletion cores/esp8266/Updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
#define U_SPIFFS 100
#define U_AUTH 200

//#define DEBUG_UPDATER Serial
#ifdef DEBUG_ESP_UPDATER
#ifdef DEBUG_ESP_PORT
#define DEBUG_UPDATER DEBUG_ESP_PORT
#endif
#endif

class UpdaterClass {
public:
Expand Down
3 changes: 3 additions & 0 deletions cores/esp8266/core_esp8266_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ static void loop_wrapper() {
preloop_update_frequency();
if(!setup_done) {
setup();
#ifdef DEBUG_ESP_PORT
DEBUG_ESP_PORT.setDebugOutput(true);
#endif
setup_done = true;
}
loop();
Expand Down
4 changes: 3 additions & 1 deletion cores/esp8266/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#include <stddef.h>
#include <stdint.h>

//#define DEBUGV(...) ets_printf(__VA_ARGS__)
#ifdef DEBUG_ESP_CORE
#define DEBUGV(...) ets_printf(__VA_ARGS__)
#endif

#ifndef DEBUGV
#define DEBUGV(...)
Expand Down
31 changes: 18 additions & 13 deletions libraries/ArduinoOTA/ArduinoOTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ extern "C" {
#include "include/UdpContext.h"
#include <ESP8266mDNS.h>

//#define OTA_DEBUG 1

#ifdef DEBUG_ESP_OTA
#ifdef DEBUG_ESP_PORT
#define OTA_DEBUG DEBUG_ESP_PORT
#endif
#endif

ArduinoOTAClass::ArduinoOTAClass()
: _port(0)
Expand Down Expand Up @@ -109,8 +114,8 @@ void ArduinoOTAClass::begin() {
}
_initialized = true;
_state = OTA_IDLE;
#if OTA_DEBUG
Serial.printf("OTA server at: %s.local:%u\n", _hostname.c_str(), _port);
#ifdef OTA_DEBUG
OTA_DEBUG.printf("OTA server at: %s.local:%u\n", _hostname.c_str(), _port);
#endif
}

Expand Down Expand Up @@ -226,8 +231,8 @@ void ArduinoOTAClass::_onRx(){

void ArduinoOTAClass::_runUpdate() {
if (!Update.begin(_size, _cmd)) {
#if OTA_DEBUG
Serial.println("Update Begin Error");
#ifdef OTA_DEBUG
OTA_DEBUG.println("Update Begin Error");
#endif
if (_error_callback) {
_error_callback(OTA_BEGIN_ERROR);
Expand All @@ -249,8 +254,8 @@ void ArduinoOTAClass::_runUpdate() {

WiFiClient client;
if (!client.connect(_ota_ip, _ota_port)) {
#if OTA_DEBUG
Serial.printf("Connect Failed\n");
#ifdef OTA_DEBUG
OTA_DEBUG.printf("Connect Failed\n");
#endif
_udp_ota->listen(*IP_ADDR_ANY, _port);
if (_error_callback) {
Expand All @@ -265,8 +270,8 @@ void ArduinoOTAClass::_runUpdate() {
while (!client.available() && waited--)
delay(1);
if (!waited){
#if OTA_DEBUG
Serial.printf("Receive Failed\n");
#ifdef OTA_DEBUG
OTA_DEBUG.printf("Receive Failed\n");
#endif
_udp_ota->listen(*IP_ADDR_ANY, _port);
if (_error_callback) {
Expand All @@ -288,8 +293,8 @@ void ArduinoOTAClass::_runUpdate() {
client.print("OK");
client.stop();
delay(10);
#if OTA_DEBUG
Serial.printf("Update Success\nRebooting...\n");
#ifdef OTA_DEBUG
OTA_DEBUG.printf("Update Success\nRebooting...\n");
#endif
if (_end_callback) {
_end_callback();
Expand All @@ -301,8 +306,8 @@ void ArduinoOTAClass::_runUpdate() {
_error_callback(OTA_END_ERROR);
}
Update.printError(client);
#if OTA_DEBUG
Update.printError(Serial);
#ifdef OTA_DEBUG
Update.printError(OTA_DEBUG);
#endif
_state = OTA_IDLE;
}
Expand Down
6 changes: 5 additions & 1 deletion libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
#ifndef ESP8266HTTPClient_H_
#define ESP8266HTTPClient_H_

//#define DEBUG_HTTPCLIENT(...) Serial1.printf( __VA_ARGS__ )
#ifdef DEBUG_ESP_HTTP_CLIENT
#ifdef DEBUG_ESP_PORT
#define DEBUG_HTTPCLIENT(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ )
#endif
#endif

#ifndef DEBUG_HTTPCLIENT
#define DEBUG_HTTPCLIENT(...)
Expand Down
13 changes: 9 additions & 4 deletions libraries/ESP8266WebServer/src/ESP8266WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@
#include "ESP8266WebServer.h"
#include "FS.h"
#include "detail/RequestHandlersImpl.h"
// #define DEBUG

//#define DEBUG_ESP_HTTP_SERVER
#ifdef DEBUG_ESP_PORT
#define DEBUG_OUTPUT DEBUG_ESP_PORT
#else
#define DEBUG_OUTPUT Serial
#endif

const char * AUTHORIZATION_HEADER = "Authorization";

Expand Down Expand Up @@ -155,7 +160,7 @@ void ESP8266WebServer::handleClient() {
return;
}

#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.println("New client");
#endif

Expand Down Expand Up @@ -416,13 +421,13 @@ void ESP8266WebServer::onNotFound(THandlerFunction fn) {
void ESP8266WebServer::_handleRequest() {
bool handled = false;
if (!_currentHandler){
#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.println("request handler not found");
#endif
}
else {
handled = _currentHandler->handle(*this, _currentMethod, _currentUri);
#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
if (!handled) {
DEBUG_OUTPUT.println("request handler failed to handle request");
}
Expand Down
Loading

0 comments on commit 119f2cd

Please sign in to comment.