improved payload handling (retransmit all fragments on CRC error)

improved `isAvailable`, checkes all record structs, inverter becomes available more early because version is check first
fix tickers were not set if NTP is not available
disabled annoying `FlashStringHelper` it gives randomly Expeptions during development, feels more stable since then
moved erase button to the bottom in settings, not nice but more functional
split `tx_count` to `tx_cnt` and `retransmits` in `system.html`
fix mqtt retransmit IP address #602
added debug infos for `scheduler` (web -> `/debug` as trigger prints list of tickers to serial console)
This commit is contained in:
lumapu 2023-01-19 22:43:23 +01:00
parent 3d3e3dc8c6
commit 3adcb68d98
19 changed files with 191 additions and 115 deletions

View file

@ -3,11 +3,6 @@
// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
//-----------------------------------------------------------------------------
#if defined(ESP32) && defined(F)
#undef F
#define F(sl) (sl)
#endif
#include "app.h"
#include <ArduinoJson.h>
#include "utils/sun.h"
@ -43,7 +38,7 @@ void app::setup() {
mWifi.setup(mConfig, &mTimestamp, std::bind(&app::onWifi, this, std::placeholders::_1));
#if !defined(AP_ONLY)
everySec(std::bind(&ahoywifi::tickWifiLoop, &mWifi));
everySec(std::bind(&ahoywifi::tickWifiLoop, &mWifi), "wifiL");
#endif
mSys->addInverters(&mConfig->inst);
@ -136,48 +131,49 @@ void app::onWifi(bool gotIp) {
regularTickers(); // reinstall regular tickers
if (gotIp) {
mInnerLoopCb = std::bind(&app::loopStandard, this);
mSendTickerId = every(std::bind(&app::tickSend, this), mConfig->nrf.sendInterval);
mSendTickerId = every(std::bind(&app::tickSend, this), mConfig->nrf.sendInterval, "tSend");
mMqttReconnect = true;
once(std::bind(&app::tickNtpUpdate, this), 2);
once(std::bind(&app::tickNtpUpdate, this), 2, "ntp2");
}
else {
mInnerLoopCb = std::bind(&app::loopWifi, this);
everySec(std::bind(&ahoywifi::tickWifiLoop, &mWifi));
everySec(std::bind(&ahoywifi::tickWifiLoop, &mWifi), "wifiL");
}
}
//-----------------------------------------------------------------------------
void app::regularTickers(void) {
DPRINTLN(DBG_DEBUG, F("regularTickers"));
everySec(std::bind(&WebType::tickSecond, &mWeb));
everySec(std::bind(&WebType::tickSecond, &mWeb), "webSc");
// Plugins
#if defined(ENA_NOKIA) || defined(ENA_SSD1306) || defined(ENA_SH1106)
everySec(std::bind(&MonoDisplayType::tickerSecond, &mMonoDisplay));
#endif
every(std::bind(&PubSerialType::tick, &mPubSerial), mConfig->serial.interval);
every(std::bind(&PubSerialType::tick, &mPubSerial), mConfig->serial.interval, "uart");
}
//-----------------------------------------------------------------------------
void app::tickNtpUpdate(void) {
uint32_t nxtTrig = 5; // default: check again in 5 sec
if (mWifi.getNtpTime()) {
if (mWifi.getNtpTime(&nxtTrig)) {
if (mMqttReconnect && mMqttEnabled) {
mMqtt.connect();
everySec(std::bind(&PubMqttType::tickerSecond, &mMqtt));
everyMin(std::bind(&PubMqttType::tickerMinute, &mMqtt));
everySec(std::bind(&PubMqttType::tickerSecond, &mMqtt), "mqttS");
everyMin(std::bind(&PubMqttType::tickerMinute, &mMqtt), "mqttM");
uint32_t nxtTrig = mTimestamp - ((mTimestamp - 1) % 86400) + 86400; // next midnight
if(mConfig->mqtt.rstYieldMidNight)
onceAt(std::bind(&app::tickMidnight, this), nxtTrig);
onceAt(std::bind(&app::tickMidnight, this), nxtTrig, "midNi");
mMqttReconnect = false;
}
nxtTrig = 43200; // check again in 12 h
nxtTrig = 43200;
if((mSunrise == 0) && (mConfig->sun.lat) && (mConfig->sun.lon)) {
mCalculatedTimezoneOffset = (int8_t)((mConfig->sun.lon >= 0 ? mConfig->sun.lon + 7.5 : mConfig->sun.lon - 7.5) / 15) * 3600;
tickCalcSunrise();
}
}
once(std::bind(&app::tickNtpUpdate, this), nxtTrig);
once(std::bind(&app::tickNtpUpdate, this), nxtTrig, "ntp");
}
//-----------------------------------------------------------------------------
@ -191,7 +187,7 @@ void app::tickCalcSunrise(void) {
tickIVCommunication();
uint32_t nxtTrig = mSunset + mConfig->sun.offsetSec + 60; // set next trigger to communication stop, +60 for safety that it is certain past communication stop
onceAt(std::bind(&app::tickCalcSunrise, this), nxtTrig);
onceAt(std::bind(&app::tickCalcSunrise, this), nxtTrig, "Sunri");
if (mMqttEnabled)
tickSun();
}
@ -212,7 +208,7 @@ void app::tickIVCommunication(void) {
}
}
if (nxtTrig != 0)
onceAt(std::bind(&app::tickIVCommunication, this), nxtTrig);
onceAt(std::bind(&app::tickIVCommunication, this), nxtTrig, "ivCom");
}
if (mMqttEnabled)
tickComm();
@ -222,14 +218,14 @@ void app::tickIVCommunication(void) {
void app::tickSun(void) {
// only used and enabled by MQTT (see setup())
if (!mMqtt.tickerSun(mSunrise, mSunset, mConfig->sun.offsetSec, mConfig->sun.disNightCom))
once(std::bind(&app::tickSun, this), 1); // MQTT not connected, retry
once(std::bind(&app::tickSun, this), 1, "mqSun"); // MQTT not connected, retry
}
//-----------------------------------------------------------------------------
void app::tickComm(void) {
// only used and enabled by MQTT (see setup())
if (!mMqtt.tickerComm(!mIVCommunicationOn))
once(std::bind(&app::tickComm, this), 1); // MQTT not connected, retry
once(std::bind(&app::tickComm, this), 1, "mqCom"); // MQTT not connected, retry
}
//-----------------------------------------------------------------------------
@ -268,7 +264,7 @@ void app::tickSend(void) {
void app::tickMidnight(void) {
// only used and enabled by MQTT (see setup())
uint32_t nxtTrig = mTimestamp - ((mTimestamp - 1) % 86400) + 86400; // next midnight
onceAt(std::bind(&app::tickMidnight, this), nxtTrig);
onceAt(std::bind(&app::tickMidnight, this), nxtTrig, "mid2");
mMqtt.tickerMidnight();
}
@ -285,8 +281,6 @@ void app::resetSystem(void) {
#ifdef AP_ONLY
mTimestamp = 1;
#else
mTimestamp = 0;
#endif
mSunrise = 0;
@ -329,8 +323,7 @@ void app::updateLed(void) {
if(mConfig->led.led0 != 0xff) {
Inverter<> *iv = mSys->getInverterByPos(0);
if (NULL != iv) {
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
if(iv->isProducing(mTimestamp, rec))
if(iv->isProducing(mTimestamp))
digitalWrite(mConfig->led.led0, LOW); // LED on
else
digitalWrite(mConfig->led.led0, HIGH); // LED off