From 7ae38649ad539f6fb4715fc12e09a60cff076771 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Fri, 23 Feb 2024 10:24:26 +0100 Subject: [PATCH] post merge MM specific adjustments --- wled00/util.cpp | 8 ++++---- wled00/wled.h | 4 ++++ wled00/wled_serial.cpp | 2 +- wled00/wled_server.cpp | 6 +++++- wled00/ws.cpp | 4 ++-- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/wled00/util.cpp b/wled00/util.cpp index bea68c48..31f9716c 100644 --- a/wled00/util.cpp +++ b/wled00/util.cpp @@ -204,12 +204,12 @@ bool requestJSONBufferLock(uint8_t module) { unsigned long now = millis(); - while (jsonBufferLock && millis()-now < 100) delay(1); // wait for fraction for buffer lock + while (jsonBufferLock && millis()-now < 1200) delay(1); // wait for fraction for buffer lock if (jsonBufferLock) { - DEBUG_PRINT(F("ERROR: Locking JSON buffer failed! (still locked by ")); - DEBUG_PRINT(jsonBufferLock); - DEBUG_PRINTLN(")"); + USER_PRINT(F("ERROR: Locking JSON buffer failed! (still locked by ")); + USER_PRINT(jsonBufferLock); + USER_PRINTLN(")"); return false; // waiting time-outed } diff --git a/wled00/wled.h b/wled00/wled.h index 3994a48f..6a3f386a 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -822,11 +822,13 @@ WLED_GLOBAL volatile uint8_t jsonBufferLock _INIT(0); #define DEBUGOUT(x) (netDebugEnabled || !canUseSerial())?NetDebug.print(x):Serial.print(x) #define DEBUGOUTLN(x) (netDebugEnabled || !canUseSerial())?NetDebug.println(x):Serial.println(x) #define DEBUGOUTF(x...) (netDebugEnabled || !canUseSerial())?NetDebug.printf(x):Serial.printf(x) + #define DEBUGOUTFP(x...) (netDebugEnabled || !canUseSerial())?NetDebug.printf_P(x):Serial.printf_P(x) #define DEBUGOUTFlush() (netDebugEnabled || !canUseSerial())?NetDebug.flush():Serial.flush() #else #define DEBUGOUT(x) {if (canUseSerial()) Serial.print(x);} #define DEBUGOUTLN(x) {if (canUseSerial()) Serial.println(x);} #define DEBUGOUTF(x...) {if (canUseSerial()) Serial.printf(x);} + #define DEBUGOUTFP(x...) {if (canUseSerial()) Serial.printf_P(x);} #define DEBUGOUTFlush() {if (canUseSerial()) Serial.flush();} #endif @@ -837,10 +839,12 @@ WLED_GLOBAL volatile uint8_t jsonBufferLock _INIT(0); #define DEBUG_PRINT(x) DEBUGOUT(x) #define DEBUG_PRINTLN(x) DEBUGOUTLN(x) #define DEBUG_PRINTF(x...) DEBUGOUTF(x) + #define DEBUG_PRINTF_P(x...) DEBUGOUTFP(x) #else #define DEBUG_PRINT(x) #define DEBUG_PRINTLN(x) #define DEBUG_PRINTF(x...) + #define DEBUG_PRINTF_P(x...) #endif #define USER_PRINT(x) DEBUGOUT(x) diff --git a/wled00/wled_serial.cpp b/wled00/wled_serial.cpp index b46bb60a..596b5791 100644 --- a/wled00/wled_serial.cpp +++ b/wled00/wled_serial.cpp @@ -137,7 +137,7 @@ void handleSerial() } else if (next == '{') { //JSON API bool verboseResponse = false; if (!requestJSONBufferLock(16)) { - Serial.println(F("{\"error\":3}")); // ERR_NOBUF + if (Serial) Serial.println(F("{\"error\":3}")); // ERR_NOBUF return; } Serial.setTimeout(100); diff --git a/wled00/wled_server.cpp b/wled00/wled_server.cpp index 8751119e..84b0a3db 100644 --- a/wled00/wled_server.cpp +++ b/wled00/wled_server.cpp @@ -193,7 +193,11 @@ void initServer() bool verboseResponse = false; bool isConfig = false; - if (!requestJSONBufferLock(14)) return; + if (!requestJSONBufferLock(14)) { + // serveJsonError(request, 503, ERR_NOBUF); //WLEDMM we dont have this function, so we'll send the error response "old style" + request->send(503, "application/json", F("{\"error\":3}")); // ERR_NOBUF + return; + } DeserializationError error = deserializeJson(doc, (uint8_t*)(request->_tempObject)); JsonObject root = doc.as(); diff --git a/wled00/ws.cpp b/wled00/ws.cpp index 0437a56c..85f75406 100644 --- a/wled00/ws.cpp +++ b/wled00/ws.cpp @@ -123,8 +123,8 @@ void sendDataWs(AsyncWebSocketClient * client) JsonObject info = doc.createNestedObject("info"); serializeInfo(info); - size_t len = measureJson(*pDoc); - DEBUG_PRINTF("JSON buffer size: %u for WS request (%u).\n", pDoc->memoryUsage(), len); + size_t len = measureJson(doc); + DEBUG_PRINTF("JSON buffer size: %u for WS request (%u).\n", doc.memoryUsage(), len); #ifdef ESP8266 size_t heap1 = ESP.getFreeHeap(); // WLEDMM moved into 8266 specific section