diff --git a/src/CHANGES.md b/src/CHANGES.md index a29901ac..c83130c8 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -7,6 +7,7 @@ * merge Prometheus metrics fix #1310 * merge MI grid profile request #1306 * merge update documentation / readme #1305 +* add `getLossRate` to radio statistics and to MqTT #1199 ## 0.8.38 - 2023-12-31 * fix Grid-Profile JSON #1304 diff --git a/src/defines.h b/src/defines.h index ad321921..d5aa04c2 100644 --- a/src/defines.h +++ b/src/defines.h @@ -103,6 +103,10 @@ typedef struct { uint32_t frmCnt; uint32_t txCnt; uint32_t retransmits; + uint16_t ivRxCnt; // last iv rx frames (from GetLossRate) + uint16_t ivTxCnt; // last iv tx frames (from GetLossRate) + uint16_t dtuRxCnt; // current DTU rx frames (since last GetLossRate) + uint16_t dtuTxCnt; // current DTU tx frames (since last GetLossRate) } statistics_t; #endif /*__DEFINES_H__*/ diff --git a/src/hm/Communication.h b/src/hm/Communication.h index 53106524..a448884e 100644 --- a/src/hm/Communication.h +++ b/src/hm/Communication.h @@ -151,7 +151,7 @@ class Communication : public CommQueue<> { if(validateIvSerial(&p->packet[1], q->iv)) { q->iv->radioStatistics.frmCnt++; - q->iv->mDtuRxCnt++; + q->iv->radioStatistics.dtuRxCnt++; if (p->packet[0] == (TX_REQ_INFO + ALL_FRAMES)) { // response from get information command if(parseFrame(p)) diff --git a/src/hm/hmInverter.h b/src/hm/hmInverter.h index 91b8480e..37a469a7 100644 --- a/src/hm/hmInverter.h +++ b/src/hm/hmInverter.h @@ -141,12 +141,6 @@ class Inverter { uint8_t curCmtFreq; // current used CMT frequency, used to check if freq. was changed during runtime bool commEnabled; // 'pause night communication' sets this field to false - uint16_t mIvRxCnt; // last iv rx frames (from GetLossRate) - uint16_t mIvTxCnt; // last iv tx frames (from GetLossRate) - uint16_t mDtuRxCnt; // cur dtu rx frames (since last GetLossRate) - uint16_t mDtuTxCnt; // cur dtu tx frames (since last getLoassRate) - uint8_t mGetLossInterval; // request iv every AHOY_GET_LOSS_INTERVAL RealTimeRunData_Debu - static uint32_t *timestamp; // system timestamp static cfgInst_t *generalConfig; // general inverter configuration from setup @@ -171,10 +165,6 @@ class Inverter { mIsSingleframeReq = false; radio = NULL; commEnabled = true; - mIvRxCnt = 0; - mIvTxCnt = 0; - mDtuRxCnt = 0; - mDtuTxCnt = 0; memset(&radioStatistics, 0, sizeof(statistics_t)); memset(heuristics.txRfQuality, -6, 5); @@ -605,21 +595,25 @@ class Inverter { uint16_t rxCnt = (pyld[0] << 8) + pyld[1]; uint16_t txCnt = (pyld[2] << 8) + pyld[3]; - if (mIvRxCnt || mIvTxCnt) { // there was successful GetLossRate in the past + if (radioStatistics.ivRxCnt || radioStatistics.ivTxCnt) { // there was successful GetLossRate in the past DPRINT_IVID(DBG_INFO, id); - DBGPRINTLN("Inv loss: " + - String (mDtuTxCnt - (rxCnt - mIvRxCnt)) + " of " + - String (mDtuTxCnt) + ", DTU loss: " + - String (txCnt - mIvTxCnt - mDtuRxCnt) + " of " + - String (txCnt - mIvTxCnt)); + DBGPRINT(F("Inv loss: ")); + DBGPRINT(String (radioStatistics.dtuTxCnt - (rxCnt - radioStatistics.ivRxCnt))); + DBGPRINT(F(" of ")); + DBGPRINT(String (radioStatistics.dtuTxCnt)); + DBGPRINT(F(", DTU loss: ")); + DBGPRINT(String (txCnt - radioStatistics.ivTxCnt - radioStatistics.dtuRxCnt)); + DBGPRINT(F(" of ")); + DBGPRINTLN(String (txCnt - radioStatistics.ivTxCnt)); } - mIvRxCnt = rxCnt; - mIvTxCnt = txCnt; - mDtuRxCnt = 0; // start new interval - mDtuTxCnt = 0; // start new interval + radioStatistics.ivRxCnt = rxCnt; + radioStatistics.ivTxCnt = txCnt; + radioStatistics.dtuRxCnt = 0; // start new interval + radioStatistics.dtuTxCnt = 0; // start new interval return true; } + return false; } @@ -811,6 +805,7 @@ class Inverter { bool mDevControlRequest; // true if change needed uint8_t mGridLen = 0; uint8_t mGridProfile[MAX_GRID_LENGTH]; + uint8_t mGetLossInterval; // request iv every AHOY_GET_LOSS_INTERVAL RealTimeRunData_Debug }; template diff --git a/src/hm/hmRadio.h b/src/hm/hmRadio.h index 6539dd21..c7b9581c 100644 --- a/src/hm/hmRadio.h +++ b/src/hm/hmRadio.h @@ -339,7 +339,7 @@ class HmRadio : public Radio { mMillis = millis(); mLastIv = iv; - iv->mDtuTxCnt++; + iv->radioStatistics.dtuTxCnt++; } uint64_t getIvId(Inverter<> *iv) { diff --git a/src/hms/hmsRadio.h b/src/hms/hmsRadio.h index 6b502816..3b3893ac 100644 --- a/src/hms/hmsRadio.h +++ b/src/hms/hmsRadio.h @@ -112,7 +112,7 @@ class CmtRadio : public Radio { if(CMT_ERR_RX_IN_FIFO == status) mIrqRcvd = true; } - iv->mDtuTxCnt++; + iv->radioStatistics.dtuTxCnt++; } uint64_t getIvId(Inverter<> *iv) { diff --git a/src/publisher/pubMqttIvData.h b/src/publisher/pubMqttIvData.h index 9a364ec9..3a38a5ed 100644 --- a/src/publisher/pubMqttIvData.h +++ b/src/publisher/pubMqttIvData.h @@ -195,12 +195,16 @@ class PubMqttIvData { inline void sendRadioStat(uint8_t start) { snprintf(mSubTopic, 32 + MAX_NAME_LENGTH, "%s/radio_stat", mIv->config->name); - snprintf(mVal, 100, "{\"tx\":%d,\"success\":%d,\"fail\":%d,\"no_answer\":%d,\"retransmits\":%d}", + snprintf(mVal, 140, "{\"tx\":%d,\"success\":%d,\"fail\":%d,\"no_answer\":%d,\"retransmits\":%d,\"lossIvRx\":%d,\"lossIvTx\":%d,\"lossDtuRx\":%d,\"lossDtuTx\":%d}", mIv->radioStatistics.txCnt, mIv->radioStatistics.rxSuccess, mIv->radioStatistics.rxFail, mIv->radioStatistics.rxFailNoAnser, - mIv->radioStatistics.retransmits); + mIv->radioStatistics.retransmits, + mIv->radioStatistics.ivRxCnt, + mIv->radioStatistics.ivTxCnt, + mIv->radioStatistics.dtuRxCnt, + mIv->radioStatistics.dtuTxCnt); mPublish(mSubTopic, mVal, false, QOS_0); } @@ -263,7 +267,7 @@ class PubMqttIvData { bool mRTRDataHasBeenSent; char mSubTopic[32 + MAX_NAME_LENGTH + 1]; - char mVal[100]; + char mVal[140]; bool mZeroValues; // makes sure that yield day is sent even if no inverter is online std::queue *mSendList;