Skip to content

Commit

Permalink
0.8.116
Browse files Browse the repository at this point in the history
* calculation of max AC power
* fix counter overflow communication queue
* added max inverter temperature
  • Loading branch information
lumapu committed May 5, 2024
1 parent abc760e commit e4a467c
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 35 deletions.
7 changes: 6 additions & 1 deletion src/CHANGES.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
7 changes: 6 additions & 1 deletion src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/hm/CommQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class CommQueue {
if(mQueue[ptr].iv->id == q->iv->id)
return true;
}
ptr++;
inc(&ptr);
}
return false;
}
Expand Down
15 changes: 9 additions & 6 deletions src/hm/hmDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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};


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
46 changes: 37 additions & 9 deletions src/hm/hmInverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ T calcMaxPowerAcCh0(Inverter<> *iv, uint8_t arg0);
template<class T=float>
T calcMaxPowerDc(Inverter<> *iv, uint8_t arg0);

template<class T=float>
T calcMaxTemperature(Inverter<> *iv, uint8_t arg0);

template<class T=float>
using func_t = T (Inverter<> *, uint8_t);

Expand Down Expand Up @@ -100,14 +103,15 @@ struct alarm_t {
// list of all available functions, mapped in hmDefines.h
template<class T=float>
const calcFunc_t<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 <class REC_TYP>
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -579,14 +584,19 @@ class Inverter {
}
}

void resetAlarms() {
void resetAlarms(bool clear = false) {
lastAlarm.fill({0, 0, 0});
mAlarmNxtWrPos = 0;
alarmCnt = 0;
alarmLastId = 0;

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) {
Expand Down Expand Up @@ -977,4 +987,22 @@ T calcMaxPowerDc(Inverter<> *iv, uint8_t arg0) {
return dcMaxPower;
}

template<class T=float>
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__*/
12 changes: 8 additions & 4 deletions src/hms/hmsDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions src/plugins/MaxPower.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ class MaxPower {
MaxPower() {
mTs = nullptr;
mMaxDiff = 60;
mValues.fill(std::make_pair(0, 0.0));
reset();
}

void setup(uint32_t *ts, uint16_t interval) {
mTs = ts;
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;
Expand All @@ -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<std::pair<uint32_t, T>, MAX_NUM_INVERTERS> mValues;
};

Expand Down
7 changes: 4 additions & 3 deletions src/web/RestApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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]]]);
Expand All @@ -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 ++) {
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/web/html/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<div class="p-2">Used Libraries</div>
</div>
<div class="row"><a href="https://github.com/bertmelis/espMqttClient" target="_blank">bertmelis/espMqttClient</a></div>
<div class="row"><a href="https://github.com/yubox-node-org/ESPAsyncWebServer" target="_blank">yubox-node-org/ESPAsyncWebServer</a></div>
<div class="row"><a href="https://github.com/esphome/ESPAsyncWebServer" target="_blank">esphome/ESPAsyncWebServer</a></div>
<div class="row"><a href="https://github.com/bblanchon/ArduinoJson" target="_blank">bblanchon/ArduinoJson</a></div>
<div class="row"><a href="https://github.com/nrf24/RF24" target="_blank">nrf24/RF24</a></div>
<div class="row"><a href="https://github.com/paulstoffregen/Time" target="_blank">paulstoffregen/Time</a></div>
Expand Down
9 changes: 5 additions & 4 deletions src/web/html/visualization.html
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -121,7 +120,8 @@
pwrLimit += ", " + (obj.max_pwr * obj.power_limit_read / 100).toFixed(1) + "&nbsp;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},
Expand All @@ -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}, [
Expand All @@ -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}"),
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e4a467c

Please sign in to comment.