mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-10 07:26:38 +02:00
MQTT reconnect delay, fixed ESP32 build
This commit is contained in:
parent
c62996c139
commit
079ba896d1
3 changed files with 13 additions and 10 deletions
|
@ -104,6 +104,7 @@ typedef enum { // ToDo: to be verified by field tests
|
||||||
#define MQTT_PORT_LEN 2 // uint16_t
|
#define MQTT_PORT_LEN 2 // uint16_t
|
||||||
#define MQTT_DISCOVERY_PREFIX "homeassistant"
|
#define MQTT_DISCOVERY_PREFIX "homeassistant"
|
||||||
#define MQTT_MAX_PACKET_SIZE 384
|
#define MQTT_MAX_PACKET_SIZE 384
|
||||||
|
#define MQTT_RECONNECT_DELAY 5000
|
||||||
|
|
||||||
#define SER_ENABLE_LEN 1 // uint8_t
|
#define SER_ENABLE_LEN 1 // uint8_t
|
||||||
#define SER_DEBUG_LEN 1 // uint8_t
|
#define SER_DEBUG_LEN 1 // uint8_t
|
||||||
|
|
|
@ -85,7 +85,8 @@ class mqtt {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
boolean resub = false;
|
boolean resub = false;
|
||||||
if(!mClient->connected()) {
|
if(!mClient->connected() && (millis() - lastReconnect) > MQTT_RECONNECT_DELAY ) {
|
||||||
|
lastReconnect = millis();
|
||||||
if(strlen(mDevName) > 0) {
|
if(strlen(mDevName) > 0) {
|
||||||
// der Server und der Port müssen neu gesetzt werden,
|
// der Server und der Port müssen neu gesetzt werden,
|
||||||
// da ein MQTT_CONNECTION_LOST -3 die Werte zerstört hat.
|
// da ein MQTT_CONNECTION_LOST -3 die Werte zerstört hat.
|
||||||
|
@ -95,7 +96,6 @@ class mqtt {
|
||||||
resub = mClient->connect(mDevName, mCfg->user, mCfg->pwd);
|
resub = mClient->connect(mDevName, mCfg->user, mCfg->pwd);
|
||||||
else
|
else
|
||||||
resub = mClient->connect(mDevName);
|
resub = mClient->connect(mDevName);
|
||||||
}
|
|
||||||
// ein Subscribe ist nur nach einem connect notwendig
|
// ein Subscribe ist nur nach einem connect notwendig
|
||||||
if(resub) {
|
if(resub) {
|
||||||
char topic[MQTT_TOPIC_LEN + 13 ]; // "/devcontrol/#" --> + 6 byte
|
char topic[MQTT_TOPIC_LEN + 13 ]; // "/devcontrol/#" --> + 6 byte
|
||||||
|
@ -106,6 +106,7 @@ class mqtt {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
WiFiClient mEspClient;
|
WiFiClient mEspClient;
|
||||||
PubSubClient *mClient;
|
PubSubClient *mClient;
|
||||||
|
@ -113,6 +114,7 @@ class mqtt {
|
||||||
bool mAddressSet;
|
bool mAddressSet;
|
||||||
mqttConfig_t *mCfg;
|
mqttConfig_t *mCfg;
|
||||||
char mDevName[DEVNAME_LEN];
|
char mDevName[DEVNAME_LEN];
|
||||||
|
unsigned long lastReconnect = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*__MQTT_H_*/
|
#endif /*__MQTT_H_*/
|
||||||
|
|
|
@ -453,7 +453,7 @@ void web::showWebApi(void)
|
||||||
if (cmd == AlarmData){
|
if (cmd == AlarmData){
|
||||||
iv->alarmMesIndex = response["payload"];
|
iv->alarmMesIndex = response["payload"];
|
||||||
}
|
}
|
||||||
DPRINTLN(DBG_INFO, F("Will make tx-request 0x15 with subcmd ") + String(cmd) + F(" and payload ") + String(response["payload"]));
|
DPRINTLN(DBG_INFO, F("Will make tx-request 0x15 with subcmd ") + String(cmd) + F(" and payload ") + String((uint16_t) response["payload"]));
|
||||||
// process payload from web request corresponding to the cmd
|
// process payload from web request corresponding to the cmd
|
||||||
iv->enqueCommand<InfoCommand>(cmd);
|
iv->enqueCommand<InfoCommand>(cmd);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue