Add some MQTT housekeeping which might solve issue (#5755)

Add some MQTT housekeeping which might solve issue (#5755)
This commit is contained in:
Theo Arends 2019-06-07 18:03:34 +02:00
parent 8626304165
commit a7dc6b71ae
3 changed files with 10 additions and 1 deletions

View File

@ -2,6 +2,7 @@
* 6.5.0.15 20190606
* Change pubsubclient MQTT_KEEPALIVE from 10 to 30 seconds in preparation of AWS IoT support
* Add support for AWS IoT with TLS 1.2 on core 2.5.2. Full doc here: https://github.com/arendst/Sonoff-Tasmota/wiki/AWS-IoT
* Add some MQTT housekeeping which might solve issue (#5755)
*
* 6.5.0.14 20190602
* Change webserver HTML input, button, textarea, and select name based on id

View File

@ -453,6 +453,9 @@ void KNX_CB_Action(message_t const &msg, void *arg);
#ifndef MQTT_TIMEOUT
#define MQTT_TIMEOUT 10000 // milli seconds
#endif
#ifndef MQTT_CLEAN_SESSION
#define MQTT_CLEAN_SESSION 1 // 0 = No clean session, 1 = Clean session (default)
#endif
#ifndef MESSZ
//#define MESSZ 405 // Max number of characters in JSON message string (6 x DS18x20 sensors)

View File

@ -345,6 +345,8 @@ void MqttDisconnected(int state)
mqtt_connected = false;
mqtt_retry_counter = Settings.mqtt_retry;
MqttClient.disconnect();
#ifdef USE_MQTT_AWS_IOT
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_MQTT D_CONNECT_FAILED_TO " %s:%d, rc %d. " D_RETRY_IN " %d " D_UNIT_SECOND), AWS_endpoint, Settings.mqtt_port, state, mqtt_retry_counter);
#else
@ -508,12 +510,15 @@ void MqttReconnect(void)
GetTopic_P(stopic, TELE, mqtt_topic, S_LWT);
Response_P(S_OFFLINE);
if (MqttClient.connected()) { MqttClient.disconnect(); }
#ifdef USE_MQTT_TLS
EspClient = WiFiClientSecure(); // Wifi Secure Client reconnect issue 4497 (https://github.com/esp8266/Arduino/issues/4497)
MqttClient.setClient(EspClient);
#elif defined(USE_MQTT_AWS_IOT)
awsClient->stop();
#else
EspClient = WiFiClient(); // Wifi Client reconnect issue 4497 (https://github.com/esp8266/Arduino/issues/4497)
MqttClient.setClient(EspClient);
#endif
if (2 == mqtt_initial_connection_state) { // Executed once just after power on and wifi is connected
@ -552,7 +557,7 @@ void MqttReconnect(void)
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_MQTT "AWS IoT endpoint: %s"), AWS_endpoint);
if (MqttClient.connect(mqtt_client, mqtt_user, mqtt_pwd, nullptr, 0, false, nullptr)) {
#else
if (MqttClient.connect(mqtt_client, mqtt_user, mqtt_pwd, stopic, 1, true, mqtt_data)) {
if (MqttClient.connect(mqtt_client, mqtt_user, mqtt_pwd, stopic, 1, true, mqtt_data, MQTT_CLEAN_SESSION)) {
#endif
#ifdef USE_MQTT_AWS_IOT
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_MQTT "AWS IoT connected in %d ms"), millis() - time);