Browse Source

0.8.53

* fix history graph
* fix MqTT yield day #1331
pull/1356/head
lumapu 9 months ago
parent
commit
ca6ebfe0fe
  1. 4
      src/CHANGES.md
  2. 16
      src/app.cpp
  3. 1
      src/app.h
  4. 2
      src/defines.h
  5. 15
      src/publisher/pubMqtt.h
  6. 27
      src/publisher/pubMqttIvData.h

4
src/CHANGES.md

@ -1,5 +1,9 @@
# Development Changes # Development Changes
## 0.8.53 - 2024-01-12
* fix history graph
* fix MqTT yield day #1331
## 0.8.52 - 2024-01-11 ## 0.8.52 - 2024-01-11
* possible fix of 'division by zero' #1345 * possible fix of 'division by zero' #1345
* fix lang #1348 #1346 * fix lang #1348 #1346

16
src/app.cpp

@ -152,7 +152,7 @@ void app::regularTickers(void) {
//everySec([this]() { mImprov.tickSerial(); }, "impro"); //everySec([this]() { mImprov.tickSerial(); }, "impro");
#endif #endif
everySec(std::bind(&HistoryType::tickerSecond, mHistory), "hist"); everySec(std::bind(&HistoryType::tickerSecond, &mHistory), "hist");
} }
#if defined(ETHERNET) #if defined(ETHERNET)
@ -241,7 +241,7 @@ void app::tickCalcSunrise(void) {
if (mMqttEnabled) { if (mMqttEnabled) {
tickSun(); tickSun();
nxtTrig = mSunrise + mConfig->sun.offsetSecMorning + 1; // one second safety to trigger correctly 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'
} }
} }
@ -291,6 +291,13 @@ void app::tickSun(void) {
once(std::bind(&app::tickSun, this), 1, "mqSun"); // MQTT not connected, retry 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) { void app::tickZeroValues(void) {
zeroIvValues(!CHECK_AVAIL, SKIP_YIELD_DAY); zeroIvValues(!CHECK_AVAIL, SKIP_YIELD_DAY);
@ -423,11 +430,8 @@ void app:: zeroIvValues(bool checkAvail, bool skipYieldDay) {
changed = true; changed = true;
} }
if(changed) { if(changed)
if(mMqttEnabled && !skipYieldDay)
mMqtt.setZeroValuesEnable();
payloadEventListener(RealTimeRunData_Debug, NULL); payloadEventListener(RealTimeRunData_Debug, NULL);
}
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

1
src/app.h

@ -314,6 +314,7 @@ class app : public IApp, public ah::Scheduler {
void tickCalcSunrise(void); void tickCalcSunrise(void);
void tickIVCommunication(void); void tickIVCommunication(void);
void tickSun(void); void tickSun(void);
void tickSunrise(void);
void tickComm(void); void tickComm(void);
void tickSend(void); void tickSend(void);
void tickMinute(void); void tickMinute(void);

2
src/defines.h

@ -13,7 +13,7 @@
//------------------------------------- //-------------------------------------
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 8 #define VERSION_MINOR 8
#define VERSION_PATCH 52 #define VERSION_PATCH 53
//------------------------------------- //-------------------------------------
typedef struct { typedef struct {

15
src/publisher/pubMqtt.h

@ -43,7 +43,6 @@ class PubMqtt {
memset(mLastIvState, (uint8_t)InverterStatus::OFF, MAX_NUM_INVERTERS); memset(mLastIvState, (uint8_t)InverterStatus::OFF, MAX_NUM_INVERTERS);
memset(mIvLastRTRpub, 0, MAX_NUM_INVERTERS * 4); memset(mIvLastRTRpub, 0, MAX_NUM_INVERTERS * 4);
mLastAnyAvail = false; mLastAnyAvail = false;
mZeroValues = false;
} }
~PubMqtt() { } ~PubMqtt() { }
@ -134,7 +133,7 @@ class PubMqtt {
#endif #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()) if (!mClient.connected())
return false; return false;
@ -153,10 +152,12 @@ class PubMqtt {
publish(mSubTopic, ((iv->commEnabled) ? dict[STR_TRUE] : dict[STR_FALSE]), true); publish(mSubTopic, ((iv->commEnabled) ? dict[STR_TRUE] : dict[STR_FALSE]), true);
} }
snprintf(mSubTopic, 32 + MAX_NAME_LENGTH, "comm_disabled"); snprintf(mSubTopic, 32 + MAX_NAME_LENGTH, "comm_disabled");
publish(mSubTopic, (((*mUtcTimestamp > (sunset + offsE)) || (*mUtcTimestamp < (sunrise + offsM))) ? dict[STR_TRUE] : dict[STR_FALSE]), true); publish(mSubTopic, (((*mUtcTimestamp > (sunset + offsE)) || (*mUtcTimestamp < (sunrise + offsM))) ? dict[STR_TRUE] : dict[STR_FALSE]), true);
if(isSunrise)
mSendIvData.resetYieldDay();
return true; return true;
} }
@ -239,10 +240,6 @@ class PubMqtt {
} }
} }
void setZeroValuesEnable(void) {
mZeroValues = true;
}
private: private:
void onConnect(bool sessionPreset) { void onConnect(bool sessionPreset) {
DPRINTLN(DBG_INFO, F("MQTT connected")); DPRINTLN(DBG_INFO, F("MQTT connected"));
@ -592,8 +589,7 @@ class PubMqtt {
if(mSendList.empty()) if(mSendList.empty())
return; return;
mSendIvData.start(mZeroValues); mSendIvData.start();
mZeroValues = false;
mLastAnyAvail = anyAvail; mLastAnyAvail = anyAvail;
} }
@ -612,7 +608,6 @@ class PubMqtt {
std::array<bool, MAX_NUM_INVERTERS> mSendAlarm{}; std::array<bool, MAX_NUM_INVERTERS> mSendAlarm{};
subscriptionCb mSubscriptionCb; subscriptionCb mSubscriptionCb;
bool mLastAnyAvail; bool mLastAnyAvail;
bool mZeroValues;
InverterStatus mLastIvState[MAX_NUM_INVERTERS]; InverterStatus mLastIvState[MAX_NUM_INVERTERS];
uint32_t mIvLastRTRpub[MAX_NUM_INVERTERS]; uint32_t mIvLastRTRpub[MAX_NUM_INVERTERS];
uint16_t mIntervalTimeout; uint16_t mIntervalTimeout;

27
src/publisher/pubMqttIvData.h

@ -26,7 +26,7 @@ class PubMqttIvData {
mUtcTimestamp = utcTs; mUtcTimestamp = utcTs;
mSendList = sendList; mSendList = sendList;
mState = IDLE; mState = IDLE;
mZeroValues = false; mYldTotalStore = 0;
mRTRDataHasBeenSent = false; mRTRDataHasBeenSent = false;
@ -42,11 +42,14 @@ class PubMqttIvData {
yield(); yield();
} }
bool start(bool zeroValues = false) { void resetYieldDay() {
mYldTotalStore = 0;
}
bool start() {
if(IDLE != mState) if(IDLE != mState)
return false; return false;
mZeroValues = zeroValues;
mRTRDataHasBeenSent = false; mRTRDataHasBeenSent = false;
mState = START; mState = START;
return true; return true;
@ -117,10 +120,14 @@ class PubMqttIvData {
mIv->isProducing(); // recalculate status mIv->isProducing(); // recalculate status
mState = SEND_DATA; mState = SEND_DATA;
} else if(mSendTotals && mTotalFound) { } 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; mState = SEND_TOTALS;
} else { } else {
mSendList->pop(); mSendList->pop();
mZeroValues = false;
mState = START; mState = START;
} }
} }
@ -141,7 +148,7 @@ class PubMqttIvData {
// calculate total values for RealTimeRunData_Debug // calculate total values for RealTimeRunData_Debug
if (CH0 == rec->assign[mPos].ch) { if (CH0 == rec->assign[mPos].ch) {
if(mIv->getStatus() > InverterStatus::OFF) { if(mIv->getStatus() != InverterStatus::OFF) {
if(mIv->config->add2Total) { if(mIv->config->add2Total) {
mTotalFound = true; mTotalFound = true;
switch (rec->assign[mPos].fieldId) { switch (rec->assign[mPos].fieldId) {
@ -152,11 +159,7 @@ class PubMqttIvData {
mTotal[1] += mIv->getValue(mPos, rec); mTotal[1] += mIv->getValue(mPos, rec);
break; break;
case FLD_YD: { case FLD_YD: {
float val = mIv->getValue(mPos, rec); mTotal[2] += mIv->getValue(mPos, rec);
if(0 == val) // inverter restarted during day
mSendTotalYd = false;
else
mTotal[2] += val;
break; break;
} }
case FLD_PDC: case FLD_PDC:
@ -236,7 +239,6 @@ class PubMqttIvData {
mPos++; mPos++;
} else { } else {
mSendList->pop(); mSendList->pop();
mZeroValues = false;
mPos = 0; mPos = 0;
mState = IDLE; mState = IDLE;
} }
@ -251,7 +253,7 @@ class PubMqttIvData {
uint8_t mCmd; uint8_t mCmd;
uint8_t mLastIvId; uint8_t mLastIvId;
bool mSendTotals, mTotalFound, mAllTotalFound, mSendTotalYd; bool mSendTotals, mTotalFound, mAllTotalFound, mSendTotalYd;
float mTotal[4]; float mTotal[4], mYldTotalStore;
Inverter<> *mIv, *mIvSend; Inverter<> *mIv, *mIvSend;
uint8_t mPos; uint8_t mPos;
@ -259,7 +261,6 @@ class PubMqttIvData {
char mSubTopic[32 + MAX_NAME_LENGTH + 1]; char mSubTopic[32 + MAX_NAME_LENGTH + 1];
char mVal[140]; char mVal[140];
bool mZeroValues; // makes sure that yield day is sent even if no inverter is online
std::queue<sendListCmdIv> *mSendList; std::queue<sendListCmdIv> *mSendList;
}; };

Loading…
Cancel
Save