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,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();
}
}

View File

@ -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();
}
}