diff --git a/src/CHANGES.md b/src/CHANGES.md index f6e4f8b2..4815879a 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -1,5 +1,9 @@ # Development Changes +## 0.7.5 - 2023-06-16 +* fix yield day reset on midnight #957 +* improved tickers in `app.cpp` + ## 0.7.4 - 2023-06-15 * fix MqTT `P_AC` send if inverters are available #987 * fix assignments for HMS 1CH and 2CH devices diff --git a/src/app.cpp b/src/app.cpp index 5ae2b845..bd060425 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -321,42 +321,14 @@ void app::tickComm(void) { //----------------------------------------------------------------------------- void app::tickZeroValues(void) { - Inverter<> *iv; - bool changed = false; - // set values to zero, except yields - for (uint8_t id = 0; id < mSys.getNumInverters(); id++) { - iv = mSys.getInverterByPos(id); - if (NULL == iv) - continue; // skip to next inverter - - mPayload.zeroInverterValues(iv); - changed = true; - } - - if(changed) - payloadEventListener(RealTimeRunData_Debug, NULL); + zeroIvValues(false); } //----------------------------------------------------------------------------- void app::tickMinute(void) { // only triggered if 'reset values on no avail is enabled' - Inverter<> *iv; - bool changed = false; - // set values to zero, except yields - for (uint8_t id = 0; id < mSys.getNumInverters(); id++) { - iv = mSys.getInverterByPos(id); - if (NULL == iv) - continue; // skip to next inverter - - if (!iv->isAvailable(mTimestamp) && !iv->isProducing(mTimestamp) && iv->config->enabled) { - mPayload.zeroInverterValues(iv); - changed = true; - } - } - - if(changed) - payloadEventListener(RealTimeRunData_Debug, NULL); + zeroIvValues(true); } //----------------------------------------------------------------------------- @@ -366,20 +338,7 @@ void app::tickMidnight(void) { uint32_t nxtTrig = gTimezone.toUTC(localTime - (localTime % 86400) + 86400); // next midnight local time onceAt(std::bind(&app::tickMidnight, this), nxtTrig, "mid2"); - Inverter<> *iv; - bool changed = false; - // set values to zero, except yield total - for (uint8_t id = 0; id < mSys.getNumInverters(); id++) { - iv = mSys.getInverterByPos(id); - if (NULL == iv) - continue; // skip to next inverter - - mPayload.zeroInverterValues(iv, false); - changed = true; - } - - if(changed) - payloadEventListener(RealTimeRunData_Debug, NULL); + zeroIvValues(false, false); if (mMqttEnabled) mMqtt.tickerMidnight(); @@ -441,6 +400,51 @@ void app::tickSend(void) { updateLed(); } +//----------------------------------------------------------------------------- +void app:: zeroIvValues(bool checkAvail, bool skipYieldDay) { + Inverter<> *iv; + bool changed = false; + // set values to zero, except yields + for (uint8_t id = 0; id < mSys.getNumInverters(); id++) { + iv = mSys.getInverterByPos(id); + if (NULL == iv) + continue; // skip to next inverter + if (!iv->config->enabled) + continue; // skip to next inverter + + if (checkAvail) { + if (!iv->isAvailable(mTimestamp)) + continue; + } + + record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug); + for(uint8_t ch = 0; ch <= iv->channels; ch++) { + uint8_t pos = 0; + for(uint8_t fld = 0; fld < FLD_EVT; fld++) { + switch(fld) { + case FLD_YD: + if(skipYieldDay) + continue; + else + break; + case FLD_YT: + continue; + } + pos = iv->getPosByChFld(ch, fld, rec); + iv->setValue(pos, rec, 0.0f); + } + iv->doCalculations(); + } + changed = true; + } + + if(changed) { + if(mMqttEnabled) + mMqtt.setZeroValuesEnable(); + payloadEventListener(RealTimeRunData_Debug, NULL); + } +} + //----------------------------------------------------------------------------- void app::resetSystem(void) { snprintf(mVersion, 12, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); diff --git a/src/app.h b/src/app.h index e053cfd9..60ba9ff0 100644 --- a/src/app.h +++ b/src/app.h @@ -241,6 +241,7 @@ class app : public IApp, public ah::Scheduler { typedef std::function innerLoopCb; void resetSystem(void); + void zeroIvValues(bool checkAvail = false, bool skipYieldDay = true); void payloadEventListener(uint8_t cmd, Inverter<> *iv) { #if !defined(AP_ONLY) diff --git a/src/defines.h b/src/defines.h index f13b038d..da7fffc2 100644 --- a/src/defines.h +++ b/src/defines.h @@ -13,7 +13,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 7 -#define VERSION_PATCH 4 +#define VERSION_PATCH 5 //------------------------------------- typedef struct { diff --git a/src/hm/hmPayload.h b/src/hm/hmPayload.h index 59f678d9..2b59cd69 100644 --- a/src/hm/hmPayload.h +++ b/src/hm/hmPayload.h @@ -95,28 +95,6 @@ class HmPayload { notify(0x0b); }*/ - void zeroInverterValues(Inverter<> *iv, bool skipYieldDay = true) { - DPRINTLN(DBG_DEBUG, F("zeroInverterValues")); - record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug); - for(uint8_t ch = 0; ch <= iv->channels; ch++) { - uint8_t pos = 0; - for(uint8_t fld = 0; fld < FLD_EVT; fld++) { - switch(fld) { - case FLD_YD: - if(skipYieldDay) - continue; - else - break; - case FLD_YT: - continue; - } - pos = iv->getPosByChFld(ch, fld, rec); - iv->setValue(pos, rec, 0.0f); - } - iv->doCalculations(); - } - } - void ivSendHighPrio(Inverter<> *iv) { mHighPrioIv = iv; } diff --git a/src/publisher/pubMqtt.h b/src/publisher/pubMqtt.h index 3a64c686..d04416d2 100644 --- a/src/publisher/pubMqtt.h +++ b/src/publisher/pubMqtt.h @@ -240,6 +240,10 @@ class PubMqtt { } } + void setZeroValuesEnable(void) { + mSendIvData.setZeroValuesEnable(); + } + private: void onConnect(bool sessionPreset) { DPRINTLN(DBG_INFO, F("MQTT connected")); diff --git a/src/publisher/pubMqttIvData.h b/src/publisher/pubMqttIvData.h index eaff9491..9f8ff318 100644 --- a/src/publisher/pubMqttIvData.h +++ b/src/publisher/pubMqttIvData.h @@ -26,6 +26,7 @@ class PubMqttIvData { mUtcTimestamp = utcTs; mSendList = sendList; mState = IDLE; + mZeroValues = false; memset(mIvLastRTRpub, 0, MAX_NUM_INVERTERS * 4); mRTRDataHasBeenSent = false; @@ -55,6 +56,10 @@ class PubMqttIvData { mPublish = cb; } + void setZeroValuesEnable(void) { + mZeroValues = true; + } + private: enum State {IDLE, START, FIND_NXT_IV, SEND_DATA, SEND_TOTALS, NUM_STATES}; typedef void (PubMqttIvData::*StateFunction)(); @@ -101,6 +106,7 @@ class PubMqttIvData { mState = SEND_TOTALS; else { mSendList->pop(); + mZeroValues = false; mState = START; } } @@ -119,11 +125,13 @@ class PubMqttIvData { switch (rec->assign[mPos].fieldId) { case FLD_YT: case FLD_YD: - if ((rec->assign[mPos].ch == CH0) && (!mIv->isProducing(*mUtcTimestamp))) { // avoids returns to 0 on restart - mPos++; - if(!mIv->isAvailable(*mUtcTimestamp)) - mSendTotals = false; // avoid send total values on not producing, because the sum of values is no built - return; + if(!mZeroValues) { + if ((rec->assign[mPos].ch == CH0) && (!mIv->isProducing(*mUtcTimestamp))) { // avoids returns to 0 on restart + mPos++; + if(!mIv->isAvailable(*mUtcTimestamp)) + mSendTotals = false; // avoid send total values on not producing, because the sum of values is no built + return; + } } retained = true; break; @@ -188,6 +196,7 @@ class PubMqttIvData { mPos++; } else { mSendList->pop(); + mZeroValues = false; mState = START; } @@ -212,6 +221,7 @@ class PubMqttIvData { char mSubTopic[32 + MAX_NAME_LENGTH + 1]; char mVal[40]; + bool mZeroValues; std::queue *mSendList; };