Skip to content

Commit

Permalink
0.8.53
Browse files Browse the repository at this point in the history
* fix history graph
* fix MqTT yield day #1331
  • Loading branch information
lumapu committed Jan 12, 2024
1 parent 455d29a commit ca6ebfe
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 34 deletions.
4 changes: 4 additions & 0 deletions src/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Development Changes

## 0.8.53 - 2024-01-12
* fix history graph
* fix MqTT yield day #1331

## 0.8.52 - 2024-01-11
* possible fix of 'division by zero' #1345
* fix lang #1348 #1346
Expand Down
16 changes: 10 additions & 6 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void app::regularTickers(void) {
//everySec([this]() { mImprov.tickSerial(); }, "impro");
#endif

everySec(std::bind(&HistoryType::tickerSecond, mHistory), "hist");
everySec(std::bind(&HistoryType::tickerSecond, &mHistory), "hist");
}

#if defined(ETHERNET)
Expand Down Expand Up @@ -241,7 +241,7 @@ void app::tickCalcSunrise(void) {
if (mMqttEnabled) {
tickSun();
nxtTrig = mSunrise + mConfig->sun.offsetSecMorning + 1; // one second safety to trigger correctly
onceAt(std::bind(&app::tickSun, this), nxtTrig, "mqSr"); // trigger on sunrise to update 'dis_night_comm'
onceAt(std::bind(&app::tickSunrise, this), nxtTrig, "mqSr"); // trigger on sunrise to update 'dis_night_comm'
}
}

Expand Down Expand Up @@ -291,6 +291,13 @@ void app::tickSun(void) {
once(std::bind(&app::tickSun, this), 1, "mqSun"); // MQTT not connected, retry
}

//-----------------------------------------------------------------------------
void app::tickSunrise(void) {
// only used and enabled by MQTT (see setup())
if (!mMqtt.tickerSun(mSunrise, mSunset, mConfig->sun.offsetSecMorning, mConfig->sun.offsetSecEvening, true))
once(std::bind(&app::tickSun, this), 1, "mqSun"); // MQTT not connected, retry
}

//-----------------------------------------------------------------------------
void app::tickZeroValues(void) {
zeroIvValues(!CHECK_AVAIL, SKIP_YIELD_DAY);
Expand Down Expand Up @@ -423,11 +430,8 @@ void app:: zeroIvValues(bool checkAvail, bool skipYieldDay) {
changed = true;
}

if(changed) {
if(mMqttEnabled && !skipYieldDay)
mMqtt.setZeroValuesEnable();
if(changed)
payloadEventListener(RealTimeRunData_Debug, NULL);
}
}

//-----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ class app : public IApp, public ah::Scheduler {
void tickCalcSunrise(void);
void tickIVCommunication(void);
void tickSun(void);
void tickSunrise(void);
void tickComm(void);
void tickSend(void);
void tickMinute(void);
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 52
#define VERSION_PATCH 53

//-------------------------------------
typedef struct {
Expand Down
15 changes: 5 additions & 10 deletions src/publisher/pubMqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class PubMqtt {
memset(mLastIvState, (uint8_t)InverterStatus::OFF, MAX_NUM_INVERTERS);
memset(mIvLastRTRpub, 0, MAX_NUM_INVERTERS * 4);
mLastAnyAvail = false;
mZeroValues = false;
}

~PubMqtt() { }
Expand Down Expand Up @@ -134,7 +133,7 @@ class PubMqtt {
#endif
}

bool tickerSun(uint32_t sunrise, uint32_t sunset, int16_t offsM, int16_t offsE) {
bool tickerSun(uint32_t sunrise, uint32_t sunset, int16_t offsM, int16_t offsE, bool isSunrise = false) {
if (!mClient.connected())
return false;

Expand All @@ -153,10 +152,12 @@ class PubMqtt {
publish(mSubTopic, ((iv->commEnabled) ? dict[STR_TRUE] : dict[STR_FALSE]), true);
}


snprintf(mSubTopic, 32 + MAX_NAME_LENGTH, "comm_disabled");
publish(mSubTopic, (((*mUtcTimestamp > (sunset + offsE)) || (*mUtcTimestamp < (sunrise + offsM))) ? dict[STR_TRUE] : dict[STR_FALSE]), true);

if(isSunrise)
mSendIvData.resetYieldDay();

return true;
}

Expand Down Expand Up @@ -239,10 +240,6 @@ class PubMqtt {
}
}

void setZeroValuesEnable(void) {
mZeroValues = true;
}

private:
void onConnect(bool sessionPreset) {
DPRINTLN(DBG_INFO, F("MQTT connected"));
Expand Down Expand Up @@ -592,8 +589,7 @@ class PubMqtt {
if(mSendList.empty())
return;

mSendIvData.start(mZeroValues);
mZeroValues = false;
mSendIvData.start();
mLastAnyAvail = anyAvail;
}

Expand All @@ -612,7 +608,6 @@ class PubMqtt {
std::array<bool, MAX_NUM_INVERTERS> mSendAlarm{};
subscriptionCb mSubscriptionCb;
bool mLastAnyAvail;
bool mZeroValues;
InverterStatus mLastIvState[MAX_NUM_INVERTERS];
uint32_t mIvLastRTRpub[MAX_NUM_INVERTERS];
uint16_t mIntervalTimeout;
Expand Down
35 changes: 18 additions & 17 deletions src/publisher/pubMqttIvData.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ template<class HMSYSTEM>
class PubMqttIvData {
public:
void setup(HMSYSTEM *sys, uint32_t *utcTs, std::queue<sendListCmdIv> *sendList) {
mSys = sys;
mUtcTimestamp = utcTs;
mSendList = sendList;
mState = IDLE;
mZeroValues = false;
mSys = sys;
mUtcTimestamp = utcTs;
mSendList = sendList;
mState = IDLE;
mYldTotalStore = 0;

mRTRDataHasBeenSent = false;

Expand All @@ -42,11 +42,14 @@ class PubMqttIvData {
yield();
}

bool start(bool zeroValues = false) {
void resetYieldDay() {
mYldTotalStore = 0;
}

bool start() {
if(IDLE != mState)
return false;

mZeroValues = zeroValues;
mRTRDataHasBeenSent = false;
mState = START;
return true;
Expand Down Expand Up @@ -117,10 +120,14 @@ class PubMqttIvData {
mIv->isProducing(); // recalculate status
mState = SEND_DATA;
} else if(mSendTotals && mTotalFound) {
if(mYldTotalStore > mTotal[2])
mSendTotalYd = false; // don't send yield total if last value was greater
else
mYldTotalStore = mTotal[2];

mState = SEND_TOTALS;
} else {
mSendList->pop();
mZeroValues = false;
mState = START;
}
}
Expand All @@ -141,7 +148,7 @@ class PubMqttIvData {

// calculate total values for RealTimeRunData_Debug
if (CH0 == rec->assign[mPos].ch) {
if(mIv->getStatus() > InverterStatus::OFF) {
if(mIv->getStatus() != InverterStatus::OFF) {
if(mIv->config->add2Total) {
mTotalFound = true;
switch (rec->assign[mPos].fieldId) {
Expand All @@ -152,11 +159,7 @@ class PubMqttIvData {
mTotal[1] += mIv->getValue(mPos, rec);
break;
case FLD_YD: {
float val = mIv->getValue(mPos, rec);
if(0 == val) // inverter restarted during day
mSendTotalYd = false;
else
mTotal[2] += val;
mTotal[2] += mIv->getValue(mPos, rec);
break;
}
case FLD_PDC:
Expand Down Expand Up @@ -236,7 +239,6 @@ class PubMqttIvData {
mPos++;
} else {
mSendList->pop();
mZeroValues = false;
mPos = 0;
mState = IDLE;
}
Expand All @@ -251,15 +253,14 @@ class PubMqttIvData {
uint8_t mCmd;
uint8_t mLastIvId;
bool mSendTotals, mTotalFound, mAllTotalFound, mSendTotalYd;
float mTotal[4];
float mTotal[4], mYldTotalStore;

Inverter<> *mIv, *mIvSend;
uint8_t mPos;
bool mRTRDataHasBeenSent;

char mSubTopic[32 + MAX_NAME_LENGTH + 1];
char mVal[140];
bool mZeroValues; // makes sure that yield day is sent even if no inverter is online

std::queue<sendListCmdIv> *mSendList;
};
Expand Down

0 comments on commit ca6ebfe

Please sign in to comment.