Skip to content

Commit

Permalink
0.8.54
Browse files Browse the repository at this point in the history
* added minimal version (without: MqTT, Display, History), WebUI is not changed!
* added simulator (must be activated before compile, standard: off)
* changed communication attempts back to 5
  • Loading branch information
lumapu committed Jan 14, 2024
1 parent ca6ebfe commit 60111d0
Show file tree
Hide file tree
Showing 17 changed files with 420 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/compile_development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ jobs:
- esp8266-prometheus
- esp8285
- esp32-wroom32
- esp32-wroom32-minimal
- esp32-wroom32-prometheus
- esp32-wroom32-ethernet
- esp32-s2-mini
- esp32-c3-mini
- opendtufusion
- opendtufusion-minimal
- opendtufusion-ethernet
steps:
- uses: actions/checkout@v3
Expand Down
5 changes: 5 additions & 0 deletions src/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Development Changes

## 0.8.54 - 2024-01-13
* added minimal version (without: MqTT, Display, History), WebUI is not changed!
* added simulator (must be activated before compile, standard: off)
* changed communication attempts back to 5

## 0.8.53 - 2024-01-12
* fix history graph
* fix MqTT yield day #1331
Expand Down
29 changes: 29 additions & 0 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ void app::setup() {

mCommunication.setup(&mTimestamp, &mConfig->serial.debug, &mConfig->serial.privacyLog, &mConfig->serial.printWholeTrace, &mConfig->inst.gapMs);
mCommunication.addPayloadListener(std::bind(&app::payloadEventListener, this, std::placeholders::_1, std::placeholders::_2));
#if defined(ENABLE_MQTT)
mCommunication.addPowerLimitAckListener([this] (Inverter<> *iv) { mMqtt.setPowerLimitAck(iv); });
#endif
mSys.setup(&mTimestamp, &mConfig->inst, this);
for (uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {
initInverter(i);
Expand All @@ -65,13 +67,15 @@ void app::setup() {

// when WiFi is in client mode, then enable mqtt broker
#if !defined(AP_ONLY)
#if defined(ENABLE_MQTT)
mMqttEnabled = (mConfig->mqtt.broker[0] > 0);
if (mMqttEnabled) {
mMqtt.setup(&mConfig->mqtt, mConfig->sys.deviceName, mVersion, &mSys, &mTimestamp, &mUptime);
mMqtt.setSubscriptionCb(std::bind(&app::mqttSubRxCb, this, std::placeholders::_1));
mCommunication.addAlarmListener([this](Inverter<> *iv) { mMqtt.alarmEvent(iv); });
}
#endif
#endif
setupLed();

mWeb.setup(this, &mSys, mConfig);
Expand All @@ -92,14 +96,23 @@ void app::setup() {
#endif
#endif

#if defined(ENABLE_HISTORY)
mHistory.setup(this, &mSys, mConfig, &mTimestamp);
#endif /*ENABLE_HISTORY*/

mPubSerial.setup(mConfig, &mSys, &mTimestamp);

#if !defined(ETHERNET)
//mImprov.setup(this, mConfig->sys.deviceName, mVersion);
#endif

#if defined(ENABLE_SIMULATOR)
mSimulator.setup(&mSys, &mTimestamp, 0);
mSimulator.addPayloadListener([this](uint8_t cmd, Inverter<> *iv) {
payloadEventListener(cmd, iv);
});
#endif /*ENABLE_SIMULATOR*/

regularTickers();
}

Expand All @@ -115,8 +128,10 @@ void app::loop(void) {
ah::Scheduler::loop();
mCommunication.loop();

#if defined(ENABLE_MQTT)
if (mMqttEnabled && mNetworkConnected)
mMqtt.loop();
#endif
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -152,7 +167,13 @@ void app::regularTickers(void) {
//everySec([this]() { mImprov.tickSerial(); }, "impro");
#endif

#if defined(ENABLE_HISTORY)
everySec(std::bind(&HistoryType::tickerSecond, &mHistory), "hist");
#endif /*ENABLE_HISTORY*/

#if defined(ENABLE_SIMULATOR)
every(std::bind(&SimulatorType::tick, &mSimulator), 5, "sim");
#endif /*ENABLE_SIMULATOR*/
}

#if defined(ETHERNET)
Expand All @@ -168,11 +189,13 @@ void app::onNtpUpdate(bool gotTime) {

//-----------------------------------------------------------------------------
void app::updateNtp(void) {
#if defined(ENABLE_MQTT)
if (mMqttReconnect && mMqttEnabled) {
mMqtt.tickerSecond();
everySec(std::bind(&PubMqttType::tickerSecond, &mMqtt), "mqttS");
everyMin(std::bind(&PubMqttType::tickerMinute, &mMqtt), "mqttM");
}
#endif /*ENABLE_MQTT*/

// only install schedulers once even if NTP wasn't successful in first loop
if (mMqttReconnect) { // @TODO: mMqttReconnect is variable which scope has changed
Expand Down Expand Up @@ -287,15 +310,19 @@ void app::tickIVCommunication(void) {
//-----------------------------------------------------------------------------
void app::tickSun(void) {
// only used and enabled by MQTT (see setup())
#if defined(ENABLE_MQTT)
if (!mMqtt.tickerSun(mSunrise, mSunset, mConfig->sun.offsetSecMorning, mConfig->sun.offsetSecEvening))
once(std::bind(&app::tickSun, this), 1, "mqSun"); // MQTT not connected, retry
#endif
}

//-----------------------------------------------------------------------------
void app::tickSunrise(void) {
// only used and enabled by MQTT (see setup())
#if defined(ENABLE_MQTT)
if (!mMqtt.tickerSun(mSunrise, mSunset, mConfig->sun.offsetSecMorning, mConfig->sun.offsetSecEvening, true))
once(std::bind(&app::tickSun, this), 1, "mqSun"); // MQTT not connected, retry
#endif
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -340,8 +367,10 @@ void app::tickMidnight(void) {
if (mConfig->inst.rstYieldMidNight) {
zeroIvValues(!CHECK_AVAIL, !SKIP_YIELD_DAY);

#if defined(ENABLE_MQTT)
if (mMqttEnabled)
mMqtt.tickerMidnight();
#endif
}
}

Expand Down
61 changes: 54 additions & 7 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@
#if defined(ESP32)
#include "hms/hmsRadio.h"
#endif
#if defined(ENABLE_MQTT)
#include "publisher/pubMqtt.h"
#endif /*ENABLE_MQTT*/
#include "publisher/pubSerial.h"
#include "utils/crc.h"
#include "utils/dbg.h"
#include "utils/scheduler.h"
#include "utils/syslog.h"
#include "web/RestApi.h"
#if defined(ENABLE_HISTORY)
#include "plugins/history.h"
#endif /*ENABLE_HISTORY*/
#include "web/web.h"
#include "hm/Communication.h"
#if defined(ETHERNET)
Expand All @@ -34,6 +38,10 @@
#include "utils/improv.h"
#endif /* defined(ETHERNET) */

#if defined(ENABLE_SIMULATOR)
#include "hm/simulator.h"
#endif /*ENABLE_SIMULATOR*/

#include <RF24.h> // position is relevant since version 1.4.7 of this library


Expand All @@ -46,9 +54,16 @@
typedef HmSystem<MAX_NUM_INVERTERS> HmSystemType;
typedef Web<HmSystemType> WebType;
typedef RestApi<HmSystemType> RestApiType;
#if defined(ENABLE_MQTT)
typedef PubMqtt<HmSystemType> PubMqttType;
#endif /*ENABLE_MQTT*/
typedef PubSerial<HmSystemType> PubSerialType;
#if defined(ENABLE_HISTORY)
typedef HistoryData<HmSystemType> HistoryType;
#endif /*ENABLE_HISTORY*/
#if defined (ENABLE_SIMULATOR)
typedef Simulator<HmSystemType> SimulatorType;
#endif /*ENABLE_SIMULATOR*/

// PLUGINS
#if defined(PLUGIN_DISPLAY)
Expand Down Expand Up @@ -190,19 +205,33 @@ class app : public IApp, public ah::Scheduler {
}

void setMqttDiscoveryFlag() {
#if defined(ENABLE_MQTT)
once(std::bind(&PubMqttType::sendDiscoveryConfig, &mMqtt), 1, "disCf");
#endif
}

bool getMqttIsConnected() {
return mMqtt.isConnected();
#if defined(ENABLE_MQTT)
return mMqtt.isConnected();
#else
return false;
#endif
}

uint32_t getMqttTxCnt() {
return mMqtt.getTxCnt();
#if defined(ENABLE_MQTT)
return mMqtt.getTxCnt();
#else
return 0;
#endif
}

uint32_t getMqttRxCnt() {
return mMqtt.getRxCnt();
#if defined(ENABLE_MQTT)
return mMqtt.getRxCnt();
#else
return 0;
#endif
}

bool getProtection(AsyncWebServerRequest *request) {
Expand Down Expand Up @@ -253,11 +282,19 @@ class app : public IApp, public ah::Scheduler {
}

uint16_t getHistoryValue(uint8_t type, uint16_t i) {
return mHistory.valueAt((HistoryStorageType)type, i);
#if defined(ENABLE_HISTORY)
return mHistory.valueAt((HistoryStorageType)type, i);
#else
return 0;
#endif
}

uint16_t getHistoryMaxDay() {
return mHistory.getMaximumDay();
#if defined(ENABLE_HISTORY)
return mHistory.getMaximumDay();
#else
return 0;
#endif
}

private:
Expand All @@ -269,8 +306,10 @@ class app : public IApp, public ah::Scheduler {

void payloadEventListener(uint8_t cmd, Inverter<> *iv) {
#if !defined(AP_ONLY)
if (mMqttEnabled)
mMqtt.payloadEventListener(cmd, iv);
#if defined(ENABLE_MQTT)
if (mMqttEnabled)
mMqtt.payloadEventListener(cmd, iv);
#endif /*ENABLE_MQTT*/
#endif
#if defined(PLUGIN_DISPLAY)
if(mConfig->plugin.display.type != 0)
Expand Down Expand Up @@ -359,7 +398,9 @@ class app : public IApp, public ah::Scheduler {
bool mNetworkConnected;

// mqtt
#if defined(ENABLE_MQTT)
PubMqttType mMqtt;
#endif /*ENABLE_MQTT*/
bool mMqttReconnect;
bool mMqttEnabled;

Expand All @@ -372,7 +413,13 @@ class app : public IApp, public ah::Scheduler {
DisplayType mDisplay;
DisplayData mDispData;
#endif
#if defined(ENABLE_HISTORY)
HistoryType mHistory;
#endif /*ENABLE_HISTORY*/

#if defined(ENABLE_SIMULATOR)
SimulatorType mSimulator;
#endif /*ENABLE_SIMULATOR*/
};

#endif /*__APP_H__*/
34 changes: 32 additions & 2 deletions src/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,33 @@
// timeout for automatic logoff (20 minutes)
#define LOGOUT_TIMEOUT (20 * 60)


//-------------------------------------
// MODULE SELECTOR - done by platform.ini
//-------------------------------------

// MqTT connection
//#define ENABLE_MQTT

// display plugin
//#define PLUGIN_DISPLAY

// history graph (WebUI)
//#define ENABLE_HISTORY

// inverter simulation
//#define ENABLE_SIMULATOR

// to enable the syslog logging (will disable web-serial)
//#define ENABLE_SYSLOG



//-------------------------------------
// CONFIGURATION - COMPILE TIME
//-------------------------------------

// ethernet

#if defined(ETHERNET)
#define ETH_SPI_HOST SPI2_HOST
#define ETH_SPI_CLOCK_MHZ 25
Expand Down Expand Up @@ -184,7 +205,7 @@
#define INVERTER_OFF_THRES_SEC 15*60

// threshold of minimum power on which the inverter is marked as inactive
#define INACT_PWR_THRESH 3
#define INACT_PWR_THRESH 1

// Timezone
#define TIMEZONE 1
Expand Down Expand Up @@ -222,6 +243,15 @@
// reconnect delay
#define MQTT_RECONNECT_DELAY 5000


// syslog settings
#ifdef ENABLE_SYSLOG
#define SYSLOG_HOST "<hostname-or-ip-address-of-syslog-server>"
#define SYSLOG_APP "ahoy"
#define SYSLOG_FACILITY FAC_USER
#define SYSLOG_PORT 514
#endif

#if __has_include("config_override.h")
#include "config_override.h"
#endif
Expand Down
8 changes: 0 additions & 8 deletions src/config/config_override_example.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,5 @@
// #define ENABLE_PROMETHEUS_EP


// to enable the syslog logging (will disable web-serial)
//#define ENABLE_SYSLOG
#ifdef ENABLE_SYSLOG
#define SYSLOG_HOST "<hostname-or-ip-address-of-syslog-server>"
#define SYSLOG_APP "ahoy"
#define SYSLOG_FACILITY FAC_USER
#define SYSLOG_PORT 514
#endif

#endif /*__CONFIG_OVERRIDE_H__*/
3 changes: 1 addition & 2 deletions src/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//-------------------------------------
#define VERSION_MAJOR 0
#define VERSION_MINOR 8
#define VERSION_PATCH 53
#define VERSION_PATCH 54

//-------------------------------------
typedef struct {
Expand Down Expand Up @@ -94,7 +94,6 @@ enum {MQTT_STATUS_OFFLINE = 0, MQTT_STATUS_PARTIAL, MQTT_STATUS_ONLINE};

#define MQTT_MAX_PACKET_SIZE 384

#define PLUGIN_DISPLAY

typedef struct {
uint32_t rxFail;
Expand Down
7 changes: 4 additions & 3 deletions src/hm/CommQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
#include "hmInverter.h"
#include "../utils/dbg.h"

#define DEFAULT_ATTEMPS 10
#define MORE_ATTEMPS_ALARMDATA 15
#define MORE_ATTEMPS_GRIDONPROFILEPARA 15
// needs a '+1' because the comparison does not send if attempts is equal 0
#define DEFAULT_ATTEMPS 5 + 1
#define MORE_ATTEMPS_ALARMDATA 15 + 1
#define MORE_ATTEMPS_GRIDONPROFILEPARA 15 + 1

template <uint8_t N=100>
class CommQueue {
Expand Down
Loading

0 comments on commit 60111d0

Please sign in to comment.