simplify calculations in WebApi_ws_Live
This commit is contained in:
parent
7bc1a17fac
commit
16fbad92ac
@ -44,6 +44,12 @@ void WebApiWsLiveClass::wsCleanupTaskCb()
|
|||||||
{
|
{
|
||||||
// see: https://github.com/me-no-dev/ESPAsyncWebServer#limiting-the-number-of-web-socket-clients
|
// see: https://github.com/me-no-dev/ESPAsyncWebServer#limiting-the-number-of-web-socket-clients
|
||||||
_ws.cleanupClients();
|
_ws.cleanupClients();
|
||||||
|
|
||||||
|
if (Configuration.get().Security.AllowReadonly) {
|
||||||
|
_ws.setAuthentication("", "");
|
||||||
|
} else {
|
||||||
|
_ws.setAuthentication(AUTH_USERNAME, Configuration.get().Security.Password);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebApiWsLiveClass::sendDataTaskCb()
|
void WebApiWsLiveClass::sendDataTaskCb()
|
||||||
@ -56,10 +62,7 @@ void WebApiWsLiveClass::sendDataTaskCb()
|
|||||||
uint32_t maxTimeStamp = 0;
|
uint32_t maxTimeStamp = 0;
|
||||||
for (uint8_t i = 0; i < Hoymiles.getNumInverters(); i++) {
|
for (uint8_t i = 0; i < Hoymiles.getNumInverters(); i++) {
|
||||||
auto inv = Hoymiles.getInverterByPos(i);
|
auto inv = Hoymiles.getInverterByPos(i);
|
||||||
|
maxTimeStamp = std::max<uint32_t>(maxTimeStamp, inv->Statistics()->getLastUpdate());
|
||||||
if (inv->Statistics()->getLastUpdate() > maxTimeStamp) {
|
|
||||||
maxTimeStamp = inv->Statistics()->getLastUpdate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update on every inverter change or at least after 10 seconds
|
// Update on every inverter change or at least after 10 seconds
|
||||||
@ -75,13 +78,8 @@ void WebApiWsLiveClass::sendDataTaskCb()
|
|||||||
String buffer;
|
String buffer;
|
||||||
serializeJson(root, 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);
|
||||||
|
_newestInverterTimestamp = maxTimeStamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (const std::bad_alloc& bad_alloc) {
|
} catch (const std::bad_alloc& bad_alloc) {
|
||||||
@ -161,10 +159,6 @@ void WebApiWsLiveClass::generateJsonResponse(JsonVariant& root)
|
|||||||
} else {
|
} else {
|
||||||
invObject["events"] = -1;
|
invObject["events"] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inv->Statistics()->getLastUpdate() > _newestInverterTimestamp) {
|
|
||||||
_newestInverterTimestamp = inv->Statistics()->getLastUpdate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonObject totalObj = root.createNestedObject("total");
|
JsonObject totalObj = root.createNestedObject("total");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user