Browse Source

Add files via upload

pull/1080/head
oberfritze 2 years ago
committed by GitHub
parent
commit
7d54eaa29f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      src/CHANGES.md
  2. 117
      src/app.cpp
  3. 27
      src/app.h
  4. 5
      src/appInterface.h
  5. 7
      src/defines.h
  6. 130
      src/platformio.ini

30
src/CHANGES.md

@ -1,15 +1,17 @@
Changelog v0.6.9 Changelog for ahoy-all-in-one compared to 0.6.9 of the main project
* improved MqTT - read SML/OBIS from UART (stream parser with min resources needed); Connections 9600,8,n,1, GND-GND, VCC-3V3, TX-TX, RX-RX
* fix WiFi hostname during boot up - prepared to show chart of grid power and total solar ac power for current days daylight period (6 a.m. to 8 p.m.)
* improved login: only one session at the same time is possible - show current grid power
* fix UI: login screen for small displays; burger menu height; small modifications for import button (in setup) - show max solar ac/dc power
* improved WiFi reconnect - improved radio retransmit (complete retransmit if nothing was received, but only when inverter ought to be active)
* optimized performance: browser caching was improved to reduce requests from ESP - shortcut radio traces a little bit
* improved NRF24 communication for more stable data transmission
* added / fixed MqTT subscription `ctrl/power/[IV-ID]` DRAWBACKS:
* improved save settings - MQTT Source is commented out (except 1 var which is used for other purpose as well)
* improved UI in setup: now `.` and `,` are allowed as floating point seperator - only up to 2 Inverters (was: 10)
* fix zero yield day functionality - RX/TX of UART0 is used for serial interface to IR sensor.
* LEDs are now configurable to show if 1st inverter is available and if MqTT is connected But: Currently there is enough heap available for stable operation on a ESP8266 plattform (WEMOS D1 R1). So adjust to your needs and see if the AHOY-DTU is still stable in operation with your hw plattform.
* LED are configurable to active high or low To update firmware via USB, unplug serial connection to IR sensor first. Surprisingly during normal operation it seems that one can use a full connected USB cable (for power supply). But I'm not sure, if this allways will be true.
Of course you cannot operate a display that uses RX/TX pins of UART0, simultanously.
- Due to not matching licence of the chart lib certain parts of visualization.html are commented out. See comments there.

117
src/app.cpp

@ -6,21 +6,32 @@
#include "app.h" #include "app.h"
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include "utils/sun.h" #include "utils/sun.h"
#include "plugins/SML_OBIS_Parser.h"
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
app::app() : ah::Scheduler() {} app::app() : ah::Scheduler() {}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::setup() { void app::setup() {
#ifdef AHOY_SML_OBIS_SUPPORT
/* Assumptions made:
Electricity meter sends SML telegrams via IR interface (9600,8,n,1) without being asked (typical behaviour).
An IR sensor is connected to the UART0 of AHOY DTU. Connected pins: GND-GND, 3V3-VCC, RX-RX, TX-TX.
*/
Serial.begin(9600, SERIAL_8N1, SERIAL_RX_ONLY);
#else
Serial.begin(115200); Serial.begin(115200);
#endif
while (!Serial) while (!Serial)
yield(); yield();
ah::Scheduler::setup(); ah::Scheduler::setup();
resetSystem(); resetSystem();
mSettings.setup(); mSettings.setup();
mSettings.getPtr(mConfig); mSettings.getPtr(mConfig);
DPRINT(DBG_INFO, F("Settings valid: ")); DPRINT(DBG_INFO, F("Settings valid: "));
@ -30,7 +41,7 @@ void app::setup() {
DBGPRINTLN(F("false")); DBGPRINTLN(F("false"));
mSys.enableDebug(); mSys.enableDebug();
mSys.setup(mConfig->nrf.amplifierPower, mConfig->nrf.pinIrq, mConfig->nrf.pinCe, mConfig->nrf.pinCs, mConfig->nrf.pinSclk, mConfig->nrf.pinMosi, mConfig->nrf.pinMiso); mSys.setup(&mTimestamp, mConfig->nrf.amplifierPower, mConfig->nrf.pinIrq, mConfig->nrf.pinCe, mConfig->nrf.pinCs, mConfig->nrf.pinSclk, mConfig->nrf.pinMosi, mConfig->nrf.pinMiso);
#if defined(AP_ONLY) #if defined(AP_ONLY)
mInnerLoopCb = std::bind(&app::loopStandard, this); mInnerLoopCb = std::bind(&app::loopStandard, this);
@ -62,7 +73,7 @@ void app::setup() {
DPRINTLN(DBG_WARN, F("WARNING! your NRF24 module can't be reached, check the wiring")); DPRINTLN(DBG_WARN, F("WARNING! your NRF24 module can't be reached, check the wiring"));
// when WiFi is in client mode, then enable mqtt broker // when WiFi is in client mode, then enable mqtt broker
#if !defined(AP_ONLY) #if !defined(AP_ONLY) && defined (AHOY_MQTT_SUPPORT)
mMqttEnabled = (mConfig->mqtt.broker[0] > 0); mMqttEnabled = (mConfig->mqtt.broker[0] > 0);
if (mMqttEnabled) { if (mMqttEnabled) {
mMqtt.setup(&mConfig->mqtt, mConfig->sys.deviceName, mVersion, &mSys, &mTimestamp); mMqtt.setup(&mConfig->mqtt, mConfig->sys.deviceName, mVersion, &mSys, &mTimestamp);
@ -84,8 +95,11 @@ void app::setup() {
mPubSerial.setup(mConfig, &mSys, &mTimestamp); mPubSerial.setup(mConfig, &mSys, &mTimestamp);
regularTickers(); #ifdef AHOY_SML_OBIS_SUPPORT
sml_setup (this, &mTimestamp);
#endif
regularTickers();
// DBGPRINTLN("--- end setup"); // DBGPRINTLN("--- end setup");
// DBGPRINTLN(String(ESP.getFreeHeap())); // DBGPRINTLN(String(ESP.getFreeHeap()));
@ -109,11 +123,16 @@ void app::loopStandard(void) {
if (mConfig->serial.debug) { if (mConfig->serial.debug) {
DPRINT(DBG_INFO, F("RX ")); DPRINT(DBG_INFO, F("RX "));
DBGPRINT(String(p->len)); DBGPRINT(String(p->len));
#ifdef undef
DBGPRINT(F("B Ch")); DBGPRINT(F("B Ch"));
DBGPRINT(String(p->ch)); DBGPRINT(String(p->ch));
DBGPRINT(F(" | ")); DBGPRINT(F(" | "));
mSys.Radio.dumpBuf(p->packet, p->len); mSys.Radio.dumpBuf(p->packet, p->len);
#else
DBGPRINTLN(" Bytes");
#endif
} }
mStat.frmCnt++; mStat.frmCnt++;
Inverter<> *iv = mSys.findInverter(&p->packet[1]); Inverter<> *iv = mSys.findInverter(&p->packet[1]);
@ -132,9 +151,16 @@ void app::loopStandard(void) {
mPayload.loop(); mPayload.loop();
mMiPayload.loop(); mMiPayload.loop();
if (mMqttEnabled) #ifdef AHOY_MQTT_SUPPORT
if (mMqttEnabled) {
mMqtt.loop(); mMqtt.loop();
} }
#endif
#ifdef AHOY_SML_OBIS_SUPPORT
sml_loop ();
#endif
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::loopWifi(void) { void app::loopWifi(void) {
@ -150,11 +176,15 @@ void app::onWifi(bool gotIp) {
if (gotIp) { if (gotIp) {
mInnerLoopCb = std::bind(&app::loopStandard, this); mInnerLoopCb = std::bind(&app::loopStandard, this);
every(std::bind(&app::tickSend, this), mConfig->nrf.sendInterval, "tSend"); every(std::bind(&app::tickSend, this), mConfig->nrf.sendInterval, "tSend");
mMqttReconnect = true; mMqttReconnect = true;
mSunrise = 0; // needs to be set to 0, to reinstall sunrise and ivComm tickers! mSunrise = 0; // needs to be set to 0, to reinstall sunrise and ivComm tickers!
once(std::bind(&app::tickNtpUpdate, this), 2, "ntp2"); once(std::bind(&app::tickNtpUpdate, this), 2, "ntp2");
if (WIFI_AP == WiFi.getMode()) { if (WIFI_AP == WiFi.getMode()) {
#ifdef AHOY_MQTT_SUPPORT
mMqttEnabled = false; mMqttEnabled = false;
#endif
everySec(std::bind(&ahoywifi::tickWifiLoop, &mWifi), "wifiL"); everySec(std::bind(&ahoywifi::tickWifiLoop, &mWifi), "wifiL");
} }
} else { } else {
@ -178,21 +208,27 @@ void app::tickNtpUpdate(void) {
uint32_t nxtTrig = 5; // default: check again in 5 sec uint32_t nxtTrig = 5; // default: check again in 5 sec
bool isOK = mWifi.getNtpTime(); bool isOK = mWifi.getNtpTime();
if (isOK || mTimestamp != 0) { if (isOK || mTimestamp != 0) {
#ifdef AHOY_MQTT_SUPPORT
if (mMqttReconnect && mMqttEnabled) { if (mMqttReconnect && mMqttEnabled) {
mMqtt.tickerSecond(); mMqtt.tickerSecond();
everySec(std::bind(&PubMqttType::tickerSecond, &mMqtt), "mqttS"); everySec(std::bind(&PubMqttType::tickerSecond, &mMqtt), "mqttS");
everyMin(std::bind(&PubMqttType::tickerMinute, &mMqtt), "mqttM"); everyMin(std::bind(&PubMqttType::tickerMinute, &mMqtt), "mqttM");
} }
#endif
// only install schedulers once even if NTP wasn't successful in first loop // only install schedulers once even if NTP wasn't successful in first loop
if (mMqttReconnect) { // @TODO: mMqttReconnect is variable which scope has changed if (mMqttReconnect) { // @TODO: mMqttReconnect is variable which scope has changed
if (mConfig->inst.rstValsNotAvail) if (mConfig->inst.rstValsNotAvail)
everyMin(std::bind(&app::tickMinute, this), "tMin"); everyMin(std::bind(&app::tickMinute, this), "tMin");
if (mConfig->inst.rstYieldMidNight) {
uint32_t localTime = gTimezone.toLocal(mTimestamp); uint32_t localTime = gTimezone.toLocal(mTimestamp);
uint32_t midTrig = gTimezone.toUTC(localTime - (localTime % 86400) + 86400); // next midnight local time uint32_t midTrig = gTimezone.toUTC(localTime - (localTime % 86400) + 86400); // next midnight local time
onceAt(std::bind(&app::tickMidnight, this), midTrig, "midNi"); onceAt(std::bind(&app::tickMidnight, this), midTrig, "midNi");
}
mSys.cleanup_history();
#ifdef AHOY_SML_OBIS_SUPPORT
sml_cleanup_history ();
#endif
} }
nxtTrig = isOK ? 43200 : 60; // depending on NTP update success check again in 12 h or in 1 min nxtTrig = isOK ? 43200 : 60; // depending on NTP update success check again in 12 h or in 1 min
@ -226,8 +262,10 @@ void app::tickCalcSunrise(void) {
uint32_t nxtTrig = mSunset + mConfig->sun.offsetSec + 60; // set next trigger to communication stop, +60 for safety that it is certain past communication stop 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, "Sunri"); onceAt(std::bind(&app::tickCalcSunrise, this), nxtTrig, "Sunri");
#ifdef AHOY_MQTT_SUPPORT
if (mMqttEnabled) if (mMqttEnabled)
tickSun(); tickSun();
#endif
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -251,22 +289,26 @@ void app::tickIVCommunication(void) {
tickComm(); tickComm();
} }
#ifdef AHOY_MQTT_SUPPORT
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::tickSun(void) { void app::tickSun(void) {
// only used and enabled by MQTT (see setup()) // only used and enabled by MQTT (see setup())
if (!mMqtt.tickerSun(mSunrise, mSunset, mConfig->sun.offsetSec, mConfig->sun.disNightCom)) if (!mMqtt.tickerSun(mSunrise, mSunset, mConfig->sun.offsetSec, mConfig->sun.disNightCom))
once(std::bind(&app::tickSun, this), 1, "mqSun"); // MQTT not connected, retry once(std::bind(&app::tickSun, this), 1, "mqSun"); // MQTT not connected, retry
} }
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::tickComm(void) { void app::tickComm(void) {
if ((!mIVCommunicationOn) && (mConfig->inst.rstValsCommStop)) if ((!mIVCommunicationOn) && (mConfig->inst.rstValsCommStop))
once(std::bind(&app::tickZeroValues, this), mConfig->nrf.sendInterval, "tZero"); once(std::bind(&app::tickZeroValues, this), mConfig->nrf.sendInterval, "tZero");
#ifdef AHOY_MQTT_SUPPORT
if (mMqttEnabled) { if (mMqttEnabled) {
if (!mMqtt.tickerComm(!mIVCommunicationOn)) if (!mMqtt.tickerComm(!mIVCommunicationOn))
once(std::bind(&app::tickComm, this), 5, "mqCom"); // MQTT not connected, retry after 5s once(std::bind(&app::tickComm, this), 5, "mqCom"); // MQTT not connected, retry after 5s
} }
#endif
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -300,7 +342,8 @@ void app::tickMinute(void) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::tickMidnight(void) { void app::tickMidnight(void) {
// only triggered if 'reset values at midnight is enabled' if (mConfig->inst.rstYieldMidNight) {
// only if 'reset values at midnight is enabled'
uint32_t localTime = gTimezone.toLocal(mTimestamp); uint32_t localTime = gTimezone.toLocal(mTimestamp);
uint32_t nxtTrig = gTimezone.toUTC(localTime - (localTime % 86400) + 86400); // next midnight local time uint32_t nxtTrig = gTimezone.toUTC(localTime - (localTime % 86400) + 86400); // next midnight local time
onceAt(std::bind(&app::tickMidnight, this), nxtTrig, "mid2"); onceAt(std::bind(&app::tickMidnight, this), nxtTrig, "mid2");
@ -315,9 +358,15 @@ void app::tickMidnight(void) {
mPayload.zeroInverterValues(iv); mPayload.zeroInverterValues(iv);
mPayload.zeroYieldDay(iv); mPayload.zeroYieldDay(iv);
} }
#ifdef AHOY_MQTT_SUPPORT
if (mMqttEnabled) if (mMqttEnabled)
mMqtt.tickerMidnight(); mMqtt.tickerMidnight();
#endif
}
mSys.cleanup_history ();
#ifdef AHOY_SML_OBIS_SUPPORT
sml_cleanup_history();
#endif
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -329,7 +378,7 @@ void app::tickSend(void) {
if (mIVCommunicationOn) { if (mIVCommunicationOn) {
if (!mSys.Radio.mBufCtrl.empty()) { if (!mSys.Radio.mBufCtrl.empty()) {
if (mConfig->serial.debug) { if (mConfig->serial.debug) {
DPRINT(DBG_DEBUG, F("recbuf not empty! #")); DPRINT(DBG_INFO, F("recbuf not empty! #"));
DBGPRINTLN(String(mSys.Radio.mBufCtrl.size())); DBGPRINTLN(String(mSys.Radio.mBufCtrl.size()));
} }
} }
@ -347,7 +396,11 @@ void app::tickSend(void) {
mPayload.ivSend(iv); mPayload.ivSend(iv);
else else
mMiPayload.ivSend(iv); mMiPayload.ivSend(iv);
} else {
DPRINTLN (DBG_INFO, "iv not enabled");
} }
} else {
DPRINTLN (DBG_INFO, "no inverter");
} }
} else { } else {
if (mConfig->serial.debug) if (mConfig->serial.debug)
@ -371,7 +424,9 @@ void app::resetSystem(void) {
mSunrise = 0; mSunrise = 0;
mSunset = 0; mSunset = 0;
#ifdef AHOY_MQTT_SUPPORT
mMqttEnabled = false; mMqttEnabled = false;
#endif
mSendLastIvId = 0; mSendLastIvId = 0;
mShowRebootRequest = false; mShowRebootRequest = false;
@ -382,10 +437,12 @@ void app::resetSystem(void) {
memset(&mStat, 0, sizeof(statistics_t)); memset(&mStat, 0, sizeof(statistics_t));
} }
#ifdef AHOY_MQTT_SUPPORT
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::mqttSubRxCb(JsonObject obj) { void app::mqttSubRxCb(JsonObject obj) {
mApi.ctrlRequest(obj); mApi.ctrlRequest(obj);
} }
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::setupLed(void) { void app::setupLed(void) {
@ -416,6 +473,7 @@ void app::updateLed(void) {
} }
} }
#ifdef AHOY_MQTT_SUPPORT
if (mConfig->led.led1 != 0xff) { if (mConfig->led.led1 != 0xff) {
if (getMqttIsConnected()) { if (getMqttIsConnected()) {
digitalWrite(mConfig->led.led1, led_on); digitalWrite(mConfig->led.led1, led_on);
@ -423,4 +481,41 @@ void app::updateLed(void) {
digitalWrite(mConfig->led.led1, led_off); digitalWrite(mConfig->led.led1, led_off);
} }
} }
#endif
}
//-----------------------------------------------------------------------------
void app::check_hist_file (File file)
{
if (file) {
uint16_t exp_index = AHOY_MIN_PAC_SUN_HOUR * 60 / AHOY_PAC_INTERVAL, index;
unsigned char data[4];
while (file.read (data, sizeof (data)) == sizeof (data)) {
index = data[0] + (data[1] << 8);
if (index != exp_index) {
DPRINTLN (DBG_WARN, "Unexpected " + String (index) + " <-> " + String (exp_index));
}
exp_index = index + 1;
}
file.close();
}
}
//-----------------------------------------------------------------------------
void app::show_history (String path)
{
Dir dir = LittleFS.openDir (path);
DPRINTLN (DBG_INFO, "Enter Dir: " + path);
while (dir.next()) {
if (dir.isDirectory ()) {
show_history (path + "/" + dir.fileName());
} else {
DPRINTLN (DBG_INFO, "file " + dir.fileName() +
", Size: " + String (dir.fileSize()));
check_hist_file (dir.openFile ("r"));
}
}
DPRINTLN (DBG_INFO, "Leave Dir: " + path);
} }

27
src/app.h

@ -37,12 +37,15 @@ typedef HmPayload<HmSystemType> PayloadType;
typedef MiPayload<HmSystemType> MiPayloadType; typedef MiPayload<HmSystemType> MiPayloadType;
typedef Web<HmSystemType> WebType; typedef Web<HmSystemType> WebType;
typedef RestApi<HmSystemType> RestApiType; typedef RestApi<HmSystemType> RestApiType;
#ifdef AHOY_MQTT_SUPPORT
typedef PubMqtt<HmSystemType> PubMqttType; typedef PubMqtt<HmSystemType> PubMqttType;
#endif
typedef PubSerial<HmSystemType> PubSerialType; typedef PubSerial<HmSystemType> PubSerialType;
// PLUGINS // PLUGINS
#include "plugins/Display/Display.h" #include "plugins/Display/Display.h"
typedef Display<HmSystemType> DisplayType; typedef Display<HmSystemType> DisplayType;
// #include <SoftwareSerial.h>
class app : public IApp, public ah::Scheduler { class app : public IApp, public ah::Scheduler {
public: public:
@ -54,6 +57,7 @@ class app : public IApp, public ah::Scheduler {
void loopStandard(void); void loopStandard(void);
void loopWifi(void); void loopWifi(void);
void onWifi(bool gotIp); void onWifi(bool gotIp);
void cleanup_history(void);
void regularTickers(void); void regularTickers(void);
void handleIntr(void) { void handleIntr(void) {
@ -135,7 +139,7 @@ class app : public IApp, public ah::Scheduler {
bool getRebootRequestState() { bool getRebootRequestState() {
return mShowRebootRequest; return mShowRebootRequest;
} }
#ifdef AHOY_MQTT_SUPPORT
void setMqttDiscoveryFlag() { void setMqttDiscoveryFlag() {
once(std::bind(&PubMqttType::sendDiscoveryConfig, &mMqtt), 1, "disCf"); once(std::bind(&PubMqttType::sendDiscoveryConfig, &mMqtt), 1, "disCf");
} }
@ -143,7 +147,7 @@ class app : public IApp, public ah::Scheduler {
void setMqttPowerLimitAck(Inverter<> *iv) { void setMqttPowerLimitAck(Inverter<> *iv) {
mMqtt.setPowerLimitAck(iv); mMqtt.setPowerLimitAck(iv);
} }
#endif
void ivSendHighPrio(Inverter<> *iv) { void ivSendHighPrio(Inverter<> *iv) {
if(mIVCommunicationOn) { // only send commands if communcation is enabled if(mIVCommunicationOn) { // only send commands if communcation is enabled
if (iv->ivGen == IV_HM) if (iv->ivGen == IV_HM)
@ -152,7 +156,7 @@ class app : public IApp, public ah::Scheduler {
mMiPayload.ivSendHighPrio(iv); mMiPayload.ivSendHighPrio(iv);
} }
} }
#ifdef AHOY_MQTT_SUPPORT
bool getMqttIsConnected() { bool getMqttIsConnected() {
return mMqtt.isConnected(); return mMqtt.isConnected();
} }
@ -164,7 +168,7 @@ class app : public IApp, public ah::Scheduler {
uint32_t getMqttRxCnt() { uint32_t getMqttRxCnt() {
return mMqtt.getRxCnt(); return mMqtt.getRxCnt();
} }
#endif
bool getProtection(AsyncWebServerRequest *request) { bool getProtection(AsyncWebServerRequest *request) {
return mWeb.isProtected(request); return mWeb.isProtected(request);
} }
@ -205,21 +209,23 @@ class app : public IApp, public ah::Scheduler {
HmSystemType mSys; HmSystemType mSys;
private: private:
typedef std::function<void()> innerLoopCb; typedef std::function<void()> innerLoopCb;
void resetSystem(void); void resetSystem(void);
void payloadEventListener(uint8_t cmd) { void payloadEventListener(uint8_t cmd) {
#if !defined(AP_ONLY) #if !defined(AP_ONLY) && defined(AHOY_MQTT_SUPPORT)
if (mMqttEnabled) if (mMqttEnabled)
mMqtt.payloadEventListener(cmd); mMqtt.payloadEventListener(cmd);
#endif #endif
if(mConfig->plugin.display.type != 0) if(mConfig->plugin.display.type != 0)
mDisplay.payloadEventListener(cmd); mDisplay.payloadEventListener(cmd);
} }
#ifdef AHOY_MQTT_SUPPORT
void mqttSubRxCb(JsonObject obj); void mqttSubRxCb(JsonObject obj);
#endif
void setupLed(); void setupLed();
void updateLed(); void updateLed();
@ -251,6 +257,10 @@ class app : public IApp, public ah::Scheduler {
void tickMinute(void); void tickMinute(void);
void tickZeroValues(void); void tickZeroValues(void);
void tickMidnight(void); void tickMidnight(void);
void check_hist_file (File file);
void show_history (String path);
/* void tickSerial(void) { /* void tickSerial(void) {
if(Serial.available() == 0) if(Serial.available() == 0)
return; return;
@ -283,16 +293,19 @@ class app : public IApp, public ah::Scheduler {
settings_t *mConfig; settings_t *mConfig;
bool mSavePending; bool mSavePending;
bool mSaveReboot; bool mSaveReboot;
bool mCritical;
uint8_t mSendLastIvId; uint8_t mSendLastIvId;
bool mSendFirst; bool mSendFirst;
statistics_t mStat; statistics_t mStat;
#ifdef AHOY_MQTT_SUPPORT
// mqtt // mqtt
PubMqttType mMqtt; PubMqttType mMqtt;
bool mMqttReconnect;
bool mMqttEnabled; bool mMqttEnabled;
#endif
bool mMqttReconnect;
// sun // sun
int32_t mCalculatedTimezoneOffset; int32_t mCalculatedTimezoneOffset;

5
src/appInterface.h

@ -40,14 +40,17 @@ class IApp {
virtual bool getRebootRequestState() = 0; virtual bool getRebootRequestState() = 0;
virtual bool getSettingsValid() = 0; virtual bool getSettingsValid() = 0;
#ifdef AHOY_MQTT_SUPPORT
virtual void setMqttDiscoveryFlag() = 0; virtual void setMqttDiscoveryFlag() = 0;
virtual void setMqttPowerLimitAck(Inverter<> *iv) = 0; virtual void setMqttPowerLimitAck(Inverter<> *iv) = 0;
#endif
virtual void ivSendHighPrio(Inverter<> *iv) = 0; virtual void ivSendHighPrio(Inverter<> *iv) = 0;
#ifdef AHOY_MQTT_SUPPORT
virtual bool getMqttIsConnected() = 0; virtual bool getMqttIsConnected() = 0;
virtual uint32_t getMqttRxCnt() = 0; virtual uint32_t getMqttRxCnt() = 0;
virtual uint32_t getMqttTxCnt() = 0; virtual uint32_t getMqttTxCnt() = 0;
#endif
virtual bool getProtection(AsyncWebServerRequest *request) = 0; virtual bool getProtection(AsyncWebServerRequest *request) = 0;
}; };

7
src/defines.h

@ -69,10 +69,17 @@ union serial_u {
uint8_t b[8]; uint8_t b[8];
}; };
#define MIN_SERIAL_INTERVAL 2 // 5 #define MIN_SERIAL_INTERVAL 2 // 5
#define MIN_SEND_INTERVAL 15 #define MIN_SEND_INTERVAL 15
#define MIN_MQTT_INTERVAL 60 #define MIN_MQTT_INTERVAL 60
#define AHOY_HIST_PATH "/hist"
// reduce resources and increase clarity for statistic output
#define AHOY_MIN_PAC_SUN_HOUR 6
#define AHOY_MAX_PAC_SUN_HOUR 20
// average power interval in minutes
#define AHOY_PAC_INTERVAL 10
#define MQTT_STATUS_NOT_AVAIL_NOT_PROD 0 #define MQTT_STATUS_NOT_AVAIL_NOT_PROD 0
#define MQTT_STATUS_AVAIL_NOT_PROD 1 #define MQTT_STATUS_AVAIL_NOT_PROD 1

130
src/platformio.ini

@ -9,22 +9,23 @@
; https://docs.platformio.org/page/projectconf.html ; https://docs.platformio.org/page/projectconf.html
[platformio] [platformio]
src_dir = . src_dir = c:\AhoiDTU\src
include_dir = . include_dir = c:\AhoiDTU\src
[env] [env]
board = d1_mini
board_build.f_cpu = 80000000L
platform=https://github.com/platformio/platform-espressif8266.git@^4.2.0
framework = arduino framework = arduino
board_build.filesystem = littlefs board_build.filesystem = littlefs
upload_speed = 921600 upload_speed = 921600
monitor_speed = 115200 monitor_speed = 115200
extra_scripts = extra_scripts =
pre:../scripts/auto_firmware_version.py pre:../scripts/auto_firmware_version.py
pre:web/html/convert.py pre:web/html/convert.py
lib_deps = lib_deps =
https://github.com/yubox-node-org/ESPAsyncWebServer https://github.com/yubox-node-org/ESPAsyncWebServer
nrf24/RF24 @ ^1.4.5 nrf24/RF24@1.4.5
paulstoffregen/Time @ ^1.6.1 paulstoffregen/Time @ ^1.6.1
https://github.com/bertmelis/espMqttClient#v1.4.2 https://github.com/bertmelis/espMqttClient#v1.4.2
bblanchon/ArduinoJson @ ^6.21.2 bblanchon/ArduinoJson @ ^6.21.2
@ -32,123 +33,6 @@ lib_deps =
olikraus/U8g2 @ ^2.34.17 olikraus/U8g2 @ ^2.34.17
zinggjm/GxEPD2 @ ^1.5.0 zinggjm/GxEPD2 @ ^1.5.0
[env:esp8266-release] [env:esp8266-release]
platform = espressif8266
board = esp12e
board_build.f_cpu = 80000000L
build_flags = -D RELEASE
;-Wl,-Map,output.map
monitor_filters =
;default ; Remove typical terminal control codes from input
;time ; Add timestamp with milliseconds for each new line
;log2file ; Log data to a file “platformio-device-monitor-*.log” located in the current working directory
esp8266_exception_decoder
[env:esp8266-release-prometheus]
platform = espressif8266
board = esp12e
board_build.f_cpu = 80000000L
build_flags = -D RELEASE -DENABLE_PROMETHEUS_EP
monitor_filters =
;default ; Remove typical terminal control codes from input
;time ; Add timestamp with milliseconds for each new line
;log2file ; Log data to a file “platformio-device-monitor-*.log” located in the current working directory
esp8266_exception_decoder
[env:esp8266-debug]
platform = espressif8266
board = esp12e
board_build.f_cpu = 80000000L
build_flags = -DDEBUG_LEVEL=DBG_DEBUG -DDEBUG_ESP_CORE -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_OOM -DDEBUG_ESP_PORT=Serial -DPIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48
build_type = debug
monitor_filters =
;default ; Remove typical terminal control codes from input
time ; Add timestamp with milliseconds for each new line
log2file ; Log data to a file “platformio-device-monitor-*.log” located in the current working directory
[env:esp8285-release]
platform = espressif8266
board = esp8285
board_build.ldscript = eagle.flash.1m64.ld
board_build.f_cpu = 80000000L
build_flags = -D RELEASE
monitor_filters =
;default ; Remove typical terminal control codes from input
time ; Add timestamp with milliseconds for each new line
;log2file ; Log data to a file “platformio-device-monitor-*.log” located in the current working directory
[env:esp8285-debug]
platform = espressif8266
board = esp8285
board_build.ldscript = eagle.flash.1m64.ld
board_build.f_cpu = 80000000L
build_flags = -DDEBUG_LEVEL=DBG_DEBUG
-DDEBUG_ESP_CORE
-DDEBUG_ESP_WIFI
-DDEBUG_ESP_HTTP_CLIENT
-DDEBUG_ESP_HTTP_SERVER
-DDEBUG_ESP_OOM
-DDEBUG_ESP_PORT=Serial
build_type = debug
monitor_filters =
;default ; Remove typical terminal control codes from input
time ; Add timestamp with milliseconds for each new line
log2file ; Log data to a file “platformio-device-monitor-*.log” located in the current working directory
[env:esp32-wroom32-release]
platform = espressif32@>=6.1.0
board = lolin_d32
build_flags = -D RELEASE -std=gnu++14
build_unflags = -std=gnu++11
monitor_filters =
;default ; Remove typical terminal control codes from input
;time ; Add timestamp with milliseconds for each new line
;log2file ; Log data to a file “platformio-device-monitor-*.log” located in the current working directory
esp32_exception_decoder
[env:esp32-wroom32-release-prometheus]
platform = espressif32@>=6.1.0
board = lolin_d32
build_flags = -D RELEASE build_flags = -D RELEASE
-std=gnu++14 monitor_filters = esp8266_exception_decoder
-DENABLE_PROMETHEUS_EP
build_unflags = -std=gnu++11
monitor_filters =
;default ; Remove typical terminal control codes from input
;time ; Add timestamp with milliseconds for each new line
;log2file ; Log data to a file “platformio-device-monitor-*.log” located in the current working directory
esp32_exception_decoder
[env:esp32-wroom32-debug]
platform = espressif32@>=6.1.0
board = lolin_d32
build_flags = -DDEBUG_LEVEL=DBG_DEBUG
-DDEBUG_ESP_CORE
-DDEBUG_ESP_WIFI
-DDEBUG_ESP_HTTP_CLIENT
-DDEBUG_ESP_HTTP_SERVER
-DDEBUG_ESP_OOM
-DDEBUG_ESP_PORT=Serial
-std=gnu++14
build_unflags = -std=gnu++11
build_type = debug
monitor_filters =
;default ; Remove typical terminal control codes from input
time ; Add timestamp with milliseconds for each new line
log2file ; Log data to a file “platformio-device-monitor-*.log” located in the current working directory
[env:opendtufusionv1-release]
platform = espressif32@>=6.1.0
board = esp32-s3-devkitc-1
upload_protocol = esp-builtin
upload_speed = 115200
debug_tool = esp-builtin
debug_speed = 12000
build_flags = -D RELEASE -std=gnu++14
build_unflags = -std=gnu++11
monitor_filters =
;default ; Remove typical terminal control codes from input
time ; Add timestamp with milliseconds for each new line
;log2file ; Log data to a file “platformio-device-monitor-*.log” located in the current working directory

Loading…
Cancel
Save