diff --git a/usermods/mpu6050_imu/mpu6050_imu.cpp b/usermods/mpu6050_imu/mpu6050_imu.cpp index 6df5d64e12..8486536fff 100644 --- a/usermods/mpu6050_imu/mpu6050_imu.cpp +++ b/usermods/mpu6050_imu/mpu6050_imu.cpp @@ -49,9 +49,9 @@ #undef DEBUG_PRINTLN #undef DEBUG_PRINTF #ifdef WLED_DEBUG - #define DEBUG_PRINT(x) DEBUGOUT.print(x) - #define DEBUG_PRINTLN(x) DEBUGOUT.println(x) - #define DEBUG_PRINTF(x...) DEBUGOUT.printf(x) + #define DEBUG_PRINT(x) DEBUGOUT(x) + #define DEBUG_PRINTLN(x) DEBUGOUTLN(x) + #define DEBUG_PRINTF(x...) DEBUGOUTF(x) #else #define DEBUG_PRINT(x) #define DEBUG_PRINTLN(x) diff --git a/wled00/FX.h b/wled00/FX.h index 9fd3a04d8a..8150748372 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -20,17 +20,10 @@ #include "wled.h" #include "colors.h" #ifdef WLED_DEBUG - // enable additional debug output - #if defined(WLED_DEBUG_HOST) - #include "net_debug.h" - #define DEBUGOUT NetDebug - #else - #define DEBUGOUT Serial - #endif - #define DEBUGFX_PRINT(x) DEBUGOUT.print(x) - #define DEBUGFX_PRINTLN(x) DEBUGOUT.println(x) - #define DEBUGFX_PRINTF(x...) DEBUGOUT.printf(x) - #define DEBUGFX_PRINTF_P(x...) DEBUGOUT.printf_P(x) + #define DEBUGFX_PRINT(x) DEBUGOUT(x) + #define DEBUGFX_PRINTLN(x) DEBUGOUTLN(x) + #define DEBUGFX_PRINTF(x...) DEBUGOUTF(x) + #define DEBUGFX_PRINTF_P(x...) DEBUGOUTF(x) #else #define DEBUGFX_PRINT(x) #define DEBUGFX_PRINTLN(x) diff --git a/wled00/bus_manager.h b/wled00/bus_manager.h index abfb08c81b..e6f805ea24 100644 --- a/wled00/bus_manager.h +++ b/wled00/bus_manager.h @@ -33,22 +33,14 @@ make_unique(Args&&... args) } #endif -// enable additional debug output -#if defined(WLED_DEBUG_HOST) - #include "net_debug.h" - #define DEBUGOUT NetDebug -#else - #define DEBUGOUT Serial -#endif - #ifdef WLED_DEBUG_BUS #ifndef ESP8266 #include #endif - #define DEBUGBUS_PRINT(x) DEBUGOUT.print(x) - #define DEBUGBUS_PRINTLN(x) DEBUGOUT.println(x) - #define DEBUGBUS_PRINTF(x...) DEBUGOUT.printf(x) - #define DEBUGBUS_PRINTF_P(x...) DEBUGOUT.printf_P(x) + #define DEBUGBUS_PRINT(x) DEBUGOUT(x) + #define DEBUGBUS_PRINTLN(x) DEBUGOUTLN(x) + #define DEBUGBUS_PRINTF(x...) DEBUGOUTF(x) + #define DEBUGBUS_PRINTF_P(x...) DEBUGOUTF(x) #else #define DEBUGBUS_PRINT(x) #define DEBUGBUS_PRINTLN(x) diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 2e458e7da9..0f7f75c155 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -659,6 +659,14 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { CJSON(hueIP[i], if_hue_ip[i]); #endif +#ifdef WLED_ENABLE_NET_DEBUG + JsonObject if_ndb = interfaces["ndb"]; + JsonArray if_ndb_ip = if_ndb["ip"]; + for (byte i = 0; i < 4; i++) + CJSON(netDebugPrintIP[i], if_ndb_ip[i]); + CJSON(netDebugPrintPort, if_ndb["port"]); +#endif + JsonObject if_ntp = interfaces[F("ntp")]; CJSON(ntpEnabled, if_ntp["en"]); getStringFromJson(ntpServerName, if_ntp[F("host")], 33); // "1.wled.pool.ntp.org" @@ -1191,6 +1199,15 @@ void serializeConfig(JsonObject root) { } #endif +#ifdef WLED_ENABLE_NET_DEBUG + JsonObject if_ndb = interfaces.createNestedObject("ndb"); + JsonArray if_ndb_ip = if_ndb.createNestedArray("ip"); + for (byte i = 0; i < 4; i++) { + if_ndb_ip.add(netDebugPrintIP[i]); + } + if_ndb["port"] = netDebugPrintPort; +#endif + JsonObject if_ntp = interfaces.createNestedObject("ntp"); if_ntp["en"] = ntpEnabled; if_ntp[F("host")] = ntpServerName; diff --git a/wled00/data/index.js b/wled00/data/index.js index ee5126973c..bd9fdbf244 100644 --- a/wled00/data/index.js +++ b/wled00/data/index.js @@ -718,7 +718,7 @@ function populateInfo(i) cn += `v${i.ver} "${vcn}"${i.release ? '
('+i.release+')' : ''}

${urows} ${urows===""?'':''} -${i.opt&0x100?inforow("Debug",""):''} +${i.opt&0x100?inforow("Net Debug",""):''} ${inforow("Build",i.vid)} ${inforow("Signal strength",i.wifi.signal +"% ("+ i.wifi.rssi, " dBm)")} ${inforow("Uptime",getRuntimeStr(i.uptime))} diff --git a/wled00/data/settings_sync.htm b/wled00/data/settings_sync.htm index 12eb3e8d07..1f8feb207c 100644 --- a/wled00/data/settings_sync.htm +++ b/wled00/data/settings_sync.htm @@ -284,6 +284,19 @@

Serial


Keep at 115200 to use Improv. Some boards may not support high rates. +
+

Net Debug ☾

+
+ This firmware build does not include Net Debug support.
+
+
+Netcat host IP:
+ . + . + . +
+Netcat host Port:
+

diff --git a/wled00/json.cpp b/wled00/json.cpp index 74e12b5470..8c9cb534cf 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -368,7 +368,7 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId) { bool stateResponse = root[F("v")] | false; - #if defined(WLED_DEBUG) && defined(WLED_DEBUG_HOST) + #if defined(WLED_DEBUG) && defined(WLED_ENABLE_NET_DEBUG) netDebugEnabled = root[F("debug")] | netDebugEnabled; #endif @@ -866,7 +866,7 @@ void serializeInfo(JsonObject root) uint16_t os = 0; #ifdef WLED_DEBUG os = 0x80; - #ifdef WLED_DEBUG_HOST + #ifdef WLED_ENABLE_NET_DEBUG os |= 0x0100; if (!netDebugEnabled) os &= ~0x0080; #endif diff --git a/wled00/net_debug.cpp b/wled00/net_debug.cpp index 4d9552a867..ed39df561d 100644 --- a/wled00/net_debug.cpp +++ b/wled00/net_debug.cpp @@ -1,23 +1,11 @@ #include "wled.h" -#ifdef WLED_DEBUG_HOST +#ifdef WLED_ENABLE_NET_DEBUG size_t NetworkDebugPrinter::write(uint8_t c) { if (!WLED_CONNECTED || !netDebugEnabled) return 0; - if (!debugPrintHostIP && !debugPrintHostIP.fromString(netDebugPrintHost)) { - #ifdef ESP8266 - WiFi.hostByName(netDebugPrintHost, debugPrintHostIP, 750); - #else - #ifdef WLED_USE_ETHERNET - ETH.hostByName(netDebugPrintHost, debugPrintHostIP); - #else - WiFi.hostByName(netDebugPrintHost, debugPrintHostIP); - #endif - #endif - } - - debugUdp.beginPacket(debugPrintHostIP, netDebugPrintPort); + debugUdp.beginPacket(netDebugPrintIP, netDebugPrintPort); debugUdp.write(c); debugUdp.endPacket(); return 1; @@ -26,19 +14,7 @@ size_t NetworkDebugPrinter::write(uint8_t c) { size_t NetworkDebugPrinter::write(const uint8_t *buf, size_t size) { if (!WLED_CONNECTED || buf == nullptr || !netDebugEnabled) return 0; - if (!debugPrintHostIP && !debugPrintHostIP.fromString(netDebugPrintHost)) { - #ifdef ESP8266 - WiFi.hostByName(netDebugPrintHost, debugPrintHostIP, 750); - #else - #ifdef WLED_USE_ETHERNET - ETH.hostByName(netDebugPrintHost, debugPrintHostIP); - #else - WiFi.hostByName(netDebugPrintHost, debugPrintHostIP); - #endif - #endif - } - - debugUdp.beginPacket(debugPrintHostIP, netDebugPrintPort); + debugUdp.beginPacket(netDebugPrintIP, netDebugPrintPort); size = debugUdp.write(buf, size); debugUdp.endPacket(); return size; diff --git a/wled00/net_debug.h b/wled00/net_debug.h index 13028fdc1a..7226f33b17 100644 --- a/wled00/net_debug.h +++ b/wled00/net_debug.h @@ -7,7 +7,7 @@ class NetworkDebugPrinter : public Print { private: WiFiUDP debugUdp; // needs to be here otherwise UDP messages get truncated upon destruction - IPAddress debugPrintHostIP; + // IPAddress debugPrintHostIP; public: virtual size_t write(uint8_t c); virtual size_t write(const uint8_t *buf, size_t s); diff --git a/wled00/set.cpp b/wled00/set.cpp index fb516ac7d6..1a84f73677 100644 --- a/wled00/set.cpp +++ b/wled00/set.cpp @@ -523,6 +523,14 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) reconnectHue(); #endif + #ifdef WLED_ENABLE_NET_DEBUG + for (int i=0;i<4;i++){ + String a = "N"+String(i); + netDebugPrintIP[i] = request->arg(a).toInt(); + } + netDebugPrintPort = request->arg("NP").toInt(); + #endif + t = request->arg(F("BD")).toInt(); if (t >= 96 && t <= 15000) serialBaud = t; updateBaudRate(serialBaud *100); diff --git a/wled00/wled.cpp b/wled00/wled.cpp index eb6019e6bf..fd9d842d3a 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -384,7 +384,7 @@ void WLED::setup() #if defined(WLED_DEBUG) && defined(ARDUINO_ARCH_ESP32) && (defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || ARDUINO_USB_CDC_ON_BOOT) delay(2500); // allow CDC USB serial to initialise #endif - #if !defined(WLED_DEBUG) && defined(ARDUINO_ARCH_ESP32) && !defined(WLED_DEBUG_HOST) && ARDUINO_USB_CDC_ON_BOOT + #if !defined(WLED_DEBUG) && defined(ARDUINO_ARCH_ESP32) && !defined(WLED_ENABLE_NET_DEBUG) && ARDUINO_USB_CDC_ON_BOOT Serial.setDebugOutput(false); // switch off kernel messages when using USBCDC #endif DEBUG_PRINTLN(); @@ -442,7 +442,7 @@ void WLED::setup() usePWMFixedNMI(); // link the NMI fix #endif -#if defined(WLED_DEBUG) && !defined(WLED_DEBUG_HOST) +#if defined(WLED_DEBUG) && !defined(WLED_ENABLE_NET_DEBUG) PinManager::allocatePin(hardwareTX, true, PinOwner::DebugOut); // TX (GPIO1 on ESP32) reserved for debug output #endif #ifdef WLED_ENABLE_DMX //reserve GPIO2 as hardcoded DMX pin @@ -827,6 +827,33 @@ void WLED::initInterfaces() } #endif +#ifdef WLED_ENABLE_NET_DEBUG + if (netDebugPrintIP[0] == 0) { + if (!netDebugPrintIP && !netDebugPrintIP.fromString(WLED_DEBUG_HOST)) { + #ifdef ESP8266 + WiFi.hostByName(WLED_DEBUG_HOST, netDebugPrintIP, 750); + #else + #ifdef WLED_USE_ETHERNET + ETH.hostByName(WLED_DEBUG_HOST, netDebugPrintIP); + #else + WiFi.hostByName(WLED_DEBUG_HOST, netDebugPrintIP); + #endif + #endif + } else { + IPAddress ipAddress = Network.localIP(); + netDebugPrintIP[0] = ipAddress[0]; + netDebugPrintIP[1] = ipAddress[1]; + netDebugPrintIP[2] = ipAddress[2]; + } + } + if (netDebugPrintPort == 0) + #ifdef WLED_DEBUG_PORT + netDebugPrintPort = WLED_DEBUG_PORT; + #else + netDebugPrintPort = 7868; //Default value + #endif +#endif + #ifndef WLED_DISABLE_ALEXA // init Alexa hue emulation if (alexaEnabled) diff --git a/wled00/wled.h b/wled00/wled.h index 1a5f1b143e..b8ba128ca9 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -974,30 +974,39 @@ WLED_GLOBAL JsonDocument *pDoc _INIT(&gDoc); #endif WLED_GLOBAL volatile uint8_t jsonBufferLock _INIT(0); +// enable net debug output over UDP; use -D WLED_ENABLE_NET_DEBUG to activate. +// Legacy: defining WLED_DEBUG_HOST='"ip_or_host"' also enables net debug and +// pre-seeds the target IP at compile time. +#if defined(WLED_DEBUG_HOST) && !defined(WLED_ENABLE_NET_DEBUG) + #define WLED_ENABLE_NET_DEBUG +#endif + // enable additional debug output -#if defined(WLED_DEBUG_HOST) +#if defined(WLED_ENABLE_NET_DEBUG) #include "net_debug.h" // On the host side, use netcat to receive the log statements: nc -l 7868 -u - // use -D WLED_DEBUG_HOST='"192.168.xxx.xxx"' or FQDN within quotes - #define DEBUGOUT NetDebug - WLED_GLOBAL bool netDebugEnabled _INIT(true); - WLED_GLOBAL char netDebugPrintHost[33] _INIT(WLED_DEBUG_HOST); - #ifndef WLED_DEBUG_PORT - #define WLED_DEBUG_PORT 7868 - #endif - WLED_GLOBAL int netDebugPrintPort _INIT(WLED_DEBUG_PORT); + WLED_GLOBAL bool netDebugEnabled _INIT(false); + WLED_GLOBAL int netDebugPrintPort _INIT(0); + WLED_GLOBAL IPAddress netDebugPrintIP _INIT_N(((0, 0, 0, 0))); // IP address of the bridge + #define DEBUGOUT(x) netDebugEnabled?NetDebug.print(x):Serial.print(x) + #define DEBUGOUTLN(x) netDebugEnabled?NetDebug.println(x):Serial.println(x) + #define DEBUGOUTF(x...) netDebugEnabled?NetDebug.printf(x):Serial.printf(x) + #define DEBUGOUTFlush() netDebugEnabled?NetDebug.flush():Serial.flush() #else - #define DEBUGOUT Serial + #define DEBUGOUT(x) Serial.print(x) + #define DEBUGOUTLN(x) Serial.println(x) + #define DEBUGOUTF(x...) Serial.printf(x) + #define DEBUGOUTFlush() Serial.flush() #endif #ifdef WLED_DEBUG #ifndef ESP8266 #include #endif - #define DEBUG_PRINT(x) DEBUGOUT.print(x) - #define DEBUG_PRINTLN(x) DEBUGOUT.println(x) - #define DEBUG_PRINTF(x...) DEBUGOUT.printf(x) - #define DEBUG_PRINTF_P(x...) DEBUGOUT.printf_P(x) + #define DEBUG_PRINT(x) DEBUGOUT(x) + #define DEBUG_PRINTLN(x) DEBUGOUTLN(x) + #define DEBUG_PRINTF(x...) DEBUGOUTF(x) + #define DEBUG_PRINTF_P(x...) DEBUGOUTF(x) #else #define DEBUG_PRINT(x) #define DEBUG_PRINTLN(x) @@ -1005,10 +1014,31 @@ WLED_GLOBAL volatile uint8_t jsonBufferLock _INIT(0); #define DEBUG_PRINTF_P(x...) #endif +// macros to print "user messages" to Serial +// cannot do this on -S2, due to buggy USBCDC serial driver +#if defined(WLED_DEBUG) || defined(WLED_ENABLE_NET_DEBUG) + // use DEBUG_PRINT + #define USER_PRINT(x) DEBUG_PRINT(x) + #define USER_PRINTLN(x) DEBUG_PRINTLN(x) + #define USER_PRINTF(x...) DEBUG_PRINTF(x) + #ifdef WLED_ENABLE_NET_DEBUG + #define USER_FLUSH() {} + #else + #define USER_FLUSH() {DEBUGOUTFlush();} + #endif +#else + // if serial is available, we use Serial.print directly + #define USER_PRINT(x) { if (canUseSerial()) DEBUGOUT(x); } + #define USER_PRINTLN(x) { if (canUseSerial()) DEBUGOUTLN(x); } + #define USER_PRINTF(x...) { if (canUseSerial()) DEBUGOUTF(x); } + #define USER_FLUSH() {DEBUGOUTFlush();} +#endif + + #ifdef WLED_DEBUG_FS - #define DEBUGFS_PRINT(x) DEBUGOUT.print(x) - #define DEBUGFS_PRINTLN(x) DEBUGOUT.println(x) - #define DEBUGFS_PRINTF(x...) DEBUGOUT.printf(x) + #define DEBUGFS_PRINT(x) DEBUGOUT(x) + #define DEBUGFS_PRINTLN(x) DEBUGOUTLN(x) + #define DEBUGFS_PRINTF(x...) DEBUGOUTF(x) #else #define DEBUGFS_PRINT(x) #define DEBUGFS_PRINTLN(x) diff --git a/wled00/xml.cpp b/wled00/xml.cpp index 812ef8c207..6037f637a0 100644 --- a/wled00/xml.cpp +++ b/wled00/xml.cpp @@ -126,7 +126,7 @@ static void appendGPIOinfo(Print& settingsScript) settingsScript.print(2); // DMX hardcoded pin firstPin = false; #endif - #if defined(WLED_DEBUG) && !defined(WLED_DEBUG_HOST) + #if defined(WLED_DEBUG) && !defined(WLED_ENABLE_NET_DEBUG) if (!firstPin) settingsScript.print(','); settingsScript.print(hardwareTX); // debug output (TX) pin firstPin = false; @@ -586,6 +586,15 @@ void getSettingsJS(byte subPage, Print& settingsScript) #ifndef WLED_ENABLE_ADALIGHT settingsScript.print(F("toggle('Serial');")); #endif + + #ifdef WLED_ENABLE_NET_DEBUG + sappend('v',SET_F("N0"),netDebugPrintIP[0]); + sappend('v',SET_F("N1"),netDebugPrintIP[1]); + sappend('v',SET_F("N2"),netDebugPrintIP[2]); + sappend('v',SET_F("N3"),netDebugPrintIP[3]); + sappend('v',SET_F("NP"),netDebugPrintPort); + #endif + } if (subPage == SUBPAGE_TIME)