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);