merged SH1106 1.3" Display, thx @dAjaY85

added SH1106 to automatic build
added IP address to MQTT (version, device and IP are retained and only transmitted once after boot) #556
added `set_power_limit` acknowledge MQTT publish #553
changed: version, device name are only published via MQTT once after boot
added `Login` to menu if admin password is set #554
added `development` to second changelog link in `index.html` #543
added interval for MQTT (as option). With this settings MQTT live data is published in a fixed timing (only if inverter is available) #542, #523
added MQTT `comm_disabled` #529
This commit is contained in:
lumapu 2023-01-07 01:15:25 +01:00
parent 2de7f25981
commit 712b5af9b9
15 changed files with 107 additions and 31 deletions

View file

@ -41,11 +41,13 @@ class PubMqtt {
~PubMqtt() { }
void setup(cfgMqtt_t *cfg_mqtt, const char *devName, const char *version, HMSYSTEM *sys, uint32_t *utcTs) {
mCfgMqtt = cfg_mqtt;
mDevName = devName;
mVersion = version;
mSys = sys;
mUtcTimestamp = utcTs;
mCfgMqtt = cfg_mqtt;
mDevName = devName;
mVersion = version;
mSys = sys;
mUtcTimestamp = utcTs;
mExeOnce = true;
mIntervalTimeout = 1;
snprintf(mLwtTopic, MQTT_TOPIC_LEN + 5, "%s/mqtt", mCfgMqtt->topic);
@ -73,7 +75,16 @@ class PubMqtt {
}
void tickerSecond() {
sendIvData();
if(0 == mCfgMqtt->interval) // no fixed interval, publish once new data were received (from inverter)
sendIvData();
else { // send mqtt data in a fixed interval
if(--mIntervalTimeout == 0) {
mIntervalTimeout = mCfgMqtt->interval;
mSendList.push(RealTimeRunData_Debug);
sendIvData();
}
}
}
void tickerMinute() {
@ -98,9 +109,16 @@ class PubMqtt {
publish("dis_night_comm", ((disNightCom) ? "true" : "false"), true);
}
void tickerComm(bool disabled) {
publish("comm_disabled", ((disabled) ? "true" : "false"), true);
publish("comm_dis_ts", String(*mUtcTimestamp).c_str(), true);
}
void payloadEventListener(uint8_t cmd) {
if(mClient.connected()) // prevent overflow if MQTT broker is not reachable but set
mSendList.push(cmd);
if(mClient.connected()) { // prevent overflow if MQTT broker is not reachable but set
if((0 == mCfgMqtt->interval) || (RealTimeRunData_Debug != cmd)) // no interval or no live data
mSendList.push(cmd);
}
}
void publish(const char *subTopic, const char *payload, bool retained = false, bool addTopic = true) {
@ -188,6 +206,15 @@ class PubMqtt {
}
}
void setPowerLimitAck(Inverter<> *iv) {
if (NULL != iv) {
char topic[7 + MQTT_TOPIC_LEN];
snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/ack_pwr_limit", iv->config->name);
publish(topic, "true", true);
}
}
private:
#if defined(ESP8266)
void onWifiConnect(const WiFiEventStationModeGotIP& event) {
@ -223,8 +250,12 @@ class PubMqtt {
DPRINTLN(DBG_INFO, F("MQTT connected"));
mEnReconnect = true;
publish("version", mVersion, true);
publish("device", mDevName, true);
if(mExeOnce) {
publish("version", mVersion, true);
publish("device", mDevName, true);
publish("ip_addr", WiFi.localIP().toString().c_str(), true);
mExeOnce = false;
}
tickerMinute();
publish(mLwtTopic, mLwtOnline, true, false);
@ -494,6 +525,8 @@ class PubMqtt {
subscriptionCb mSubscriptionCb;
bool mIvAvail; // shows if at least one inverter is available
uint8_t mLastIvState[MAX_NUM_INVERTERS];
bool mExeOnce;
uint16_t mIntervalTimeout;
// last will topic and payload must be available trough lifetime of 'espMqttClient'
char mLwtTopic[MQTT_TOPIC_LEN+5];