diff --git a/wled00/const.h b/wled00/const.h index 51c3d496..902521ae 100644 --- a/wled00/const.h +++ b/wled00/const.h @@ -302,9 +302,9 @@ #endif #ifdef WLED_USE_DYNAMIC_JSON - #define MIN_HEAP_SIZE JSON_BUFFER_SIZE+512 + #define MIN_HEAP_SIZE (JSON_BUFFER_SIZE+512) #else - #define MIN_HEAP_SIZE 4096 + #define MIN_HEAP_SIZE (MAX_LED_MEMORY+2048) #endif // Maximum size of node map (list of other WLED instances) diff --git a/wled00/ws.cpp b/wled00/ws.cpp index 0cb9d539..1d4e524f 100644 --- a/wled00/ws.cpp +++ b/wled00/ws.cpp @@ -117,8 +117,10 @@ void sendDataWs(AsyncWebSocketClient * client) serializeInfo(info); DEBUG_PRINTF("JSON buffer size: %u for WS request.\n", doc.memoryUsage()); size_t len = measureJson(doc); - buffer = ws.makeBuffer(len); - if (!buffer) { + size_t heap1 = ESP.getFreeHeap(); + buffer = ws.makeBuffer(len); // will not allocate correct memory sometimes + size_t heap2 = ESP.getFreeHeap(); + if (!buffer || heap1-heap2 WS_LIVE_INTERVAL) { + #ifdef ESP8266 + ws.cleanupClients(2); + #else ws.cleanupClients(); + #endif bool success = true; - if (wsLiveClientId) - success = serveLiveLeds(nullptr, wsLiveClientId); + if (wsLiveClientId) success = serveLiveLeds(nullptr, wsLiveClientId); wsLastLiveTime = millis(); if (!success) wsLastLiveTime -= 20; //try again in 20ms if failed due to non-empty WS queue }