Browse Source

0.7.5

* fix yield day reset on midnight #957
* improved tickers in `app.cpp`
pull/1005/head
lumapu 2 years ago
parent
commit
76f01bbe95
  1. 4
      src/CHANGES.md
  2. 92
      src/app.cpp
  3. 1
      src/app.h
  4. 2
      src/defines.h
  5. 22
      src/hm/hmPayload.h
  6. 4
      src/publisher/pubMqtt.h
  7. 20
      src/publisher/pubMqttIvData.h

4
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

92
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);

1
src/app.h

@ -241,6 +241,7 @@ class app : public IApp, public ah::Scheduler {
typedef std::function<void()> innerLoopCb;
void resetSystem(void);
void zeroIvValues(bool checkAvail = false, bool skipYieldDay = true);
void payloadEventListener(uint8_t cmd, Inverter<> *iv) {
#if !defined(AP_ONLY)

2
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 {

22
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;
}

4
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"));

20
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<sendListCmdIv> *mSendList;
};

Loading…
Cancel
Save