diff --git a/code/espurna/config/all.h b/code/espurna/config/all.h index 1a82307e..d804ad6a 100644 --- a/code/espurna/config/all.h +++ b/code/espurna/config/all.h @@ -1,10 +1,10 @@ #include "version.h" #include "arduino.h" #include "prototypes.h" -#include "debug.h" #include "general.h" #include "hardware.h" #include "sensors.h" +#include "debug.h" /* If you want to modify the stock configuration but you don't want to touch diff --git a/code/espurna/config/arduino.h b/code/espurna/config/arduino.h index 9ab0e280..23ee13ca 100644 --- a/code/espurna/config/arduino.h +++ b/code/espurna/config/arduino.h @@ -11,6 +11,13 @@ #define DEBUG_PORT Serial #endif +// Uncomment and configure these lines to enable remote debug via udpDebug +// To receive the message son the destination computer use nc: +// nc -ul 8111 + +//#define DEBUG_UDP_IP IPAddress(192, 168, 1, 100) +//#define DEBUG_UDP_PORT 8111 + //-------------------------------------------------------------------------------- // Hardware //-------------------------------------------------------------------------------- diff --git a/code/espurna/config/debug.h b/code/espurna/config/debug.h index e91a19bd..271a4c25 100644 --- a/code/espurna/config/debug.h +++ b/code/espurna/config/debug.h @@ -1,8 +1,12 @@ -#ifdef DEBUG_PORT -#ifndef SONOFF_DUAL - #define DEBUG_MSG(...) DEBUG_PORT.printf( __VA_ARGS__ ) - #define DEBUG_MSG_P(...) { char buffer[81]; snprintf_P(buffer, 80, __VA_ARGS__ ); DEBUG_PORT.printf( buffer ); } +#define DEBUG_MESSAGE_MAX_LENGTH 80 + +#ifdef SONOFF_DUAL +#undef DEBUG_PORT #endif + +#if defined(DEBUG_PORT) | defined(DEBUG_UDP_IP) + #define DEBUG_MSG(...) debugSend(__VA_ARGS__) + #define DEBUG_MSG_P(...) debugSend_P(__VA_ARGS__) #endif #ifndef DEBUG_MSG diff --git a/code/espurna/debug.ino b/code/espurna/debug.ino new file mode 100644 index 00000000..c114f874 --- /dev/null +++ b/code/espurna/debug.ino @@ -0,0 +1,60 @@ +/* + +DEBUG MODULE + +Copyright (C) 2016-2017 by Xose PĂ©rez + +*/ + +#include +#include + +#ifdef DEBUG_UDP_IP +#include +WiFiUDP udpDebug; +#endif + +void debugSend(const char * format, ...) { + + char buffer[DEBUG_MESSAGE_MAX_LENGTH+1]; + + va_list args; + va_start(args, format); + ets_vsnprintf(buffer, DEBUG_MESSAGE_MAX_LENGTH, format, args); + va_end(args); + + #ifdef DEBUG_PORT + DEBUG_PORT.printf(buffer); + #endif + + #ifdef DEBUG_UDP_IP + udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT); + udpDebug.write(buffer); + udpDebug.endPacket(); + #endif + +} + +void debugSend_P(PGM_P format, ...) { + + char buffer[DEBUG_MESSAGE_MAX_LENGTH+1]; + + char f[DEBUG_MESSAGE_MAX_LENGTH+1]; + memcpy_P(f, format, DEBUG_MESSAGE_MAX_LENGTH); + + va_list args; + va_start(args, format); + ets_vsnprintf(buffer, DEBUG_MESSAGE_MAX_LENGTH, f, args); + va_end(args); + + #ifdef DEBUG_PORT + DEBUG_PORT.printf(buffer); + #endif + + #ifdef DEBUG_UDP_IP + udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT); + udpDebug.write(buffer); + udpDebug.endPacket(); + #endif + +}