From f649d26f66cec1887608ae294f94e40e8db20151 Mon Sep 17 00:00:00 2001 From: lumapu Date: Thu, 15 Jun 2023 23:18:12 +0200 Subject: [PATCH] 0.7.4 * fix MqTT `P_AC` send if inverters are available #987 * fix assignments for HMS 1CH and 2CH devices * fixed uptime overflow #990 --- src/CHANGES.md | 5 +++++ src/app.cpp | 2 +- src/defines.h | 2 +- src/hm/hmDefines.h | 3 ++- src/hm/hmInverter.h | 28 ++++++++++++++++++++-------- src/publisher/pubMqtt.h | 7 ++++--- src/publisher/pubMqttIvData.h | 3 ++- src/utils/scheduler.h | 2 +- src/web/html/visualization.html | 1 - 9 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/CHANGES.md b/src/CHANGES.md index 8225f1df..f6e4f8b2 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -1,5 +1,10 @@ # Development Changes +## 0.7.4 - 2023-06-15 +* fix MqTT `P_AC` send if inverters are available #987 +* fix assignments for HMS 1CH and 2CH devices +* fixed uptime overflow #990 + ## 0.7.3 - 2023-06-09 * fix hidden SSID scan #983 * improved NRF24 missing message on home screen #981 diff --git a/src/app.cpp b/src/app.cpp index 0df468e3..5ae2b845 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -81,7 +81,7 @@ void app::setup() { #if !defined(AP_ONLY) mMqttEnabled = (mConfig->mqtt.broker[0] > 0); if (mMqttEnabled) { - mMqtt.setup(&mConfig->mqtt, mConfig->sys.deviceName, mVersion, &mSys, &mTimestamp); + mMqtt.setup(&mConfig->mqtt, mConfig->sys.deviceName, mVersion, &mSys, &mTimestamp, &mUptime); mMqtt.setSubscriptionCb(std::bind(&app::mqttSubRxCb, this, std::placeholders::_1)); mPayload.addAlarmListener(std::bind(&PubMqttType::alarmEventListener, &mMqtt, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); mMiPayload.addAlarmListener(std::bind(&PubMqttType::alarmEventListener, &mMqtt, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); diff --git a/src/defines.h b/src/defines.h index 90eefe87..f13b038d 100644 --- a/src/defines.h +++ b/src/defines.h @@ -13,7 +13,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 7 -#define VERSION_PATCH 3 +#define VERSION_PATCH 4 //------------------------------------- typedef struct { diff --git a/src/hm/hmDefines.h b/src/hm/hmDefines.h index abe03b24..be59330d 100644 --- a/src/hm/hmDefines.h +++ b/src/hm/hmDefines.h @@ -32,7 +32,8 @@ const char* const fields[] = {"U_DC", "I_DC", "P_DC", "YieldDay", "YieldWeek", " const char* const notAvail = "n/a"; const uint8_t fieldUnits[] = {UNIT_V, UNIT_A, UNIT_W, UNIT_WH, UNIT_KWH, UNIT_KWH, - UNIT_V, UNIT_A, UNIT_W, UNIT_HZ, UNIT_C, UNIT_NONE, UNIT_PCT, UNIT_PCT, UNIT_VAR, + UNIT_V, UNIT_V, UNIT_V, UNIT_V, UNIT_V, UNIT_V, UNIT_V, UNIT_A, UNIT_A, UNIT_A, UNIT_A, + UNIT_W, UNIT_HZ, UNIT_C, UNIT_NONE, UNIT_PCT, UNIT_PCT, UNIT_VAR, UNIT_NONE, UNIT_NONE, UNIT_NONE, UNIT_NONE, UNIT_NONE, UNIT_NONE, UNIT_PCT, UNIT_NONE}; // mqtt discovery device classes diff --git a/src/hm/hmInverter.h b/src/hm/hmInverter.h index 8e162274..094be658 100644 --- a/src/hm/hmInverter.h +++ b/src/hm/hmInverter.h @@ -422,16 +422,28 @@ class Inverter { switch (cmd) { case RealTimeRunData_Debug: if (INV_TYPE_1CH == type) { - rec->length = (uint8_t)(HM1CH_LIST_LEN); - rec->assign = (byteAssign_t *)hm1chAssignment; - rec->pyldLen = HM1CH_PAYLOAD_LEN; - channels = 1; + if(IV_HM == ivGen) { + rec->length = (uint8_t)(HM1CH_LIST_LEN); + rec->assign = (byteAssign_t *)hm1chAssignment; + rec->pyldLen = HM1CH_PAYLOAD_LEN; + } else if(IV_HMS == ivGen) { + rec->length = (uint8_t)(HMS1CH_LIST_LEN); + rec->assign = (byteAssign_t *)hms1chAssignment; + rec->pyldLen = HMS1CH_PAYLOAD_LEN; + } + channels = 1; } else if (INV_TYPE_2CH == type) { - rec->length = (uint8_t)(HM2CH_LIST_LEN); - rec->assign = (byteAssign_t *)hm2chAssignment; - rec->pyldLen = HM2CH_PAYLOAD_LEN; - channels = 2; + if(IV_HM == ivGen) { + rec->length = (uint8_t)(HM2CH_LIST_LEN); + rec->assign = (byteAssign_t *)hm2chAssignment; + rec->pyldLen = HM2CH_PAYLOAD_LEN; + } else if(IV_HMS == ivGen) { + rec->length = (uint8_t)(HMS2CH_LIST_LEN); + rec->assign = (byteAssign_t *)hms2chAssignment; + rec->pyldLen = HMS2CH_PAYLOAD_LEN; + } + channels = 2; } else if (INV_TYPE_4CH == type) { if(IV_HM == ivGen) { diff --git a/src/publisher/pubMqtt.h b/src/publisher/pubMqtt.h index 5be82c0f..3a64c686 100644 --- a/src/publisher/pubMqtt.h +++ b/src/publisher/pubMqtt.h @@ -56,12 +56,13 @@ class PubMqtt { ~PubMqtt() { } - void setup(cfgMqtt_t *cfg_mqtt, const char *devName, const char *version, HMSYSTEM *sys, uint32_t *utcTs) { + void setup(cfgMqtt_t *cfg_mqtt, const char *devName, const char *version, HMSYSTEM *sys, uint32_t *utcTs, uint32_t *uptime) { mCfgMqtt = cfg_mqtt; mDevName = devName; mVersion = version; mSys = sys; mUtcTimestamp = utcTs; + mUptime = uptime; mIntervalTimeout = 1; mSendIvData.setup(sys, utcTs, &mSendList); @@ -126,7 +127,7 @@ class PubMqtt { } void tickerMinute() { - snprintf(mVal, 40, "%ld", millis() / 1000); + snprintf(mVal, 40, "%d", (*mUptime)); publish(subtopics[MQTT_UPTIME], mVal); publish(subtopics[MQTT_RSSI], String(WiFi.RSSI()).c_str()); publish(subtopics[MQTT_FREE_HEAP], String(ESP.getFreeHeap()).c_str()); @@ -582,7 +583,7 @@ class PubMqtt { HMSYSTEM *mSys; PubMqttIvData mSendIvData; - uint32_t *mUtcTimestamp; + uint32_t *mUtcTimestamp, *mUptime; uint32_t mRxCnt, mTxCnt; std::queue mSendList; std::queue mAlarmList; diff --git a/src/publisher/pubMqttIvData.h b/src/publisher/pubMqttIvData.h index 11742c29..eaff9491 100644 --- a/src/publisher/pubMqttIvData.h +++ b/src/publisher/pubMqttIvData.h @@ -121,7 +121,8 @@ class PubMqttIvData { case FLD_YD: if ((rec->assign[mPos].ch == CH0) && (!mIv->isProducing(*mUtcTimestamp))) { // avoids returns to 0 on restart mPos++; - mSendTotals = false; // avoid send total values on not producing, because the sum of values is no built + if(!mIv->isAvailable(*mUtcTimestamp)) + mSendTotals = false; // avoid send total values on not producing, because the sum of values is no built return; } retained = true; diff --git a/src/utils/scheduler.h b/src/utils/scheduler.h index ca250a3e..50a46826 100644 --- a/src/utils/scheduler.h +++ b/src/utils/scheduler.h @@ -117,6 +117,7 @@ namespace ah { protected: uint32_t mTimestamp; + uint32_t mUptime; private: inline uint8_t addTicker(scdCb c, uint32_t timeout, uint32_t reload, bool isTimestamp, const char *name) { @@ -162,7 +163,6 @@ namespace ah { sP mTicker[MAX_NUM_TICKER]; bool mTickerInUse[MAX_NUM_TICKER]; uint32_t mMillis, mPrevMillis, mDiff; - uint32_t mUptime; uint8_t mDiffSeconds; uint8_t mMax; }; diff --git a/src/web/html/visualization.html b/src/web/html/visualization.html index de5b0069..fe8256cf 100644 --- a/src/web/html/visualization.html +++ b/src/web/html/visualization.html @@ -19,7 +19,6 @@ var units, ivEn; var mIvHtml = []; var mNum = 0; - var names = ["Voltage", "Current", "Power", "Yield Day", "Yield Total", "Irradiation"]; var total = Array(5).fill(0); function parseGeneric(obj) {