diff --git a/src/WebApi_ws_live.cpp b/src/WebApi_ws_live.cpp index fedc9fff..0e2cd61f 100644 --- a/src/WebApi_ws_live.cpp +++ b/src/WebApi_ws_live.cpp @@ -59,25 +59,29 @@ 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); - DynamicJsonDocument root(40960); - JsonVariant var = root; - generateJsonResponse(var); + String buffer; + if (buffer) { + serializeJson(root, buffer); - String buffer; - if (buffer) { - serializeJson(root, buffer); + if (Configuration.get().Security_AllowReadonly) { + _ws.setAuthentication("", ""); + } else { + _ws.setAuthentication(AUTH_USERNAME, Configuration.get().Security_Password); + } - if (Configuration.get().Security_AllowReadonly) { - _ws.setAuthentication("", ""); - } else { - _ws.setAuthentication(AUTH_USERNAME, Configuration.get().Security_Password); + _ws.textAll(buffer); } - _ws.textAll(buffer); + _lastWsPublish = millis(); + } + catch (std::bad_alloc& bad_alloc) { + MessageOutput.printf("Call to /api/livedata/status temporarely out of resources. Reason: \"%s\".", bad_alloc.what()); } - - _lastWsPublish = millis(); } } diff --git a/src/WebApi_ws_vedirect_live.cpp b/src/WebApi_ws_vedirect_live.cpp index fcf1224e..d7407f47 100644 --- a/src/WebApi_ws_vedirect_live.cpp +++ b/src/WebApi_ws_vedirect_live.cpp @@ -55,25 +55,29 @@ 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); - DynamicJsonDocument root(1024); - JsonVariant var = root; - generateJsonResponse(var); + String buffer; + if (buffer) { + serializeJson(root, buffer); + + if (Configuration.get().Security_AllowReadonly) { + _ws.setAuthentication("", ""); + } else { + _ws.setAuthentication(AUTH_USERNAME, Configuration.get().Security_Password); + } - String buffer; - if (buffer) { - serializeJson(root, buffer); - - if (Configuration.get().Security_AllowReadonly) { - _ws.setAuthentication("", ""); - } else { - _ws.setAuthentication(AUTH_USERNAME, Configuration.get().Security_Password); - } + _ws.textAll(buffer); + } - _ws.textAll(buffer); + _lastWsPublish = millis(); + } + catch (std::bad_alloc& bad_alloc) { + MessageOutput.printf("Call to /api/vedirectlivedata/status temporarely out of resources. Reason: \"%s\".", bad_alloc.what()); } - - _lastWsPublish = millis(); } }