diff --git a/src/CHANGES.md b/src/CHANGES.md index 7c58866a..06520805 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -2,6 +2,12 @@ (starting from release version `0.5.66`) +## 0.5.108 +* merge: PR SPI pins configureable (ESP32) #807, #806 +* merge: PR MI serial outputs #809 +* fix: no MQTT `total` sensor for autodiscover if only one inverter was found #805 +* fix: MQTT `total` renamed to `device_name` + `_TOTOL` for better visibility #805 + ## 0.5.107 * fix: show save message * fix: removed serial newline for `enqueueCmd` diff --git a/src/defines.h b/src/defines.h index 05cbd23b..1ed01f66 100644 --- a/src/defines.h +++ b/src/defines.h @@ -13,7 +13,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 5 -#define VERSION_PATCH 107 +#define VERSION_PATCH 108 //------------------------------------- typedef struct { diff --git a/src/hm/hmInverter.h b/src/hm/hmInverter.h index d3efd9ac..b1390b29 100644 --- a/src/hm/hmInverter.h +++ b/src/hm/hmInverter.h @@ -304,7 +304,7 @@ class Inverter { if (getPosByChFld(0, FLD_ACT_ACTIVE_PWR_LIMIT, rec) == pos){ actPowerLimit = rec->record[pos]; DPRINT(DBG_DEBUG, F("Inverter actual power limit: ")); - DBGPRINTLN(String(actPowerLimit, 1)); + DPRINTLN(DBG_DEBUG, String(actPowerLimit, 1)); } } else if (rec->assign == AlarmDataAssignment) { diff --git a/src/hm/hmPayload.h b/src/hm/hmPayload.h index 01282b00..0af8f466 100644 --- a/src/hm/hmPayload.h +++ b/src/hm/hmPayload.h @@ -168,7 +168,7 @@ class HmPayload { DPRINTLN(DBG_DEBUG, F("fragment number zero received and ignored")); } else { DPRINT(DBG_DEBUG, F("PID: 0x")); - DBGHEXLN(*pid); + DPRINTLN(DBG_DEBUG, String(*pid, HEX)); if ((*pid & 0x7F) < MAX_PAYLOAD_ENTRIES) { memcpy(mPayload[iv->id].data[(*pid & 0x7F) - 1], &p->packet[10], p->len - 11); mPayload[iv->id].len[(*pid & 0x7F) - 1] = p->len - 11; @@ -285,7 +285,7 @@ class HmPayload { DPRINT(DBG_INFO, F("procPyld: txid: 0x")); DBGHEXLN(mPayload[iv->id].txId); DPRINT(DBG_DEBUG, F("procPyld: max: ")); - DBGPRINTLN(String(mPayload[iv->id].maxPackId)); + DPRINTLN(DBG_DEBUG, String(mPayload[iv->id].maxPackId)); record_t<> *rec = iv->getRecordStruct(mPayload[iv->id].txCmd); // choose the parser mPayload[iv->id].complete = true; diff --git a/src/publisher/pubMqtt.h b/src/publisher/pubMqtt.h index a529d1fc..8240c1e5 100644 --- a/src/publisher/pubMqtt.h +++ b/src/publisher/pubMqtt.h @@ -38,6 +38,7 @@ typedef struct { bool running; uint8_t lastIvId; uint8_t sub; + uint8_t foundIvCnt; } discovery_t; template @@ -224,6 +225,7 @@ class PubMqtt { mDiscovery.running = true; mDiscovery.lastIvId = 0; mDiscovery.sub = 0; + mDiscovery.foundIvCnt = 0; } void setPowerLimitAck(Inverter<> *iv) { @@ -350,14 +352,16 @@ class PubMqtt { uint8_t fldTotal[4] = {FLD_PAC, FLD_YT, FLD_YD, FLD_PDC}; const char* unitTotal[4] = {"W", "kWh", "Wh", "W"}; - String node_mac = WiFi.macAddress().substring(12,14)+ WiFi.macAddress().substring(15,17); - String node_id = "AHOY_DTU_" + node_mac; + String node_id = String(mDevName) + "_TOTAL"; bool total = (mDiscovery.lastIvId == MAX_NUM_INVERTERS); Inverter<> *iv = mSys->getInverterByPos(mDiscovery.lastIvId); record_t<> *rec; - if (NULL != iv) + if (NULL != iv) { rec = iv->getRecordStruct(RealTimeRunData_Debug); + if(0 == mDiscovery.sub) + mDiscovery.foundIvCnt++; + } if ((NULL != iv) || total) { if (!total) { @@ -412,7 +416,7 @@ class PubMqtt { if (!total) snprintf(topic, 64, "%s/sensor/%s/ch%d_%s/config", MQTT_DISCOVERY_PREFIX, iv->config->name, rec->assign[mDiscovery.sub].ch, iv->getFieldName(mDiscovery.sub, rec)); else // total values - snprintf(topic, 64, "%s/sensor/%s/total_%s/config", MQTT_DISCOVERY_PREFIX, node_id.c_str(),fields[fldTotal[mDiscovery.sub]]); + snprintf(topic, 64, "%s/sensor/%s/total_%s/config", MQTT_DISCOVERY_PREFIX, node_id.c_str(), fields[fldTotal[mDiscovery.sub]]); size_t size = measureJson(doc2) + 1; memset(buf, 0, size); serializeJson(doc2, buf, size); @@ -420,18 +424,26 @@ class PubMqtt { if(++mDiscovery.sub == ((!total) ? (rec->length) : 4)) { mDiscovery.sub = 0; - if(++mDiscovery.lastIvId == (MAX_NUM_INVERTERS + 1)) - mDiscovery.running = false; + checkDiscoveryEnd(); } } else { mDiscovery.sub = 0; - if(++mDiscovery.lastIvId == (MAX_NUM_INVERTERS + 1)) - mDiscovery.running = false; + checkDiscoveryEnd(); } yield(); } + void checkDiscoveryEnd(void) { + if(++mDiscovery.lastIvId == MAX_NUM_INVERTERS) { + // check if only one inverter was found, then don't create 'total' sensor + DPRINTLN(DBG_INFO, "found: " + String(mDiscovery.foundIvCnt)); + if(mDiscovery.foundIvCnt == 1) + mDiscovery.running = false; + } else if(mDiscovery.lastIvId == (MAX_NUM_INVERTERS + 1)) + mDiscovery.running = false; + } + const char *getFieldDeviceClass(uint8_t fieldId) { uint8_t pos = 0; for (; pos < DEVICE_CLS_ASSIGN_LIST_LEN; pos++) {