Merge branch 'VArt67-Merge-to-upstream' into development03

This commit is contained in:
lumapu 2024-01-09 20:49:00 +01:00
commit fa32906707
12 changed files with 353 additions and 12 deletions

View file

@ -22,6 +22,8 @@
#include "ESPAsyncWebServer.h"
#endif
#include "plugins/history.h"
#if defined(F) && defined(ESP32)
#undef F
#define F(sl) (sl)
@ -103,6 +105,8 @@ class RestApi {
else if(path == "setup/getip") getWifiIp(root);
#endif /* !defined(ETHERNET) */
else if(path == "live") getLive(request,root);
else if (path == "powerHistory") getPowerHistory(request, root);
else if (path == "yieldDayHistory") getYieldDayHistory(request, root);
else {
if(path.substring(0, 12) == "inverter/id/")
getInverter(root, request->url().substring(17).toInt());
@ -197,6 +201,8 @@ class RestApi {
ep[F("setup")] = url + F("setup");
ep[F("system")] = url + F("system");
ep[F("live")] = url + F("live");
ep[F("powerHistory")] = url + F("powerHistory");
ep[F("yieldDayHistory")] = url + F("yieldDayHistory");
}
@ -785,6 +791,36 @@ class RestApi {
}
}
void getPowerHistory(AsyncWebServerRequest *request, JsonObject obj) {
getGeneric(request, obj.createNestedObject(F("generic")));
obj[F("refresh")] = mConfig->inst.sendInterval;
obj[F("datapoints")] = HISTORY_DATA_ARR_LENGTH;
uint16_t max = 0;
for (uint16_t fld = 0; fld < HISTORY_DATA_ARR_LENGTH; fld++) {
uint16_t value = mApp->getHistoryValue((uint8_t)HistoryStorageType::POWER, fld);
obj[F("value")][fld] = value;
if (value > max)
max = value;
}
obj[F("max")] = max;
obj[F("maxDay")] = mApp->getHistoryMaxDay();
}
void getYieldDayHistory(AsyncWebServerRequest *request, JsonObject obj) {
getGeneric(request, obj.createNestedObject(F("generic")));
obj[F("refresh")] = 86400; // 1 day
obj[F("datapoints")] = HISTORY_DATA_ARR_LENGTH;
uint16_t max = 0;
for (uint16_t fld = 0; fld < HISTORY_DATA_ARR_LENGTH; fld++) {
uint16_t value = mApp->getHistoryValue((uint8_t)HistoryStorageType::YIELD, fld);
obj[F("value")][fld] = value;
if (value > max)
max = value;
}
obj[F("max")] = max;
}
bool setCtrl(JsonObject jsonIn, JsonObject jsonOut) {
Inverter<> *iv = mSys->getInverterByPos(jsonIn[F("id")]);
bool accepted = true;