From 6b9b9dad187e0325906ba156b43de33a939bf6be Mon Sep 17 00:00:00 2001 From: electron-rare <108685187+electron-rare@users.noreply.github.com> Date: Wed, 11 Mar 2026 06:48:30 +0100 Subject: [PATCH] fix(wled): remove websocket deprecations and duplicate bus macro Co-Authored-By: easter_egg <108685187+electron-rare@users.noreply.github.com> --- wled00/bus_wrapper.h | 11 ++--------- wled00/ws.cpp | 36 +++++++++++++++--------------------- 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/wled00/bus_wrapper.h b/wled00/bus_wrapper.h index e7851564..f681c0a8 100644 --- a/wled00/bus_wrapper.h +++ b/wled00/bus_wrapper.h @@ -174,14 +174,7 @@ /*** ESP32 Neopixel methods ***/ #ifdef ARDUINO_ARCH_ESP32 -//TM1934 (Warm White, Middle White, Cold White) -#define B_32_RN_NEO_3 NeoPixelBusLg -#ifndef WLED_NO_I2S0_PIXELBUS -#define B_32_I0_NEO_3 NeoPixelBusLg -#endif -#ifndef WLED_NO_I2S1_PIXELBUS -#define B_32_I1_NEO_3 NeoPixelBusLg -#endif +//TM1934 currently reuses the generic NEO_3 transport mapping below. //RGB #define B_32_RN_NEO_3 NeoPixelBusLg #ifndef WLED_NO_I2S0_PIXELBUS @@ -1241,4 +1234,4 @@ class PolyBus { } }; -#endif \ No newline at end of file +#endif diff --git a/wled00/ws.cpp b/wled00/ws.cpp index b8c85d50..c1479919 100644 --- a/wled00/ws.cpp +++ b/wled00/ws.cpp @@ -99,7 +99,7 @@ void wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTyp void sendDataWs(AsyncWebSocketClient * client) { if (!ws.count()) return; - AsyncWebSocketMessageBuffer * buffer; + char * payload = nullptr; if (!requestJSONBufferLock(12)) return; @@ -112,42 +112,36 @@ void sendDataWs(AsyncWebSocketClient * client) DEBUG_PRINTF("JSON buffer size: %u for WS request (%u).\n", doc.memoryUsage(), len); size_t heap1 = ESP.getFreeHeap(); + (void)heap1; DEBUG_PRINT(F("heap ")); DEBUG_PRINTLN(ESP.getFreeHeap()); #ifdef ESP8266 if (len>heap1) { DEBUG_PRINTLN(F("Out of memory (WS)!")); + releaseJSONBufferLock(); return; } #endif - buffer = ws.makeBuffer(len); // will not allocate correct memory sometimes on ESP8266 - #ifdef ESP8266 - size_t heap2 = ESP.getFreeHeap(); - DEBUG_PRINT(F("heap ")); DEBUG_PRINTLN(ESP.getFreeHeap()); - #else - size_t heap2 = 0; // ESP32 variants do not have the same issue and will work without checking heap allocation - #endif - if (!buffer || heap1-heap2(malloc(len + 1U)); + if (!payload) { releaseJSONBufferLock(); DEBUG_PRINTLN(F("WS buffer allocation failed.")); ws.closeAll(1013); //code 1013 = temporary overload, try again later ws.cleanupClients(0); //disconnect all clients to release memory - ws._cleanBuffers(); return; //out of memory } - buffer->lock(); - serializeJson(doc, (char *)buffer->get(), len); + serializeJson(doc, payload, len + 1U); + payload[len] = '\0'; DEBUG_PRINT(F("Sending WS data ")); if (client) { - client->text(buffer); + client->text(payload, len); DEBUG_PRINTLN(F("to a single client.")); } else { - ws.textAll(buffer); + ws.textAll(payload, len); DEBUG_PRINTLN(F("to multiple clients.")); } - buffer->unlock(); - ws._cleanBuffers(); + free(payload); releaseJSONBufferLock(); } @@ -167,9 +161,8 @@ bool sendLiveLedsWs(uint32_t wsClient) size_t pos = (strip.isMatrix ? 4 : 2); // start of data size_t bufSize = pos + (used/n)*3; - AsyncWebSocketMessageBuffer * wsBuf = ws.makeBuffer(bufSize); - if (!wsBuf) return false; //out of memory - uint8_t* buffer = wsBuf->get(); + uint8_t* buffer = static_cast(malloc(bufSize)); + if (!buffer) return false; //out of memory buffer[0] = 'L'; buffer[1] = 1; //version @@ -208,7 +201,8 @@ bool sendLiveLedsWs(uint32_t wsClient) buffer[pos++] = scale8(qadd8(w, b), strip.getBrightness()); //B } - wsc->binary(wsBuf); + wsc->binary(buffer, bufSize); + free(buffer); return true; } @@ -231,4 +225,4 @@ void handleWs() #else void handleWs() {} void sendDataWs(AsyncWebSocketClient * client) {} -#endif \ No newline at end of file +#endif