mirror of
https://github.com/lumapu/ahoy.git
synced 2025-04-30 10:46:24 +02:00
Merge branch 'development03' into hms
This commit is contained in:
commit
cf2cf37918
7 changed files with 258 additions and 99 deletions
|
@ -1,15 +1,14 @@
|
|||
Changelog v0.6.9
|
||||
# Development Changes
|
||||
|
||||
## 0.6.12 - 2023-04-28
|
||||
* improved MqTT
|
||||
* fix WiFi hostname during boot up
|
||||
* improved login: only one session at the same time is possible
|
||||
* fix UI: login screen for small displays; burger menu height; small modifications for import button (in setup)
|
||||
* improved WiFi reconnect
|
||||
* optimized performance: browser caching was improved to reduce requests from ESP
|
||||
* improved NRF24 communication for more stable data transmission
|
||||
* added / fixed MqTT subscription `ctrl/power/[IV-ID]`
|
||||
* improved save settings
|
||||
* improved UI in setup: now `.` and `,` are allowed as floating point seperator
|
||||
* fix zero yield day functionality
|
||||
* LEDs are now configurable to show if 1st inverter is available and if MqTT is connected
|
||||
* LED are configurable to active high or low
|
||||
* fix menu active item
|
||||
|
||||
## 0.6.11 - 2023-04-27
|
||||
* added MqTT class for publishing all values in Arduino `loop`
|
||||
|
||||
## 0.6.10 - HMS
|
||||
* Version available in `HMS` branch
|
||||
|
||||
## 0.6.9
|
||||
* last Relaese
|
||||
|
|
|
@ -219,6 +219,8 @@ void app::regularTickers(void) {
|
|||
if (mConfig->plugin.display.type != 0)
|
||||
everySec(std::bind(&DisplayType::tickerSecond, &mDisplay), "disp");
|
||||
every(std::bind(&PubSerialType::tick, &mPubSerial), mConfig->serial.interval, "uart");
|
||||
|
||||
// every([this]() {mPayload.simulation();}, 15, "simul");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 2023 Ahoy, https://www.mikrocontroller.net/topic/525778
|
||||
// 2023 Ahoy, https://ahoydtu.de
|
||||
// Creative Commons - https://creativecommons.org/licenses/by-nc-sa/4.0/deed
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
|||
//-------------------------------------
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 6
|
||||
#define VERSION_PATCH 10
|
||||
#define VERSION_PATCH 12
|
||||
|
||||
//-------------------------------------
|
||||
typedef struct {
|
||||
|
|
|
@ -72,6 +72,29 @@ class HmPayload {
|
|||
}
|
||||
}
|
||||
|
||||
/*void simulation() {
|
||||
uint8_t pay[] = {
|
||||
0x00, 0x01, 0x01, 0x24, 0x02, 0x28, 0x02, 0x33,
|
||||
0x06, 0x49, 0x06, 0x6a, 0x00, 0x05, 0x5f, 0x1b,
|
||||
0x00, 0x06, 0x66, 0x9a, 0x03, 0xfd, 0x04, 0x0b,
|
||||
0x01, 0x23, 0x02, 0x28, 0x02, 0x28, 0x06, 0x41,
|
||||
0x06, 0x43, 0x00, 0x05, 0xdc, 0x2c, 0x00, 0x06,
|
||||
0x2e, 0x3f, 0x04, 0x01, 0x03, 0xfb, 0x09, 0x78,
|
||||
0x13, 0x86, 0x18, 0x15, 0x00, 0xcf, 0x00, 0xfe,
|
||||
0x03, 0xe7, 0x01, 0x42, 0x00, 0x03
|
||||
};
|
||||
|
||||
Inverter<> *iv = mSys->getInverterByPos(0);
|
||||
record_t<> *rec = iv->getRecordStruct(0x0b);
|
||||
rec->ts = *mTimestamp;
|
||||
for (uint8_t i = 0; i < rec->length; i++) {
|
||||
iv->addValue(i, pay, rec);
|
||||
yield();
|
||||
}
|
||||
iv->doCalculations();
|
||||
notify(0x0b);
|
||||
}*/
|
||||
|
||||
void zeroYieldDay(Inverter<> *iv) {
|
||||
DPRINTLN(DBG_DEBUG, F("zeroYieldDay"));
|
||||
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "../hm/hmSystem.h"
|
||||
|
||||
#include "pubMqttDefs.h"
|
||||
#include "pubMqttIvData.h"
|
||||
|
||||
#define QOS_0 0
|
||||
|
||||
|
@ -63,6 +64,10 @@ class PubMqtt {
|
|||
mUtcTimestamp = utcTs;
|
||||
mIntervalTimeout = 1;
|
||||
|
||||
mSendIvData.setup(sys, utcTs, &mSendList);
|
||||
mSendIvData.setPublishFunc([this](const char *subTopic, const char *payload, bool retained) {
|
||||
publish(subTopic, payload, retained);
|
||||
});
|
||||
mDiscovery.running = false;
|
||||
|
||||
snprintf(mLwtTopic, MQTT_TOPIC_LEN + 5, "%s/mqtt", mCfgMqtt->topic);
|
||||
|
@ -88,6 +93,8 @@ class PubMqtt {
|
|||
}
|
||||
|
||||
void loop() {
|
||||
mSendIvData.loop();
|
||||
|
||||
#if defined(ESP8266)
|
||||
mClient.loop();
|
||||
yield();
|
||||
|
@ -562,89 +569,7 @@ class PubMqtt {
|
|||
if(mSendList.empty())
|
||||
return;
|
||||
|
||||
float total[4];
|
||||
bool RTRDataHasBeenSent = false;
|
||||
|
||||
while(!mSendList.empty()) {
|
||||
memset(total, 0, sizeof(float) * 4);
|
||||
uint8_t curInfoCmd = mSendList.front();
|
||||
|
||||
if ((curInfoCmd != RealTimeRunData_Debug) || !RTRDataHasBeenSent) { // send RTR Data only once
|
||||
bool sendTotals = (curInfoCmd == RealTimeRunData_Debug);
|
||||
|
||||
for (uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
||||
Inverter<> *iv = mSys->getInverterByPos(id);
|
||||
if (NULL == iv)
|
||||
continue; // skip to next inverter
|
||||
if (!iv->config->enabled)
|
||||
continue; // skip to next inverter
|
||||
|
||||
// send RTR Data only if status is available
|
||||
if ((curInfoCmd != RealTimeRunData_Debug) || (MQTT_STATUS_NOT_AVAIL_NOT_PROD != mLastIvState[id]))
|
||||
sendData(iv, curInfoCmd);
|
||||
|
||||
// calculate total values for RealTimeRunData_Debug
|
||||
if (sendTotals) {
|
||||
record_t<> *rec = iv->getRecordStruct(curInfoCmd);
|
||||
|
||||
sendTotals &= (iv->getLastTs(rec) > 0);
|
||||
if (sendTotals) {
|
||||
for (uint8_t i = 0; i < rec->length; i++) {
|
||||
if (CH0 == rec->assign[i].ch) {
|
||||
switch (rec->assign[i].fieldId) {
|
||||
case FLD_PAC:
|
||||
total[0] += iv->getValue(i, rec);
|
||||
break;
|
||||
case FLD_YT:
|
||||
total[1] += iv->getValue(i, rec);
|
||||
break;
|
||||
case FLD_YD:
|
||||
total[2] += iv->getValue(i, rec);
|
||||
break;
|
||||
case FLD_PDC:
|
||||
total[3] += iv->getValue(i, rec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
yield();
|
||||
}
|
||||
|
||||
if (sendTotals) {
|
||||
uint8_t fieldId;
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
bool retained = true;
|
||||
switch (i) {
|
||||
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(total[i]));
|
||||
publish(mSubTopic, mVal, retained);
|
||||
}
|
||||
RTRDataHasBeenSent = true;
|
||||
yield();
|
||||
}
|
||||
}
|
||||
|
||||
mSendList.pop(); // remove from list once all inverters were processed
|
||||
}
|
||||
|
||||
mSendIvData.start();
|
||||
mLastAnyAvail = anyAvail;
|
||||
}
|
||||
|
||||
|
@ -655,6 +580,8 @@ class PubMqtt {
|
|||
#endif
|
||||
|
||||
HMSYSTEM *mSys;
|
||||
PubMqttIvData<HMSYSTEM> mSendIvData;
|
||||
|
||||
uint32_t *mUtcTimestamp;
|
||||
uint32_t mRxCnt, mTxCnt;
|
||||
std::queue<uint8_t> mSendList;
|
||||
|
|
208
src/publisher/pubMqttIvData.h
Normal file
208
src/publisher/pubMqttIvData.h
Normal file
|
@ -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__*/
|
|
@ -78,7 +78,7 @@ function parseNav(obj) {
|
|||
if(i == 2)
|
||||
continue;
|
||||
var l = document.getElementById("nav"+i);
|
||||
if(window.location.pathname == "/" + l.href.split('/').pop())
|
||||
if(window.location.pathname == "/" + l.href.substring(0, l.href.indexOf("?")).split('/').pop())
|
||||
l.classList.add("active");
|
||||
|
||||
if(obj["menu_protEn"]) {
|
||||
|
|
Loading…
Add table
Reference in a new issue