LiveService if out of ressources close websocket

This commit is contained in:
helgeerbe 2023-02-22 15:46:52 +01:00
parent 0f80a25937
commit a758d894f6
2 changed files with 36 additions and 28 deletions

View File

@ -59,7 +59,7 @@ void WebApiWsLiveClass::loop()
// Update on every inverter change or at least after 10 seconds
if (millis() - _lastWsPublish > (10 * 1000) || (maxTimeStamp != _newestInverterTimestamp)) {
try {
DynamicJsonDocument root(40960);
JsonVariant var = root;
generateJsonResponse(var);
@ -79,6 +79,10 @@ void WebApiWsLiveClass::loop()
_lastWsPublish = millis();
}
catch (std::bad_alloc& bad_alloc) {
MessageOutput.printf("Call to /api/livedata/status temporarely out of resources. Reason: \"%s\".", bad_alloc.what());
}
}
}
void WebApiWsLiveClass::generateJsonResponse(JsonVariant& root)

View File

@ -55,7 +55,7 @@ void WebApiWsVedirectLiveClass::loop()
// Update on ve.direct change or at least after 10 seconds
if (millis() - _lastWsPublish > (10 * 1000) || (maxTimeStamp != _newestVedirectTimestamp)) {
try {
DynamicJsonDocument root(1024);
JsonVariant var = root;
generateJsonResponse(var);
@ -75,6 +75,10 @@ void WebApiWsVedirectLiveClass::loop()
_lastWsPublish = millis();
}
catch (std::bad_alloc& bad_alloc) {
MessageOutput.printf("Call to /api/vedirectlivedata/status temporarely out of resources. Reason: \"%s\".", bad_alloc.what());
}
}
}
void WebApiWsVedirectLiveClass::generateJsonResponse(JsonVariant& root)