Optimization & bugfix for net debug.

- Inherited from Print class.
- Added UI option to disable net  debug output.
This commit is contained in:
Blaz Kristan 2022-11-10 21:50:21 +01:00
parent 5f4199183c
commit d370f67f60
6 changed files with 1935 additions and 1952 deletions

View File

@ -657,12 +657,13 @@ function populateInfo(i)
}
var vcn = "Kuuhaku";
if (i.ver.startsWith("0.14.")) vcn = "Hoshi";
if (i.ver.includes("-bl")) vcn = "Supāku";
// if (i.ver.includes("-bl")) vcn = "Supāku";
if (i.cn) vcn = i.cn;
cn += `v${i.ver} "${vcn}"<br><br><table>
${urows}
${urows===""?'':'<tr><td colspan=2><hr style="height:1px;border-width:0;color:gray;background-color:gray"></td></tr>'}
${i.opt&0x100?inforow("Debug","<button class=\"btn btn-xs\" onclick=\"requestJson({'debug':"+(i.opt&0x0080?"false":"true")+"});\"><i class=\"icons "+(i.opt&0x0080?"on":"off")+"\">&#xe08f;</i></button>"):''}
${inforow("Build",i.vid)}
${inforow("Signal strength",i.wifi.signal +"% ("+ i.wifi.rssi, " dBm)")}
${inforow("Uptime",getRuntimeStr(i.uptime))}

File diff suppressed because it is too large Load Diff

View File

@ -255,6 +255,10 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
{
bool stateResponse = root[F("v")] | false;
#if defined(WLED_DEBUG) && defined(WLED_DEBUG_HOST)
netDebugEnabled = root[F("debug")] | netDebugEnabled;
#endif
bool onBefore = bri;
getVal(root["bri"], &bri);
@ -679,9 +683,13 @@ void serializeInfo(JsonObject root)
usermods.addToJsonInfo(root);
byte os = 0;
uint16_t os = 0;
#ifdef WLED_DEBUG
os = 0x80;
#ifdef WLED_DEBUG_HOST
os |= 0x0100;
if (!netDebugEnabled) os &= ~0x0080;
#endif
#endif
#ifndef WLED_DISABLE_ALEXA
os += 0x40;

View File

@ -2,10 +2,8 @@
#ifdef WLED_DEBUG_HOST
NetworkDebugPrinter NetDebug;
void NetworkDebugPrinter::print(const char *s, bool newline) {
if (!WLED_CONNECTED || !udpConnected || s == nullptr) return;
size_t NetworkDebugPrinter::write(uint8_t c) {
if (!WLED_CONNECTED || !udpConnected) return 0;
if (!debugPrintHostIP && !debugPrintHostIP.fromString(netDebugPrintHost)) {
#ifdef ESP8266
@ -19,57 +17,33 @@ void NetworkDebugPrinter::print(const char *s, bool newline) {
#endif
}
WiFiUDP debugUdp;
debugUdp.beginPacket(debugPrintHostIP, netDebugPrintPort);
debugUdp.write(reinterpret_cast<const uint8_t *>(s), strlen(s));
if (newline) debugUdp.write('\n');
debugUdp.write(c);
debugUdp.endPacket();
return 1;
}
void NetworkDebugPrinter::print(const __FlashStringHelper* s, bool newline) {
char buf[512];
strncpy_P(buf, (PGM_P)s, 512);
print(buf, newline);
size_t NetworkDebugPrinter::write(const uint8_t *buf, size_t size) {
if (!WLED_CONNECTED || !udpConnected || buf == nullptr) 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.write(buf, size);
debugUdp.endPacket();
return size;
}
void NetworkDebugPrinter::print(String s) {
print(s.c_str());
}
void NetworkDebugPrinter::print(unsigned int n, bool newline) {
char s[10];
snprintf_P(s, sizeof(s), PSTR("%d"), n);
s[9] = '\0';
print(s, newline);
}
void NetworkDebugPrinter::println() {
print("", true);
}
void NetworkDebugPrinter::println(const char *s) {
print(s, true);
}
void NetworkDebugPrinter::println(const __FlashStringHelper* s) {
print(s, true);
}
void NetworkDebugPrinter::println(String s) {
print(s.c_str(), true);
}
void NetworkDebugPrinter::println(unsigned int n) {
print(n, true);
}
void NetworkDebugPrinter::printf(const char *fmt...) {
va_list args;
va_start(args, fmt);
char s[1024];
vsnprintf(s, sizeof(s), fmt, args);
va_end(args);
print(s);
}
NetworkDebugPrinter NetDebug;
#endif

View File

@ -4,20 +4,13 @@
#include <WString.h>
#include <WiFiUdp.h>
class NetworkDebugPrinter {
private:
class NetworkDebugPrinter : public Print {
private:
WiFiUDP debugUdp; // needs to be here otherwise UDP messages get truncated upon destruction
IPAddress debugPrintHostIP;
public:
void print(const char *s, bool newline = false);
void print(const __FlashStringHelper* s, bool newline = false);
void print(String s);
void print(unsigned int n, bool newline = false);
void println();
void println(const char *s);
void println(const __FlashStringHelper* s);
void println(String s);
void println(unsigned int n);
void printf(const char *fmt, ...);
public:
virtual size_t write(uint8_t c);
virtual size_t write(const uint8_t *buf, size_t s);
};
extern NetworkDebugPrinter NetDebug;

View File

@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2211050
#define VERSION 2211100
//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG
@ -677,6 +677,7 @@ WLED_GLOBAL volatile uint8_t jsonBufferLock _INIT(0);
// 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);
#if defined(WLED_DEBUG_NET_PORT)
WLED_GLOBAL int netDebugPrintPort _INIT(WLED_DEBUG_PORT);