From b34b22c6583ecb966c1ea135e6a078634081c174 Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Sat, 2 Sep 2023 01:41:53 +0200 Subject: [PATCH] Fix: Workaround: Don't allow memory intensive web functions in parallel Somehow the API has to be adjusted to reduce memory consumption. For now lets just prevent both methods to allocate memory at the same time. --- include/WebApi_ws_live.h | 2 ++ src/WebApi_ws_live.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/WebApi_ws_live.h b/include/WebApi_ws_live.h index 0cf1449b5..1e6649200 100644 --- a/include/WebApi_ws_live.h +++ b/include/WebApi_ws_live.h @@ -25,4 +25,6 @@ class WebApiWsLiveClass { uint32_t _lastInvUpdateCheck = 0; uint32_t _lastWsCleanup = 0; uint32_t _newestInverterTimestamp = 0; + + std::mutex _mutex; }; \ No newline at end of file diff --git a/src/WebApi_ws_live.cpp b/src/WebApi_ws_live.cpp index 8b7c6a2e1..5ab468d8e 100644 --- a/src/WebApi_ws_live.cpp +++ b/src/WebApi_ws_live.cpp @@ -62,7 +62,8 @@ void WebApiWsLiveClass::loop() if (millis() - _lastWsPublish > (10 * 1000) || (maxTimeStamp != _newestInverterTimestamp)) { try { - DynamicJsonDocument root(40960); + std::lock_guard lock(_mutex); + DynamicJsonDocument root(4096 * INV_MAX_COUNT); JsonVariant var = root; generateJsonResponse(var); @@ -221,7 +222,8 @@ void WebApiWsLiveClass::onLivedataStatus(AsyncWebServerRequest* request) } try { - AsyncJsonResponse* response = new AsyncJsonResponse(false, 40960U); + std::lock_guard lock(_mutex); + AsyncJsonResponse* response = new AsyncJsonResponse(false, 4096 * INV_MAX_COUNT); JsonVariant root = response->getRoot(); generateJsonResponse(root);