Skip to content

Commit

Permalink
0.8.7
Browse files Browse the repository at this point in the history
* fix ESP8266 inverter settings #1226
* send radio statistics via MqTT #1227
* made night communication inverter depended
* added option to prevent adding values of inverter to total values (MqTT only) #1199
  • Loading branch information
lumapu committed Nov 13, 2023
1 parent a82777b commit 1bc3a0f
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 161 deletions.
6 changes: 6 additions & 0 deletions src/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Development Changes

## 0.8.7 - 2023-11-13
* fix ESP8266 inverter settings #1226
* send radio statistics via MqTT #1227
* made night communication inverter depended
* added option to prevent adding values of inverter to total values (MqTT only) #1199

## 0.8.6 - 2023-11-12
* merged PR #1225
* improved heuristics (prevent update of statitistic during testing)
Expand Down
92 changes: 50 additions & 42 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
//-----------------------------------------------------------------------------

#include <ArduinoJson.h>

#include "app.h"

#include "utils/sun.h"


Expand Down Expand Up @@ -239,43 +237,50 @@ void app::tickCalcSunrise(void) {

//-----------------------------------------------------------------------------
void app::tickIVCommunication(void) {
mIVCommunicationOn = !mConfig->sun.disNightCom; // if sun.disNightCom is false, communication is always on
if (!mIVCommunicationOn) { // inverter communication only during the day
uint32_t nxtTrig;
if (mTimestamp < (mSunrise - mConfig->sun.offsetSec)) { // current time is before communication start, set next trigger to communication start
nxtTrig = mSunrise - mConfig->sun.offsetSec;
} else {
if (mTimestamp >= (mSunset + mConfig->sun.offsetSec)) { // current time is past communication stop, nothing to do. Next update will be done at midnight by tickCalcSunrise
nxtTrig = 0;
} else { // current time lies within communication start/stop time, set next trigger to communication stop
mIVCommunicationOn = true;
nxtTrig = mSunset + mConfig->sun.offsetSec;
bool restartTick = false;
bool zeroValues = false;
uint32_t nxtTrig = 0;

Inverter<> *iv;
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
iv = mSys.getInverterByPos(i);
if(NULL == iv)
continue;

iv->commEnabled = !iv->config->disNightCom; // if sun.disNightCom is false, communication is always on
if (!iv->commEnabled) { // inverter communication only during the day
if (mTimestamp < (mSunrise - mConfig->sun.offsetSec)) { // current time is before communication start, set next trigger to communication start
nxtTrig = mSunrise - mConfig->sun.offsetSec;
} else {
if (mTimestamp >= (mSunset + mConfig->sun.offsetSec)) { // current time is past communication stop, nothing to do. Next update will be done at midnight by tickCalcSunrise
nxtTrig = 0;
} else { // current time lies within communication start/stop time, set next trigger to communication stop
iv->commEnabled = true;
nxtTrig = mSunset + mConfig->sun.offsetSec;
}
}
if (nxtTrig != 0)
restartTick = true;
}
if (nxtTrig != 0)
onceAt(std::bind(&app::tickIVCommunication, this), nxtTrig, "ivCom");

if ((!iv->commEnabled) && (mConfig->inst.rstValsCommStop))
zeroValues = true;
}
tickComm();

if(restartTick) // at least one inverter
onceAt(std::bind(&app::tickIVCommunication, this), nxtTrig, "ivCom");

if (zeroValues) // at least one inverter
once(std::bind(&app::tickZeroValues, this), mConfig->nrf.sendInterval, "tZero");
}

//-----------------------------------------------------------------------------
void app::tickSun(void) {
// 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))
once(std::bind(&app::tickSun, this), 1, "mqSun"); // MQTT not connected, retry
}

//-----------------------------------------------------------------------------
void app::tickComm(void) {
if ((!mIVCommunicationOn) && (mConfig->inst.rstValsCommStop))
once(std::bind(&app::tickZeroValues, this), mConfig->nrf.sendInterval, "tZero");

if (mMqttEnabled) {
if (!mMqtt.tickerComm(!mIVCommunicationOn))
once(std::bind(&app::tickComm, this), 5, "mqCom"); // MQTT not connected, retry after 5s
}
}

//-----------------------------------------------------------------------------
void app::tickZeroValues(void) {
zeroIvValues(!CHECK_AVAIL, SKIP_YIELD_DAY);
Expand Down Expand Up @@ -325,22 +330,24 @@ void app::tickMidnight(void) {

//-----------------------------------------------------------------------------
void app::tickSend(void) {
if(!mIVCommunicationOn) {
DPRINTLN(DBG_WARN, F("Time not set or it is night time, therefore no communication to the inverter!"));
return;
}

for (uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {
Inverter<> *iv = mSys.getInverterByPos(i);
if(NULL != iv) {
if(iv->config->enabled) {
iv->tickSend([this, iv](uint8_t cmd, bool isDevControl) {
if(isDevControl)
mCommunication.addImportant(iv, cmd);
else
mCommunication.add(iv, cmd);
});
if(NULL == iv)
continue;

if(iv->config->enabled) {
if(!iv->commEnabled) {
DPRINT_IVID(DBG_INFO, iv->id);
DBGPRINTLN(F("no communication to the inverter (night time)"));
continue;
}

iv->tickSend([this, iv](uint8_t cmd, bool isDevControl) {
if(isDevControl)
mCommunication.addImportant(iv, cmd);
else
mCommunication.add(iv, cmd);
});
}
}

Expand All @@ -358,6 +365,8 @@ void app:: zeroIvValues(bool checkAvail, bool skipYieldDay) {
continue; // skip to next inverter
if (!iv->config->enabled)
continue; // skip to next inverter
if (iv->commEnabled)
continue; // skip to next inverter

if (checkAvail) {
if (!iv->isAvailable())
Expand Down Expand Up @@ -415,7 +424,6 @@ void app::resetSystem(void) {

mSendLastIvId = 0;
mShowRebootRequest = false;
mIVCommunicationOn = true;
mSavePending = false;
mSaveReboot = false;

Expand Down
1 change: 0 additions & 1 deletion src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ class app : public IApp, public ah::Scheduler {
Communication mCommunication;

bool mShowRebootRequest;
bool mIVCommunicationOn;

#if defined(ETHERNET)
ahoyeth mEth;
Expand Down
26 changes: 17 additions & 9 deletions src/config/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html#flash-layout
* */

#define CONFIG_VERSION 1
#define CONFIG_VERSION 2


#define PROT_MASK_INDEX 0x0001
Expand Down Expand Up @@ -110,7 +110,6 @@ typedef struct {
typedef struct {
float lat;
float lon;
bool disNightCom; // disable night communication
uint16_t offsetSec;
} cfgSun_t;

Expand Down Expand Up @@ -145,6 +144,8 @@ typedef struct {
char chName[6][MAX_NAME_LENGTH];
uint8_t frequency;
uint8_t powerLevel;
bool disNightCom; // disable night communication
bool add2Total; // add values to total values - useful if one inverter is on battery to turn off
} cfgIv_t;

typedef struct {
Expand Down Expand Up @@ -420,7 +421,6 @@ class settings {

mCfg.sun.lat = 0.0;
mCfg.sun.lon = 0.0;
mCfg.sun.disNightCom = false;
mCfg.sun.offsetSec = 0;

mCfg.serial.interval = SERIAL_INTERVAL;
Expand All @@ -442,8 +442,10 @@ class settings {
mCfg.inst.yieldEffiency = 0.955f;

for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {
mCfg.inst.iv[i].powerLevel = 0xff; // impossible high value
mCfg.inst.iv[i].frequency = 0x12; // 863MHz (minimum allowed frequency)
mCfg.inst.iv[i].powerLevel = 0xff; // impossible high value
mCfg.inst.iv[i].frequency = 0x12; // 863MHz (minimum allowed frequency)
mCfg.inst.iv[i].disNightCom = false;
mCfg.inst.iv[i].add2Total = true;
}

mCfg.led.led0 = DEF_LED0;
Expand All @@ -465,11 +467,15 @@ class settings {
}

void loadAddedDefaults() {
if(0 < mCfg.configVersion) {
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {
if(mCfg.configVersion < 1) {
mCfg.inst.iv[i].powerLevel = 0xff; // impossible high value
mCfg.inst.iv[i].frequency = 0x0; // 860MHz (backward compatibility)
}
if(mCfg.configVersion < 2) {
mCfg.inst.iv[i].disNightCom = false;
mCfg.inst.iv[i].add2Total = true;
}
}
}

Expand Down Expand Up @@ -601,12 +607,10 @@ class settings {
if(set) {
obj[F("lat")] = mCfg.sun.lat;
obj[F("lon")] = mCfg.sun.lon;
obj[F("dis")] = mCfg.sun.disNightCom;
obj[F("offs")] = mCfg.sun.offsetSec;
} else {
getVal<float>(obj, F("lat"), &mCfg.sun.lat);
getVal<float>(obj, F("lon"), &mCfg.sun.lon);
getVal<bool>(obj, F("dis"), &mCfg.sun.disNightCom);
getVal<uint16_t>(obj, F("offs"), &mCfg.sun.offsetSec);
}
}
Expand Down Expand Up @@ -734,6 +738,8 @@ class settings {
obj[F("sn")] = cfg->serial.u64;
obj[F("freq")] = cfg->frequency;
obj[F("pa")] = cfg->powerLevel;
obj[F("dis")] = cfg->disNightCom;
obj[F("add")] = cfg->add2Total;
for(uint8_t i = 0; i < 6; i++) {
obj[F("yield")][i] = cfg->yieldCor[i];
obj[F("pwr")][i] = cfg->chMaxPwr[i];
Expand All @@ -745,6 +751,8 @@ class settings {
getVal<uint64_t>(obj, F("sn"), &cfg->serial.u64);
getVal<uint8_t>(obj, F("freq"), &cfg->frequency);
getVal<uint8_t>(obj, F("pa"), &cfg->powerLevel);
getVal<bool>(obj, F("dis"), &cfg->disNightCom);
getVal<bool>(obj, F("add"), &cfg->add2Total);
uint8_t size = 4;
if(obj.containsKey(F("pwr")))
size = obj[F("pwr")].size();
Expand Down
2 changes: 1 addition & 1 deletion 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 5
#define VERSION_PATCH 7

//-------------------------------------
typedef struct {
Expand Down
2 changes: 2 additions & 0 deletions src/hm/hmInverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class Inverter {
int8_t txRfQuality[5]; // heuristics tx quality (check 'Heuristics.h')
uint8_t txRfChId; // RF TX channel id
uint8_t curCmtFreq; // current used CMT frequency, used to check if freq. was changed during runtime
bool commEnabled; // 'pause night communication' sets this field to false

static uint32_t *timestamp; // system timestamp
static cfgInst_t *generalConfig; // general inverter configuration from setup
Expand All @@ -150,6 +151,7 @@ class Inverter {
alarmLastId = 0;
rssi = -127;
radio = NULL;
commEnabled = true;
memset(&radioStatistics, 0, sizeof(statistics_t));
memset(txRfQuality, -6, 5);

Expand Down
13 changes: 11 additions & 2 deletions src/publisher/pubMqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,24 @@ class PubMqtt {
#endif
}

bool tickerSun(uint32_t sunrise, uint32_t sunset, uint32_t offs, bool disNightCom) {
bool tickerSun(uint32_t sunrise, uint32_t sunset, uint32_t offs) {
if (!mClient.connected())
return false;

publish(subtopics[MQTT_SUNRISE], String(sunrise).c_str(), true);
publish(subtopics[MQTT_SUNSET], String(sunset).c_str(), true);
publish(subtopics[MQTT_COMM_START], String(sunrise - offs).c_str(), true);
publish(subtopics[MQTT_COMM_STOP], String(sunset + offs).c_str(), true);
publish(subtopics[MQTT_DIS_NIGHT_COMM], ((disNightCom) ? dict[STR_TRUE] : dict[STR_FALSE]), true);

Inverter<> *iv;
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {
iv = mSys->getInverterByPos(i);
if(NULL == iv)
continue;

snprintf(mSubTopic, 32 + MAX_NAME_LENGTH, "%s/dis_night_comm", iv->config->name);
publish(mSubTopic, ((iv->commEnabled) ? dict[STR_TRUE] : dict[STR_FALSE]), true);
}

return true;
}
Expand Down
2 changes: 0 additions & 2 deletions src/publisher/pubMqttDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ enum {
MQTT_SUNSET,
MQTT_COMM_START,
MQTT_COMM_STOP,
MQTT_DIS_NIGHT_COMM,
MQTT_COMM_DISABLED,
MQTT_COMM_DIS_TS,
MQTT_VERSION,
Expand All @@ -69,7 +68,6 @@ const char* const subtopics[] PROGMEM = {
"sunset",
"comm_start",
"comm_stop",
"dis_night_comm",
"comm_disabled",
"comm_dis_ts",
"version",
Expand Down
Loading

0 comments on commit 1bc3a0f

Please sign in to comment.