mirror of https://github.com/lumapu/ahoy.git
lumapu
2 years ago
8 changed files with 281 additions and 137 deletions
@ -1,34 +1,14 @@ |
|||
# Development Changes |
|||
|
|||
## 0.6.7 - 2023-04-13 |
|||
* merge PR #883, improved store of settings and javascript, thx @tastendruecker123 |
|||
* support `.` and `,` as floating point seperator in setup #881 |
|||
## 0.6.12 - 2023-04-28 |
|||
* improved MqTT |
|||
* fix menu active item |
|||
|
|||
## 0.6.6 - 2023-04-12 |
|||
* increased distance for `import` button in mobile view #879 |
|||
* changed `led_high_active` to `bool` #879 |
|||
## 0.6.11 - 2023-04-27 |
|||
* added MqTT class for publishing all values in Arduino `loop` |
|||
|
|||
## 0.6.5 - 2023-04-11 |
|||
* fix #845 MqTT subscription for `ctrl/power/[IV-ID]` was missing |
|||
* merge PR #876, check JSON settings during read for existance |
|||
* **NOTE:** incompatible change: renamed `led_high_active` to `act_high`, maybe setting must be changed after update |
|||
* merge PR #861 do not send channel metric if channel is disabled |
|||
## 0.6.10 - HMS |
|||
* Version available in `HMS` branch |
|||
|
|||
## 0.6.4 - 2023-04-06 |
|||
* merge PR #846, improved NRF24 communication and MI, thx @beegee3 & @rejoe2 |
|||
* merge PR #859, fix burger menu height, thx @ThomasPohl |
|||
|
|||
## 0.6.3 - 2023-04-04 |
|||
* fix login, password length was not checked #852 |
|||
* merge PR #854 optimize browser caching, thx @tastendruecker123 #828 |
|||
* fix WiFi reconnect not working #851 |
|||
* updated issue templates #822 |
|||
|
|||
## 0.6.2 - 2023-04-04 |
|||
* fix login from multiple clients #819 |
|||
* fix login screen on small displays |
|||
|
|||
## 0.6.1 - 2023-04-01 |
|||
* merge LED fix - LED1 shows MqTT state, LED configureable active high/low #839 |
|||
* only publish new inverter data #826 |
|||
* potential fix of WiFi hostname during boot up #752 |
|||
## 0.6.9 |
|||
* last Relaese |
|||
|
@ -0,0 +1,208 @@ |
|||
//-----------------------------------------------------------------------------
|
|||
// 2023 Ahoy, https://ahoydtu.de
|
|||
// Creative Commons - https://creativecommons.org/licenses/by-nc-sa/4.0/deed
|
|||
//-----------------------------------------------------------------------------
|
|||
|
|||
#ifndef __PUB_MQTT_IV_DATA_H__ |
|||
#define __PUB_MQTT_IV_DATA_H__ |
|||
|
|||
#include "../utils/dbg.h" |
|||
#include "../hm/hmSystem.h" |
|||
#include "pubMqttDefs.h" |
|||
|
|||
typedef std::function<void(const char *subTopic, const char *payload, bool retained)> pubMqttPublisherType; |
|||
|
|||
template<class HMSYSTEM> |
|||
class PubMqttIvData { |
|||
public: |
|||
void setup(HMSYSTEM *sys, uint32_t *utcTs, std::queue<uint8_t> *sendList) { |
|||
mSys = sys; |
|||
mUtcTimestamp = utcTs; |
|||
mSendList = sendList; |
|||
mState = IDLE; |
|||
|
|||
memset(mIvLastRTRpub, 0, MAX_NUM_INVERTERS * 4); |
|||
mRTRDataHasBeenSent = false; |
|||
|
|||
mTable[IDLE] = &PubMqttIvData::stateIdle; |
|||
mTable[START] = &PubMqttIvData::stateStart; |
|||
mTable[FIND_NXT_IV] = &PubMqttIvData::stateFindNxtIv; |
|||
mTable[SEND_DATA] = &PubMqttIvData::stateSend; |
|||
mTable[SEND_TOTALS] = &PubMqttIvData::stateSendTotals; |
|||
} |
|||
|
|||
void loop() { |
|||
(this->*mTable[mState])(); |
|||
yield(); |
|||
} |
|||
|
|||
bool start(void) { |
|||
if(IDLE != mState) |
|||
return false; |
|||
|
|||
mRTRDataHasBeenSent = false; |
|||
mState = START; |
|||
return true; |
|||
} |
|||
|
|||
void setPublishFunc(pubMqttPublisherType cb) { |
|||
mPublish = cb; |
|||
} |
|||
|
|||
private: |
|||
enum State {IDLE, START, FIND_NXT_IV, SEND_DATA, SEND_TOTALS, NUM_STATES}; |
|||
typedef void (PubMqttIvData::*StateFunction)(); |
|||
|
|||
void stateIdle() { |
|||
; // nothing to do
|
|||
} |
|||
|
|||
void stateStart() { |
|||
mLastIvId = 0; |
|||
if(!mSendList->empty()) { |
|||
mCmd = mSendList->front(); |
|||
|
|||
if((RealTimeRunData_Debug != mCmd) || !mRTRDataHasBeenSent) { |
|||
mSendTotals = (RealTimeRunData_Debug == mCmd); |
|||
memset(mTotal, 0, sizeof(float) * 4); |
|||
mState = FIND_NXT_IV; |
|||
} else |
|||
mSendList->pop(); |
|||
} else |
|||
mState = IDLE; |
|||
} |
|||
|
|||
void stateFindNxtIv() { |
|||
bool found = false; |
|||
|
|||
for (; mLastIvId < mSys->getNumInverters(); mLastIvId++) { |
|||
mIv = mSys->getInverterByPos(mLastIvId); |
|||
if (NULL != mIv) { |
|||
if (mIv->config->enabled) { |
|||
found = true; |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
mLastIvId++; |
|||
|
|||
mPos = 0; |
|||
if(found) |
|||
mState = SEND_DATA; |
|||
else if(mSendTotals) |
|||
mState = SEND_TOTALS; |
|||
else { |
|||
mSendList->pop(); |
|||
mState = START; |
|||
} |
|||
} |
|||
|
|||
void stateSend() { |
|||
record_t<> *rec = mIv->getRecordStruct(mCmd); |
|||
uint32_t lastTs = mIv->getLastTs(rec); |
|||
bool pubData = (lastTs > 0); |
|||
if (mCmd == RealTimeRunData_Debug) |
|||
pubData &= (lastTs != mIvLastRTRpub[mIv->id]); |
|||
|
|||
if (pubData) { |
|||
if(mPos < rec->length) { |
|||
bool retained = false; |
|||
if (mCmd == RealTimeRunData_Debug) { |
|||
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++; |
|||
return; |
|||
} |
|||
retained = true; |
|||
break; |
|||
} |
|||
|
|||
// calculate total values for RealTimeRunData_Debug
|
|||
if (CH0 == rec->assign[mPos].ch) { |
|||
switch (rec->assign[mPos].fieldId) { |
|||
case FLD_PAC: |
|||
mTotal[0] += mIv->getValue(mPos, rec); |
|||
break; |
|||
case FLD_YT: |
|||
mTotal[1] += mIv->getValue(mPos, rec); |
|||
break; |
|||
case FLD_YD: |
|||
mTotal[2] += mIv->getValue(mPos, rec); |
|||
break; |
|||
case FLD_PDC: |
|||
mTotal[3] += mIv->getValue(mPos, rec); |
|||
break; |
|||
} |
|||
} |
|||
} else |
|||
mIvLastRTRpub[mIv->id] = lastTs; |
|||
|
|||
snprintf(mSubTopic, 32 + MAX_NAME_LENGTH, "%s/ch%d/%s", mIv->config->name, rec->assign[mPos].ch, fields[rec->assign[mPos].fieldId]); |
|||
snprintf(mVal, 40, "%g", ah::round3(mIv->getValue(mPos, rec))); |
|||
mPublish(mSubTopic, mVal, retained); |
|||
mPos++; |
|||
} else |
|||
mState = FIND_NXT_IV; |
|||
} else |
|||
mState = FIND_NXT_IV; |
|||
} |
|||
|
|||
void stateSendTotals() { |
|||
uint8_t fieldId; |
|||
if(mPos < 4) { |
|||
bool retained = true; |
|||
switch (mPos) { |
|||
default: |
|||
case 0: |
|||
fieldId = FLD_PAC; |
|||
retained = false; |
|||
break; |
|||
case 1: |
|||
fieldId = FLD_YT; |
|||
break; |
|||
case 2: |
|||
fieldId = FLD_YD; |
|||
break; |
|||
case 3: |
|||
fieldId = FLD_PDC; |
|||
retained = false; |
|||
break; |
|||
} |
|||
snprintf(mSubTopic, 32 + MAX_NAME_LENGTH, "total/%s", fields[fieldId]); |
|||
snprintf(mVal, 40, "%g", ah::round3(mTotal[mPos])); |
|||
mPublish(mSubTopic, mVal, retained); |
|||
mPos++; |
|||
} else { |
|||
mSendList->pop(); |
|||
mState = START; |
|||
} |
|||
|
|||
mRTRDataHasBeenSent = true; |
|||
} |
|||
|
|||
HMSYSTEM *mSys; |
|||
uint32_t *mUtcTimestamp; |
|||
pubMqttPublisherType mPublish; |
|||
State mState; |
|||
StateFunction mTable[NUM_STATES]; |
|||
|
|||
uint8_t mCmd; |
|||
uint8_t mLastIvId; |
|||
bool mSendTotals; |
|||
float mTotal[4]; |
|||
|
|||
Inverter<> *mIv; |
|||
uint8_t mPos; |
|||
uint32_t mIvLastRTRpub[MAX_NUM_INVERTERS]; |
|||
bool mRTRDataHasBeenSent; |
|||
|
|||
char mSubTopic[32 + MAX_NAME_LENGTH + 1]; |
|||
char mVal[40]; |
|||
|
|||
std::queue<uint8_t> *mSendList; |
|||
}; |
|||
|
|||
#endif /*__PUB_MQTT_IV_DATA_H__*/ |
Loading…
Reference in new issue