Browse Source

reduce MQTT retry interval from maximum speed to one second

fixed homeassistant autodiscovery #565
pull/635/head
lumapu 2 years ago
parent
commit
7ceaa7944f
  1. 4
      src/CHANGES.md
  2. 2
      src/defines.h
  3. 5
      src/plugins/MonochromeDisplay/MonochromeDisplay.h
  4. 41
      src/publisher/pubMqtt.h

4
src/CHANGES.md

@ -2,6 +2,10 @@
(starting from release version `0.5.66`) (starting from release version `0.5.66`)
## 0.5.76
* reduce MQTT retry interval from maximum speed to one second
* fixed homeassistant autodiscovery #565
## 0.5.75 ## 0.5.75
* fix wakeup issue, once wifi was lost during night the communication didn't start in the morning * fix wakeup issue, once wifi was lost during night the communication didn't start in the morning
* reenabled FlashStringHelper because of lacking RAM * reenabled FlashStringHelper because of lacking RAM

2
src/defines.h

@ -13,7 +13,7 @@
//------------------------------------- //-------------------------------------
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 5 #define VERSION_MINOR 5
#define VERSION_PATCH 75 #define VERSION_PATCH 76
//------------------------------------- //-------------------------------------
typedef struct { typedef struct {

5
src/plugins/MonochromeDisplay/MonochromeDisplay.h

@ -43,8 +43,6 @@ static TimeChangeRule CET = {"CET ", Last, Sun, Oct, 3, 60}; // Central Eu
template<class HMSYSTEM> template<class HMSYSTEM>
class MonochromeDisplay { class MonochromeDisplay {
public: public:
uint8_t dispContrast = 60;
MonochromeDisplay() : mCE(CEST, CET) {} MonochromeDisplay() : mCE(CEST, CET) {}
void setup(display_t *cfg, HMSYSTEM *sys, uint32_t *utcTs, uint8_t disp_reset, const char *version) { void setup(display_t *cfg, HMSYSTEM *sys, uint32_t *utcTs, uint8_t disp_reset, const char *version) {
@ -75,6 +73,7 @@ class MonochromeDisplay {
mDisplay->clearBuffer(); mDisplay->clearBuffer();
mDisplay->setContrast(mCfg->contrast); mDisplay->setContrast(mCfg->contrast);
printText("Ahoy!", 0, 35); printText("Ahoy!", 0, 35);
printText("ahoydtu.de", 2, 20);
printText(version, 3, 46); printText(version, 3, 46);
mDisplay->sendBuffer(); mDisplay->sendBuffer();
} }
@ -193,7 +192,7 @@ class MonochromeDisplay {
void printText(const char* text, uint8_t line, uint8_t dispX = 5) { void printText(const char* text, uint8_t line, uint8_t dispX = 5) {
if(!mIsLarge) if(!mIsLarge)
dispX = 5; dispX = (line == 0) ? 10 : 5;
setFont(line); setFont(line);
if(mCfg->pxShift) if(mCfg->pxShift)
dispX += (_mExtra % 7); // add pixel movement dispX += (_mExtra % 7); // add pixel movement

41
src/publisher/pubMqtt.h

@ -46,6 +46,7 @@ class PubMqtt {
mSys = sys; mSys = sys;
mUtcTimestamp = utcTs; mUtcTimestamp = utcTs;
mIntervalTimeout = 1; mIntervalTimeout = 1;
mReconnectRequest = false;
snprintf(mLwtTopic, MQTT_TOPIC_LEN + 5, "%s/mqtt", mCfgMqtt->topic); snprintf(mLwtTopic, MQTT_TOPIC_LEN + 5, "%s/mqtt", mCfgMqtt->topic);
@ -66,6 +67,7 @@ class PubMqtt {
} }
void connect() { void connect() {
mReconnectRequest = false;
if(!mClient.connected()) if(!mClient.connected())
mClient.connect(); mClient.connect();
} }
@ -80,7 +82,10 @@ class PubMqtt {
sendIvData(); sendIvData();
} }
} }
if(mReconnectRequest) {
connect();
return;
}
} }
void tickerMinute() { void tickerMinute() {
@ -147,12 +152,21 @@ class PubMqtt {
if(!mClient.connected()) if(!mClient.connected())
return; return;
if(addTopic) { String topic = "";
String topic = String(mCfgMqtt->topic) + "/" + String(subTopic); if(addTopic)
mClient.publish(topic.c_str(), QOS_0, retained, payload); topic = String(mCfgMqtt->topic) + "/";
} topic += String(subTopic);
else
mClient.publish(subTopic, QOS_0, retained, payload); do {
if(0 != mClient.publish(topic.c_str(), QOS_0, retained, payload))
break;
if(!mClient.connected())
break;
mClient.loop();
yield();
} while(1);
mTxCnt++; mTxCnt++;
} }
@ -181,7 +195,7 @@ class PubMqtt {
void sendDiscoveryConfig(void) { void sendDiscoveryConfig(void) {
DPRINTLN(DBG_VERBOSE, F("sendMqttDiscoveryConfig")); DPRINTLN(DBG_VERBOSE, F("sendMqttDiscoveryConfig"));
char topic[64], buffer[512], name[32], uniq_id[32]; char topic[64], name[32], uniq_id[32];
DynamicJsonDocument doc(512); DynamicJsonDocument doc(512);
for (uint8_t id = 0; id < mSys->getNumInverters(); id++) { for (uint8_t id = 0; id < mSys->getNumInverters(); id++) {
Inverter<> *iv = mSys->getInverterByPos(id); Inverter<> *iv = mSys->getInverterByPos(id);
@ -221,8 +235,12 @@ class PubMqtt {
doc[F("stat_cla")] = String(stateCls); doc[F("stat_cla")] = String(stateCls);
snprintf(topic, 64, "%s/sensor/%s/ch%d_%s/config", MQTT_DISCOVERY_PREFIX, iv->config->name, rec->assign[i].ch, iv->getFieldName(i, rec)); snprintf(topic, 64, "%s/sensor/%s/ch%d_%s/config", MQTT_DISCOVERY_PREFIX, iv->config->name, rec->assign[i].ch, iv->getFieldName(i, rec));
serializeJson(doc, buffer); size_t size = measureJson(doc) + 1;
publish(topic, buffer, true, false); char *buf = new char[size];
memset(buf, 0, size);
serializeJson(doc, buf, size);
publish(topic, buf, true, false);
delete[] buf;
} }
yield(); yield();
@ -258,7 +276,7 @@ class PubMqtt {
switch (reason) { switch (reason) {
case espMqttClientTypes::DisconnectReason::TCP_DISCONNECTED: case espMqttClientTypes::DisconnectReason::TCP_DISCONNECTED:
DBGPRINTLN(F("TCP disconnect")); DBGPRINTLN(F("TCP disconnect"));
connect(); mReconnectRequest = true;
break; break;
case espMqttClientTypes::DisconnectReason::MQTT_UNACCEPTABLE_PROTOCOL_VERSION: case espMqttClientTypes::DisconnectReason::MQTT_UNACCEPTABLE_PROTOCOL_VERSION:
DBGPRINTLN(F("wrong protocol version")); DBGPRINTLN(F("wrong protocol version"));
@ -561,6 +579,7 @@ class PubMqtt {
std::queue<uint8_t> mSendList; std::queue<uint8_t> mSendList;
subscriptionCb mSubscriptionCb; subscriptionCb mSubscriptionCb;
bool mIvAvail; // shows if at least one inverter is available bool mIvAvail; // shows if at least one inverter is available
bool mReconnectRequest;
uint8_t mLastIvState[MAX_NUM_INVERTERS]; uint8_t mLastIvState[MAX_NUM_INVERTERS];
uint16_t mIntervalTimeout; uint16_t mIntervalTimeout;

Loading…
Cancel
Save