diff --git a/src/CHANGES.md b/src/CHANGES.md index 53485e03..87e18bb3 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -1,8 +1,13 @@ # Development Changes +## 0.8.116 - 2024-05-05 +* calculation of max AC power +* fix counter overflow communication queue +* added max inverter temperature + ## 0.8.115 - 2024-05-03 * fix inverter communication with manual time sync #1603 -* improved queue, only add new object once they not exist +* improved queue, only add new object once they not exist in queue * added option to reset values on communication start (sunrise) * fixed calculation of max AC power (API, MqTT) diff --git a/src/app.cpp b/src/app.cpp index dd7048e9..8ee943da 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -361,6 +361,8 @@ void app::tickMidnight(void) { uint8_t pos = iv->getPosByChFld(i, FLD_MP, rec); iv->setValue(pos, rec, 0.0f); } + if(InverterStatus::OFF == iv->getStatus()) + iv->resetAlarms(true); } } @@ -435,6 +437,9 @@ bool app::sendIv(Inverter<> *iv) { void app:: zeroIvValues(bool checkAvail, bool skipYieldDay) { Inverter<> *iv; bool changed = false; + + mMaxPower.reset(); + // set values to zero, except yields for (uint8_t id = 0; id < mSys.getNumInverters(); id++) { iv = mSys.getInverterByPos(id); @@ -470,7 +475,7 @@ void app:: zeroIvValues(bool checkAvail, bool skipYieldDay) { pos = iv->getPosByChFld(ch, FLD_MP, rec); iv->setValue(pos, rec, 0.0f); } - iv->resetAlarms(); + iv->resetAlarms(true); iv->doCalculations(); } } diff --git a/src/defines.h b/src/defines.h index 4aad1ee1..16b21456 100644 --- a/src/defines.h +++ b/src/defines.h @@ -13,7 +13,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 8 -#define VERSION_PATCH 115 +#define VERSION_PATCH 116 //------------------------------------- typedef struct { uint8_t ch; diff --git a/src/hm/CommQueue.h b/src/hm/CommQueue.h index 7164d773..bf6f6861 100644 --- a/src/hm/CommQueue.h +++ b/src/hm/CommQueue.h @@ -131,7 +131,7 @@ class CommQueue { if(mQueue[ptr].iv->id == q->iv->id) return true; } - ptr++; + inc(&ptr); } return false; } diff --git a/src/hm/hmDefines.h b/src/hm/hmDefines.h index 1dc3148d..98281805 100644 --- a/src/hm/hmDefines.h +++ b/src/hm/hmDefines.h @@ -59,14 +59,14 @@ enum {FLD_UDC = 0, FLD_IDC, FLD_PDC, FLD_YD, FLD_YW, FLD_YT, FLD_IRR, FLD_Q, FLD_EVT, FLD_FW_VERSION, FLD_FW_BUILD_YEAR, FLD_FW_BUILD_MONTH_DAY, FLD_FW_BUILD_HOUR_MINUTE, FLD_BOOTLOADER_VER, FLD_ACT_ACTIVE_PWR_LIMIT, FLD_PART_NUM, FLD_HW_VERSION, FLD_GRID_PROFILE_CODE, - FLD_GRID_PROFILE_VERSION, /*FLD_ACT_REACTIVE_PWR_LIMIT, FLD_ACT_PF,*/ FLD_LAST_ALARM_CODE, FLD_MP}; + FLD_GRID_PROFILE_VERSION, /*FLD_ACT_REACTIVE_PWR_LIMIT, FLD_ACT_PF,*/ FLD_LAST_ALARM_CODE, FLD_MP, FLD_MT}; const char* const fields[] = {"U_DC", "I_DC", "P_DC", "YieldDay", "YieldWeek", "YieldTotal", "U_AC", "U_AC_1N", "U_AC_2N", "U_AC_3N", "UAC_12", "UAC_23", "UAC_31", "I_AC", "IAC_1", "I_AC_2", "I_AC_3", "P_AC", "F_AC", "Temp", "PF_AC", "Efficiency", "Irradiation","Q_AC", "ALARM_MES_ID","FWVersion","FWBuildYear","FWBuildMonthDay","FWBuildHourMinute","BootloaderVersion", "active_PowerLimit", "HWPartNumber", "HWVersion", "GridProfileCode", - "GridProfileVersion", /*"reactivePowerLimit","Powerfactor",*/ "LastAlarmCode", "MaxPower"}; + "GridProfileVersion", /*"reactivePowerLimit","Powerfactor",*/ "LastAlarmCode", "MaxPower", "MaxTemp"}; const char* const notAvail = "n/a"; const uint8_t fieldUnits[] = {UNIT_V, UNIT_A, UNIT_W, UNIT_WH, UNIT_KWH, UNIT_KWH, @@ -103,7 +103,7 @@ const byteAssign_fieldDeviceClass deviceFieldAssignment[] = { #define DEVICE_CLS_ASSIGN_LIST_LEN (sizeof(deviceFieldAssignment) / sizeof(byteAssign_fieldDeviceClass)) // indices to calculation functions, defined in hmInverter.h -enum {CALC_YT_CH0 = 0, CALC_YD_CH0, CALC_UDC_CH, CALC_PDC_CH0, CALC_EFF_CH0, CALC_IRR_CH, CALC_MPAC_CH0, CALC_MPDC_CH}; +enum {CALC_YT_CH0 = 0, CALC_YD_CH0, CALC_UDC_CH, CALC_PDC_CH0, CALC_EFF_CH0, CALC_IRR_CH, CALC_MPAC_CH0, CALC_MPDC_CH, CALC_MT_CH0}; enum {CMD_CALC = 0xffff}; @@ -208,7 +208,8 @@ const byteAssign_t hm1chAssignment[] = { { FLD_YT, UNIT_KWH, CH0, CALC_YT_CH0, 0, CMD_CALC }, { FLD_PDC, UNIT_W, CH0, CALC_PDC_CH0, 0, CMD_CALC }, { FLD_EFF, UNIT_PCT, CH0, CALC_EFF_CH0, 0, CMD_CALC }, - { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC } + { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC }, + { FLD_MT, UNIT_C, CH0, CALC_MT_CH0, 0, CMD_CALC } }; #define HM1CH_LIST_LEN (sizeof(hm1chAssignment) / sizeof(byteAssign_t)) #define HM1CH_PAYLOAD_LEN 30 @@ -246,7 +247,8 @@ const byteAssign_t hm2chAssignment[] = { { FLD_YT, UNIT_KWH, CH0, CALC_YT_CH0, 0, CMD_CALC }, { FLD_PDC, UNIT_W, CH0, CALC_PDC_CH0, 0, CMD_CALC }, { FLD_EFF, UNIT_PCT, CH0, CALC_EFF_CH0, 0, CMD_CALC }, - { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC } + { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC }, + { FLD_MT, UNIT_C, CH0, CALC_MT_CH0, 0, CMD_CALC } }; #define HM2CH_LIST_LEN (sizeof(hm2chAssignment) / sizeof(byteAssign_t)) @@ -301,7 +303,8 @@ const byteAssign_t hm4chAssignment[] = { { FLD_YT, UNIT_KWH, CH0, CALC_YT_CH0, 0, CMD_CALC }, { FLD_PDC, UNIT_W, CH0, CALC_PDC_CH0, 0, CMD_CALC }, { FLD_EFF, UNIT_PCT, CH0, CALC_EFF_CH0, 0, CMD_CALC }, - { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC } + { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC }, + { FLD_MT, UNIT_C, CH0, CALC_MT_CH0, 0, CMD_CALC } }; #define HM4CH_LIST_LEN (sizeof(hm4chAssignment) / sizeof(byteAssign_t)) #define HM4CH_PAYLOAD_LEN 62 diff --git a/src/hm/hmInverter.h b/src/hm/hmInverter.h index 9aa75878..2263188c 100644 --- a/src/hm/hmInverter.h +++ b/src/hm/hmInverter.h @@ -56,6 +56,9 @@ T calcMaxPowerAcCh0(Inverter<> *iv, uint8_t arg0); template T calcMaxPowerDc(Inverter<> *iv, uint8_t arg0); +template +T calcMaxTemperature(Inverter<> *iv, uint8_t arg0); + template using func_t = T (Inverter<> *, uint8_t); @@ -100,14 +103,15 @@ struct alarm_t { // list of all available functions, mapped in hmDefines.h template const calcFunc_t calcFunctions[] = { - { CALC_YT_CH0, &calcYieldTotalCh0 }, - { CALC_YD_CH0, &calcYieldDayCh0 }, - { CALC_UDC_CH, &calcUdcCh }, - { CALC_PDC_CH0, &calcPowerDcCh0 }, - { CALC_EFF_CH0, &calcEffiencyCh0 }, - { CALC_IRR_CH, &calcIrradiation }, - { CALC_MPAC_CH0, &calcMaxPowerAcCh0 }, - { CALC_MPDC_CH, &calcMaxPowerDc } + { CALC_YT_CH0, &calcYieldTotalCh0 }, + { CALC_YD_CH0, &calcYieldDayCh0 }, + { CALC_UDC_CH, &calcUdcCh }, + { CALC_PDC_CH0, &calcPowerDcCh0 }, + { CALC_EFF_CH0, &calcEffiencyCh0 }, + { CALC_IRR_CH, &calcIrradiation }, + { CALC_MPAC_CH0, &calcMaxPowerAcCh0 }, + { CALC_MPDC_CH, &calcMaxPowerDc }, + { CALC_MT_CH0, &calcMaxTemperature } }; template @@ -147,6 +151,7 @@ class Inverter { HeuristicInv heuristics; // heuristic information / logic uint8_t curCmtFreq = 0; // current used CMT frequency, used to check if freq. was changed during runtime uint32_t tsMaxAcPower = 0; // holds the Timestamp when the MaxAC power was seen + uint32_t tsMaxTemperature = 0; // holds the Timestamp when the max temperature was seen bool commEnabled = true; // 'pause night communication' sets this field to false public: @@ -579,7 +584,7 @@ class Inverter { } } - void resetAlarms() { + void resetAlarms(bool clear = false) { lastAlarm.fill({0, 0, 0}); mAlarmNxtWrPos = 0; alarmCnt = 0; @@ -587,6 +592,11 @@ class Inverter { memset(mOffYD, 0, sizeof(float) * 6); memset(mLastYD, 0, sizeof(float) * 6); + + if(clear) { + tsMaxAcPower = 0; + tsMaxTemperature = 0; + } } bool parseGetLossRate(const uint8_t pyld[], uint8_t len) { @@ -977,4 +987,22 @@ T calcMaxPowerDc(Inverter<> *iv, uint8_t arg0) { return dcMaxPower; } +template +T calcMaxTemperature(Inverter<> *iv, uint8_t arg0) { + DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcMaxTemperature")); + // arg0 = channel + if(NULL != iv) { + record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug); + T temp = iv->getChannelFieldValue(arg0, FLD_T, rec); + T maxTemp = iv->getChannelFieldValue(arg0, FLD_MT, rec); + + if(temp > maxTemp) { + iv->tsMaxTemperature = *iv->Timestamp; + return temp; + } + return maxTemp; + } + return 0; +} + #endif /*__HM_INVERTER_H__*/ diff --git a/src/hms/hmsDefines.h b/src/hms/hmsDefines.h index 61275dc1..c71aa796 100644 --- a/src/hms/hmsDefines.h +++ b/src/hms/hmsDefines.h @@ -33,7 +33,8 @@ const byteAssign_t hms1chAssignment[] = { { FLD_YT, UNIT_KWH, CH0, CALC_YT_CH0, 0, CMD_CALC }, { FLD_PDC, UNIT_W, CH0, CALC_PDC_CH0, 0, CMD_CALC }, { FLD_EFF, UNIT_PCT, CH0, CALC_EFF_CH0, 0, CMD_CALC }, - { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC } + { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC }, + { FLD_MT, UNIT_C, CH0, CALC_MT_CH0, 0, CMD_CALC } }; #define HMS1CH_LIST_LEN (sizeof(hms1chAssignment) / sizeof(byteAssign_t)) #define HMS1CH_PAYLOAD_LEN 30 @@ -70,7 +71,8 @@ const byteAssign_t hms2chAssignment[] = { { FLD_YT, UNIT_KWH, CH0, CALC_YT_CH0, 0, CMD_CALC }, { FLD_PDC, UNIT_W, CH0, CALC_PDC_CH0, 0, CMD_CALC }, { FLD_EFF, UNIT_PCT, CH0, CALC_EFF_CH0, 0, CMD_CALC }, - { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC } + { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC }, + { FLD_MT, UNIT_C, CH0, CALC_MT_CH0, 0, CMD_CALC } }; #define HMS2CH_LIST_LEN (sizeof(hms2chAssignment) / sizeof(byteAssign_t)) #define HMS2CH_PAYLOAD_LEN 42 @@ -123,7 +125,8 @@ const byteAssign_t hms4chAssignment[] = { { FLD_YT, UNIT_KWH, CH0, CALC_YT_CH0, 0, CMD_CALC }, { FLD_PDC, UNIT_W, CH0, CALC_PDC_CH0, 0, CMD_CALC }, { FLD_EFF, UNIT_PCT, CH0, CALC_EFF_CH0, 0, CMD_CALC }, - { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC } + { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC }, + { FLD_MT, UNIT_C, CH0, CALC_MT_CH0, 0, CMD_CALC } }; #define HMS4CH_LIST_LEN (sizeof(hms4chAssignment) / sizeof(byteAssign_t)) #define HMS4CH_PAYLOAD_LEN 66 @@ -199,7 +202,8 @@ const byteAssign_t hmt6chAssignment[] = { { FLD_YT, UNIT_KWH, CH0, CALC_YT_CH0, 0, CMD_CALC }, { FLD_PDC, UNIT_W, CH0, CALC_PDC_CH0, 0, CMD_CALC }, { FLD_EFF, UNIT_PCT, CH0, CALC_EFF_CH0, 0, CMD_CALC }, - { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC } + { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC }, + { FLD_MT, UNIT_C, CH0, CALC_MT_CH0, 0, CMD_CALC } }; #define HMT6CH_LIST_LEN (sizeof(hmt6chAssignment) / sizeof(byteAssign_t)) #define HMT6CH_PAYLOAD_LEN 98 diff --git a/src/platformio.ini b/src/platformio.ini index 53a56dd1..49eff335 100644 --- a/src/platformio.ini +++ b/src/platformio.ini @@ -27,7 +27,6 @@ extra_scripts = lib_deps = https://github.com/esphome/ESPAsyncWebServer @ ^3.1.0 https://github.com/nRF24/RF24.git#v1.4.8 - paulstoffregen/Time @ ^1.6.1 https://github.com/bertmelis/espMqttClient#v1.6.0 bblanchon/ArduinoJson @ ^6.21.3 diff --git a/src/plugins/MaxPower.h b/src/plugins/MaxPower.h index 8e2d4e37..34eeaf9f 100644 --- a/src/plugins/MaxPower.h +++ b/src/plugins/MaxPower.h @@ -17,7 +17,7 @@ class MaxPower { MaxPower() { mTs = nullptr; mMaxDiff = 60; - mValues.fill(std::make_pair(0, 0.0)); + reset(); } void setup(uint32_t *ts, uint16_t interval) { @@ -25,6 +25,11 @@ class MaxPower { mMaxDiff = interval * 4; } + void reset(void) { + mValues.fill(std::make_pair(0, 0.0)); + mLast = 0.0; + } + void payloadEvent(uint8_t cmd, Inverter<> *iv) { if(RealTimeRunData_Debug != cmd) return; @@ -42,14 +47,17 @@ class MaxPower { if((mValues[i].first + mMaxDiff) >= *mTs) val += mValues[i].second; else if(mValues[i].first > 0) - return 0; // old data + return mLast; // old data } - return val; + if(val > mLast) + mLast = val; + return mLast; } private: uint32_t *mTs; uint32_t mMaxDiff; + float mLast; std::array, MAX_NUM_INVERTERS> mValues; }; diff --git a/src/web/RestApi.h b/src/web/RestApi.h index 375c0e52..dcfd8044 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -603,6 +603,7 @@ class RestApi { obj[F("alarm_cnt")] = iv->alarmCnt; obj[F("rssi")] = iv->rssi; obj[F("ts_max_ac_pwr")] = iv->tsMaxAcPower; + obj[F("ts_max_temp")] = iv->tsMaxTemperature; JsonArray ch = obj.createNestedArray("ch"); @@ -905,6 +906,7 @@ class RestApi { void getLive(AsyncWebServerRequest *request, JsonObject obj) { getGeneric(request, obj.createNestedObject(F("generic"))); obj[F("refresh")] = mConfig->inst.sendInterval; + obj[F("max_total_pwr")] = ah::round3(mApp->getTotalMaxPower()); for (uint8_t fld = 0; fld < sizeof(acList); fld++) { obj[F("ch0_fld_units")][fld] = String(units[fieldUnits[acList[fld]]]); @@ -914,7 +916,6 @@ class RestApi { obj[F("fld_units")][fld] = String(units[fieldUnits[dcList[fld]]]); obj[F("fld_names")][fld] = String(fields[dcList[fld]]); } - obj[F("max_total_pwr")] = mApp->getTotalMaxPower(); Inverter<> *iv; for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) { @@ -1106,9 +1107,9 @@ class RestApi { private: constexpr static uint8_t acList[] = {FLD_UAC, FLD_IAC, FLD_PAC, FLD_F, FLD_PF, FLD_T, FLD_YT, - FLD_YD, FLD_PDC, FLD_EFF, FLD_Q, FLD_MP}; + FLD_YD, FLD_PDC, FLD_EFF, FLD_Q, FLD_MP, FLD_MT}; constexpr static uint8_t acListHmt[] = {FLD_UAC_1N, FLD_IAC_1, FLD_PAC, FLD_F, FLD_PF, FLD_T, - FLD_YT, FLD_YD, FLD_PDC, FLD_EFF, FLD_Q, FLD_MP}; + FLD_YT, FLD_YD, FLD_PDC, FLD_EFF, FLD_Q, FLD_MP, FLD_MT}; constexpr static uint8_t dcList[] = {FLD_UDC, FLD_IDC, FLD_PDC, FLD_YD, FLD_YT, FLD_IRR, FLD_MP}; private: diff --git a/src/web/html/about.html b/src/web/html/about.html index c0eb8c5e..1b27ac9d 100644 --- a/src/web/html/about.html +++ b/src/web/html/about.html @@ -14,7 +14,7 @@
Used Libraries
- + diff --git a/src/web/html/visualization.html b/src/web/html/visualization.html index f0f96112..ab909ba1 100644 --- a/src/web/html/visualization.html +++ b/src/web/html/visualization.html @@ -106,7 +106,6 @@ total[4] += obj.ch[0][8]; // P_DC total[5] += obj.ch[0][10]; // Q_AC } - total[3] += obj.ch[0][11]; // MAX P_AC total[1] += obj.ch[0][7]; // YieldDay total[2] += obj.ch[0][6]; // YieldTotal @@ -121,7 +120,8 @@ pwrLimit += ", " + (obj.max_pwr * obj.power_limit_read / 100).toFixed(1) + " W"; } - var maxAcPwr = toIsoDateStr(new Date(obj.ts_max_ac_pwr * 1000)); + var maxAcPwrDate = toIsoDateStr(new Date(obj.ts_max_ac_pwr * 1000)) + var maxTempDate = toIsoDateStr(new Date(obj.ts_max_temp * 1000)) return ml("div", {class: "row mt-2"}, ml("div", {class: "col"}, [ ml("div", {class: "p-2 " + clh}, @@ -136,7 +136,7 @@ ml("div", {class: "col a-c"}, ml("span", { class: "pointer", onclick: function() { getAjax("/api/inverter/alarm/" + obj.id, parseIvAlarm); }}, ("{#ALARMS}: " + obj.alarm_cnt))), - ml("div", {class: "col a-r mx-2 mx-md-1"}, String(obj.ch[0][5].toFixed(1)) + t.innerText) + ml("div", {class: "col a-r mx-2 mx-md-1 tooltip", data: (obj.ch[0][12] + t.innerText + "\n" + maxTempDate)}, String(obj.ch[0][5].toFixed(1)) + t.innerText) ]) ), ml("div", {class: "p-2 " + clbg}, [ @@ -147,7 +147,7 @@ ]), ml("div", {class: "hr"}), ml("div", {class: "row mt-2"},[ - numMid(obj.ch[0][11], "W", "{#MAX_AC_POWER}", {class: "fs-6 tooltip", data: maxAcPwr}), + numMid(obj.ch[0][11], "W", "{#MAX_AC_POWER}", {class: "fs-6 tooltip", data: maxAcPwrDate}), numMid(obj.ch[0][8], "W", "{#DC_POWER}"), numMid(obj.ch[0][0], "V", "{#AC_VOLTAGE}"), numMid(obj.ch[0][1], "A", "{#AC_CURRENT}"), @@ -516,6 +516,7 @@ mNum = 0; totalsRendered = false total.fill(0); + total[3] = obj.max_total_pwr for(var i = 0; i < obj.iv.length; i++) { if(obj.iv[i]) { getAjax("/api/inverter/id/" + i, parseIv);