From ca25f1654850067a5bb474bcbf8ddc769d52089c Mon Sep 17 00:00:00 2001 From: lumapu Date: Sun, 12 Feb 2023 02:00:54 +0100 Subject: [PATCH] prevent send devcontrol request during disabled night communication changed yield total correction as module (inverter input) value #570 MQTT Yield Day zero, next try to fix #671 --- src/CHANGES.md | 5 +++++ src/app.cpp | 5 +++-- src/app.h | 3 ++- src/config/settings.h | 12 ++++++------ src/defines.h | 2 +- src/hm/hmInverter.h | 5 ++--- src/hm/hmRadio.h | 2 +- src/publisher/pubMqtt.h | 7 ++----- src/web/RestApi.h | 4 ++-- src/web/html/setup.html | 18 +++++++++--------- src/web/html/style.css | 2 +- src/web/web.h | 2 +- src/wifi/ahoywifi.cpp | 2 ++ 13 files changed, 37 insertions(+), 32 deletions(-) diff --git a/src/CHANGES.md b/src/CHANGES.md index 26a38c00..ba0c5866 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -2,6 +2,11 @@ (starting from release version `0.5.66`) +## 0.5.86 +* prevent send devcontrol request during disabled night communication +* changed yield total correction as module (inverter input) value #570 +* MQTT Yield Day zero, next try to fix #671 + ## 0.5.85 * fix power-limit was not checked for max retransmits #667 * fix blue LED lights up all the time #672 diff --git a/src/app.cpp b/src/app.cpp index 5fcab648..6d752fc5 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -181,10 +181,11 @@ void app::tickNtpUpdate(void) { } // immediately start communicating - if(isOK && mSendFirst) { + // @TODO: leads to reboot loops, everytime if there is no asynchronous function #674 + /*if(isOK && mSendFirst) { mSendFirst = false; once(std::bind(&app::tickSend, this), 2, "senOn"); - } + }*/ mMqttReconnect = false; } diff --git a/src/app.h b/src/app.h index c3a7d0b3..b449a9a3 100644 --- a/src/app.h +++ b/src/app.h @@ -136,7 +136,8 @@ class app : public IApp, public ah::Scheduler { } void ivSendHighPrio(Inverter<> *iv) { - mPayload.ivSendHighPrio(iv); + if(mIVCommunicationOn) // only send commands if communcation is enabled + mPayload.ivSendHighPrio(iv); } bool getMqttIsConnected() { diff --git a/src/config/settings.h b/src/config/settings.h index d54bbf4e..9e58515b 100644 --- a/src/config/settings.h +++ b/src/config/settings.h @@ -105,8 +105,8 @@ typedef struct { char name[MAX_NAME_LENGTH]; serial_u serial; uint16_t chMaxPwr[4]; + int32_t yieldCor[4]; // signed YieldTotal correction value char chName[4][MAX_NAME_LENGTH]; - uint32_t yieldCor; // YieldTotal correction value } cfgIv_t; typedef struct { @@ -220,7 +220,7 @@ class settings { else { //DPRINTLN(DBG_INFO, fp.readString()); //fp.seek(0, SeekSet); - DynamicJsonDocument root(4096); + DynamicJsonDocument root(4500); DeserializationError err = deserializeJson(root, fp); if(!err && (root.size() > 0)) { mCfg.valid = true; @@ -252,7 +252,7 @@ class settings { return false; } - DynamicJsonDocument json(4096); + DynamicJsonDocument json(4500); JsonObject root = json.to(); jsonWifi(root.createNestedObject(F("wifi")), true); jsonNrf(root.createNestedObject(F("nrf")), true); @@ -520,17 +520,17 @@ class settings { obj[F("en")] = (bool)cfg->enabled; obj[F("name")] = cfg->name; obj[F("sn")] = cfg->serial.u64; - obj[F("yield")] = cfg->yieldCor; for(uint8_t i = 0; i < 4; i++) { - obj[F("pwr")][i] = cfg->chMaxPwr[i]; + obj[F("yield")][i] = cfg->yieldCor[i]; + obj[F("pwr")][i] = cfg->chMaxPwr[i]; obj[F("chName")][i] = cfg->chName[i]; } } else { cfg->enabled = (bool)obj[F("en")]; snprintf(cfg->name, MAX_NAME_LENGTH, "%s", obj[F("name")].as()); cfg->serial.u64 = obj[F("sn")]; - cfg->yieldCor = obj[F("yield")]; for(uint8_t i = 0; i < 4; i++) { + cfg->yieldCor[i] = obj[F("yield")][i]; cfg->chMaxPwr[i] = obj[F("pwr")][i]; snprintf(cfg->chName[i], MAX_NAME_LENGTH, "%s", obj[F("chName")][i].as()); } diff --git a/src/defines.h b/src/defines.h index 38cf3926..b070adf9 100644 --- a/src/defines.h +++ b/src/defines.h @@ -13,7 +13,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 5 -#define VERSION_PATCH 85 +#define VERSION_PATCH 86 //------------------------------------- typedef struct { diff --git a/src/hm/hmInverter.h b/src/hm/hmInverter.h index d50f341a..3369c5a8 100644 --- a/src/hm/hmInverter.h +++ b/src/hm/hmInverter.h @@ -255,9 +255,8 @@ class Inverter { if (FLD_T == rec->assign[pos].fieldId) { // temperature is a signed value! rec->record[pos] = (REC_TYP)((int16_t)val) / (REC_TYP)(div); - } else if ((FLD_YT == rec->assign[pos].fieldId) - && (config->yieldCor != 0)) { - rec->record[pos] = ((REC_TYP)(val) / (REC_TYP)(div)) - ((REC_TYP)config->yieldCor); + } else if (FLD_YT == rec->assign[pos].fieldId) { + rec->record[pos] = ((REC_TYP)(val) / (REC_TYP)(div)) + ((REC_TYP)config->yieldCor[rec->assign[pos].ch]); } else { if ((REC_TYP)(div) > 1) rec->record[pos] = (REC_TYP)(val) / (REC_TYP)(div); diff --git a/src/hm/hmRadio.h b/src/hm/hmRadio.h index ef5e5e23..3ad39f31 100644 --- a/src/hm/hmRadio.h +++ b/src/hm/hmRadio.h @@ -238,7 +238,7 @@ class HmRadio { bool getReceived(void) { bool tx_ok, tx_fail, rx_ready; mNrf24.whatHappened(tx_ok, tx_fail, rx_ready); // resets the IRQ pin to HIGH - DBGPRINTLN("RX whatHappened Ch" + String(mRfChLst[mRxChIdx]) + " " + String(tx_ok) + String(tx_fail) + String(rx_ready)); + //DBGPRINTLN("RX whatHappened Ch" + String(mRfChLst[mRxChIdx]) + " " + String(tx_ok) + String(tx_fail) + String(rx_ready)); bool isLastPackage = false; while(mNrf24.available()) { diff --git a/src/publisher/pubMqtt.h b/src/publisher/pubMqtt.h index 25151312..03304ab0 100644 --- a/src/publisher/pubMqtt.h +++ b/src/publisher/pubMqtt.h @@ -474,7 +474,7 @@ class PubMqtt { } } - void sendIvData(bool sendTotals = true) { + void sendIvData() { if(mSendList.empty()) return; @@ -527,8 +527,8 @@ class PubMqtt { total[3] += iv->getValue(i, rec); break; } + sendTotal = true; } - sendTotal = true; } yield(); } @@ -537,9 +537,6 @@ class PubMqtt { mSendList.pop(); // remove from list once all inverters were processed - if(!sendTotals) // skip total value calculation - continue; - if ((true == sendTotal) && processIvStatus()) { uint8_t fieldId; for (uint8_t i = 0; i < 4; i++) { diff --git a/src/web/RestApi.h b/src/web/RestApi.h index 36cf1357..9c3f931f 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -287,11 +287,11 @@ class RestApi { obj2[F("serial")] = String(iv->config->serial.u64, HEX); obj2[F("channels")] = iv->channels; obj2[F("version")] = String(iv->getFwVersion()); - obj2[F("yieldCor")] = iv->config->yieldCor; for(uint8_t j = 0; j < iv->channels; j ++) { + obj2[F("ch_yield_cor")][j] = iv->config->yieldCor[j]; obj2[F("ch_max_power")][j] = iv->config->chMaxPwr[j]; - obj2[F("ch_name")][j] = iv->config->chName[j]; + obj2[F("ch_name")][j] = iv->config->chName[j]; } } } diff --git a/src/web/html/setup.html b/src/web/html/setup.html index 723c6677..6da7160c 100644 --- a/src/web/html/setup.html +++ b/src/web/html/setup.html @@ -298,7 +298,7 @@ document.getElementById("btnAdd").addEventListener("click", function() { if(highestId <= (maxInv-1)) { - ivHtml(JSON.parse('{"enabled":true,"name":"","serial":"","channels":4,"ch_max_power":[0,0,0,0],"ch_name":["","","",""]}'), highestId); + ivHtml(JSON.parse('{"enabled":true,"name":"","serial":"","channels":4,"ch_max_power":[0,0,0,0],"ch_name":["","","",""],"ch_yield_cor":[0,0,0,0]}'), highestId); } }); @@ -393,9 +393,11 @@ for(var i=0;i<4;i++) { setHide(id+"ModPwr"+i, true); setHide(id+"ModName"+i, true); + setHide(id+"YieldCor"+i, true); } setHide("lbl"+id+"ModPwr", true); setHide("lbl"+id+"ModName", true); + setHide("lbl"+id+"YieldCor", true); if(serial.charAt(0) == 1) { if((serial.charAt(1) == 0) || (serial.charAt(1) == 1)) { @@ -413,9 +415,11 @@ for(var i=0;itype = INV_TYPE_4CH; iv->channels = 4; break; default: break; } - iv->config->yieldCor = request->arg("inv" + String(i) + "YieldCor").toInt(); // name request->arg("inv" + String(i) + "Name").toCharArray(iv->config->name, MAX_NAME_LENGTH); // max channel power / name for(uint8_t j = 0; j < 4; j++) { + iv->config->yieldCor[j] = request->arg("inv" + String(i) + "YieldCor" + String(j)).toInt(); iv->config->chMaxPwr[j] = request->arg("inv" + String(i) + "ModPwr" + String(j)).toInt() & 0xffff; request->arg("inv" + String(i) + "ModName" + String(j)).toCharArray(iv->config->chName[j], MAX_NAME_LENGTH); } diff --git a/src/wifi/ahoywifi.cpp b/src/wifi/ahoywifi.cpp index dc8f03b5..1e9165e6 100644 --- a/src/wifi/ahoywifi.cpp +++ b/src/wifi/ahoywifi.cpp @@ -311,6 +311,8 @@ void ahoywifi::getBSSIDs() { //----------------------------------------------------------------------------- void ahoywifi::connectionEvent(WiFiStatus_t status) { + DPRINTLN(DBG_INFO, "connectionEvent"); + switch(status) { case CONNECTED: if(mStaConn != CONNECTED) {