Skip to content

Commit

Permalink
Fix: Workaround: Don't allow memory intensive web functions in parallel
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tbnobody committed Sep 1, 2023
1 parent 2c41be1 commit b34b22c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/WebApi_ws_live.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ class WebApiWsLiveClass {
uint32_t _lastInvUpdateCheck = 0;
uint32_t _lastWsCleanup = 0;
uint32_t _newestInverterTimestamp = 0;

std::mutex _mutex;
};
6 changes: 4 additions & 2 deletions src/WebApi_ws_live.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ void WebApiWsLiveClass::loop()
if (millis() - _lastWsPublish > (10 * 1000) || (maxTimeStamp != _newestInverterTimestamp)) {

try {
DynamicJsonDocument root(40960);
std::lock_guard<std::mutex> lock(_mutex);
DynamicJsonDocument root(4096 * INV_MAX_COUNT);
JsonVariant var = root;
generateJsonResponse(var);

Expand Down Expand Up @@ -221,7 +222,8 @@ void WebApiWsLiveClass::onLivedataStatus(AsyncWebServerRequest* request)
}

try {
AsyncJsonResponse* response = new AsyncJsonResponse(false, 40960U);
std::lock_guard<std::mutex> lock(_mutex);
AsyncJsonResponse* response = new AsyncJsonResponse(false, 4096 * INV_MAX_COUNT);
JsonVariant root = response->getRoot();

generateJsonResponse(root);
Expand Down

0 comments on commit b34b22c

Please sign in to comment.