diff --git a/src/CHANGES.md b/src/CHANGES.md index d5bc62a9..8e6855b0 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -1,8 +1,9 @@ # Development Changes -## 0.8.119 - 2024-05-16 +## 0.8.119 - 2024-05-17 * fix reset values at midnight if WiFi isn't available #1620 * fix typo in English versions +* add yield day to history graph #1614 ## 0.8.118 - 2024-05-10 * possible fix reset max values #1609 diff --git a/src/platformio.ini b/src/platformio.ini index efcc6e5f..ebf7ad41 100644 --- a/src/platformio.ini +++ b/src/platformio.ini @@ -163,6 +163,7 @@ build_flags = ${env:esp32-wroom32-minimal.build_flags} -DENABLE_MQTT -DPLUGIN_DISPLAY -DENABLE_HISTORY + -DENABLE_SIMULATOR monitor_filters = esp32_exception_decoder diff --git a/src/plugins/history.h b/src/plugins/history.h index 8531b463..bffbc6d5 100644 --- a/src/plugins/history.h +++ b/src/plugins/history.h @@ -62,9 +62,9 @@ class HistoryData { for (uint8_t i = 0; i < mSys->getNumInverters(); i++) { Inverter<> *iv = mSys->getInverterByPos(i); - record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug); if (iv == NULL) continue; + record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug); curPwr += iv->getChannelFieldValue(CH0, FLD_PAC, rec); yldDay += iv->getChannelFieldValue(CH0, FLD_YD, rec); if (rec->ts > ts) diff --git a/src/web/RestApi.h b/src/web/RestApi.h index f3477c92..f3ca6bc9 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -103,8 +103,8 @@ class RestApi { else if(path == "setup/getip") getIp(root); #endif /* !defined(ETHERNET) */ else if(path == "live") getLive(request,root); - else if (path == "powerHistory") getPowerHistory(request, root); - else if (path == "powerHistoryDay") getPowerHistoryDay(request, root); + else if (path == "powerHistory") getPowerHistory(request, root, HistoryStorageType::POWER); + else if (path == "powerHistoryDay") getPowerHistory(request, root, HistoryStorageType::POWER_DAY); else { if(path.substring(0, 12) == "inverter/id/") getInverter(root, request->url().substring(17).toInt()); @@ -927,40 +927,37 @@ class RestApi { } } - void getPowerHistory(AsyncWebServerRequest *request, JsonObject obj) { + void getPowerHistory(AsyncWebServerRequest *request, JsonObject obj, HistoryStorageType type) { getGeneric(request, obj.createNestedObject(F("generic"))); #if defined(ENABLE_HISTORY) - obj[F("refresh")] = mApp->getHistoryPeriod((uint8_t)HistoryStorageType::POWER); + obj[F("refresh")] = mApp->getHistoryPeriod(static_cast(type)); + 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); + uint16_t value = mApp->getHistoryValue(static_cast(type), fld); obj[F("value")][fld] = value; if (value > max) max = value; } obj[F("max")] = max; - obj[F("lastValueTs")] = mApp->getHistoryLastValueTs((uint8_t)HistoryStorageType::POWER); - #endif /*ENABLE_HISTORY*/ - } - void getPowerHistoryDay(AsyncWebServerRequest *request, JsonObject obj){ - //getGeneric(request, obj.createNestedObject(F("generic"))); - #if defined(ENABLE_HISTORY) - obj[F("refresh")] = mApp->getHistoryPeriod((uint8_t)HistoryStorageType::POWER_DAY); - uint16_t max = 0; - for (uint16_t fld = 0; fld < HISTORY_DATA_ARR_LENGTH; fld++) { - uint16_t value = mApp->getHistoryValue((uint8_t)HistoryStorageType::POWER_DAY, fld); - obj[F("value")][fld] = value; - if (value > max) - max = value; + if(HistoryStorageType::POWER_DAY == type) { + float yldDay = 0; + for (uint8_t i = 0; i < mSys->getNumInverters(); i++) { + Inverter<> *iv = mSys->getInverterByPos(i); + if (iv == NULL) + continue; + record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug); + yldDay += iv->getChannelFieldValue(CH0, FLD_YD, rec); + } + obj[F("yld")] = ah::round3(yldDay / 1000.0); } - obj[F("max")] = max; - obj[F("lastValueTs")] = mApp->getHistoryLastValueTs((uint8_t)HistoryStorageType::POWER_DAY); + + obj[F("lastValueTs")] = mApp->getHistoryLastValueTs(static_cast(type)); #endif /*ENABLE_HISTORY*/ } - - void getYieldDayHistory(AsyncWebServerRequest *request, JsonObject obj) { + /*void getYieldDayHistory(AsyncWebServerRequest *request, JsonObject obj) { //getGeneric(request, obj.createNestedObject(F("generic"))); #if defined(ENABLE_HISTORY) && defined(ENABLE_HISTORY_YIELD_PER_DAY) obj[F("refresh")] = mApp->getHistoryPeriod((uint8_t)HistoryStorageType::YIELD); @@ -972,8 +969,8 @@ class RestApi { max = value; } obj[F("max")] = max; - #endif /*ENABLE_HISTORY*/ - } + #endif + }*/ bool setCtrl(JsonObject jsonIn, JsonObject jsonOut, const char *clientIP) { if(jsonIn.containsKey(F("auth"))) { diff --git a/src/web/html/history.html b/src/web/html/history.html index 2a13f572..08227b1f 100644 --- a/src/web/html/history.html +++ b/src/web/html/history.html @@ -133,12 +133,17 @@ } let pts2 = pts + " " + String(last) + "," + String(height) pts2 += " " + String(first) + "," + String(height) - return [ + elm = [ mlNs("polyline", {stroke: "url(#gLine)", fill: "none", points: pts}), mlNs("polyline", {stroke: "none", fill: "url(#gFill)", points: pts2}), mlNs("text", {x: i*.8, y: 10}, "{#MAXIMUM}: " + String(obj.max) + "W"), mlNs("text", {x: i*.8, y: 25}, "{#LAST_VALUE}: " + String(lastVal) + "W") ] + + if(undefined !== obj.yld) + elm.push(mlNs("text", {x: i*.8, y: 40}, "{#YIELD_DAY}: " + String(obj.yld) + "kWh")) + + return elm; } diff --git a/src/web/lang.json b/src/web/lang.json index 901b53ed..0b0754b2 100644 --- a/src/web/lang.json +++ b/src/web/lang.json @@ -1587,6 +1587,11 @@ "token": "LAST_VALUE", "en": "Last value", "de": "Letzter Wert" + }, + { + "token": "YIELD_DAY", + "en": "Yield day", + "de": "Tagesertrag" } ] }