Changed MQTT Wifi connection timeout

Changed MQTT Wifi connection timeout from 5000 to 200 mSec (#9886)
This commit is contained in:
Theo Arends 2020-11-17 16:44:00 +01:00
parent cdd89e4f43
commit 17c94a2b62
3 changed files with 13 additions and 4 deletions

View File

@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
### Changed ### Changed
- Shelly Dimmer fw upgrade using WebGUI Firmware Upgrade and file from folder `tools/fw_shd_stm32/` - Shelly Dimmer fw upgrade using WebGUI Firmware Upgrade and file from folder `tools/fw_shd_stm32/`
- MQTT Wifi connection timeout from 5000 to 200 mSec (#9886)
### Fixed ### Fixed
- KNX ESP32 UDP mulicastpackage (#9811) - KNX ESP32 UDP mulicastpackage (#9811)

View File

@ -77,6 +77,7 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota
- Core library from v2.7.4.5 to v2.7.4.7 - Core library from v2.7.4.5 to v2.7.4.7
- Platformio compiler option `no target align` enabled (#9749) - Platformio compiler option `no target align` enabled (#9749)
- Sonoff L1 color up scaling and color margin detection (#9545) - Sonoff L1 color up scaling and color margin detection (#9545)
- MQTT Wifi connection timeout from 5000 to 200 mSec (#9886)
### Fixed ### Fixed
- NTP fallback server functionality (#9739) - NTP fallback server functionality (#9739)

View File

@ -54,6 +54,7 @@ void (* const MqttCommand[])(void) PROGMEM = {
struct MQTT { struct MQTT {
uint16_t connect_count = 0; // MQTT re-connect count uint16_t connect_count = 0; // MQTT re-connect count
uint16_t retry_counter = 1; // MQTT connection retry counter uint16_t retry_counter = 1; // MQTT connection retry counter
uint16_t retry_counter_delay = 0; // MQTT retry counter multiplier
uint8_t initial_connection_state = 2; // MQTT connection messages state uint8_t initial_connection_state = 2; // MQTT connection messages state
bool connected = false; // MQTT virtual connection status bool connected = false; // MQTT virtual connection status
bool allowed = false; // MQTT enabled and parameters valid bool allowed = false; // MQTT enabled and parameters valid
@ -480,7 +481,11 @@ uint16_t MqttConnectCount(void)
void MqttDisconnected(int state) void MqttDisconnected(int state)
{ {
Mqtt.connected = false; Mqtt.connected = false;
Mqtt.retry_counter = Settings.mqtt_retry;
if ((Settings.mqtt_retry * Mqtt.retry_counter_delay) < 120) {
Mqtt.retry_counter_delay++;
}
Mqtt.retry_counter = Settings.mqtt_retry * Mqtt.retry_counter_delay;
MqttClient.disconnect(); MqttClient.disconnect();
@ -496,6 +501,7 @@ void MqttConnected(void)
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_MQTT D_CONNECTED)); AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_MQTT D_CONNECTED));
Mqtt.connected = true; Mqtt.connected = true;
Mqtt.retry_counter = 0; Mqtt.retry_counter = 0;
Mqtt.retry_counter_delay = 0;
Mqtt.connect_count++; Mqtt.connect_count++;
GetTopic_P(stopic, TELE, TasmotaGlobal.mqtt_topic, S_LWT); GetTopic_P(stopic, TELE, TasmotaGlobal.mqtt_topic, S_LWT);
@ -602,7 +608,7 @@ void MqttReconnect(void)
#endif // USE_EMULATION #endif // USE_EMULATION
Mqtt.connected = false; Mqtt.connected = false;
Mqtt.retry_counter = Settings.mqtt_retry; Mqtt.retry_counter = Settings.mqtt_retry * Mqtt.retry_counter_delay;
TasmotaGlobal.global_state.mqtt_down = 1; TasmotaGlobal.global_state.mqtt_down = 1;
#ifdef FIRMWARE_MINIMAL #ifdef FIRMWARE_MINIMAL
@ -629,15 +635,16 @@ void MqttReconnect(void)
Response_P(S_LWT_OFFLINE); Response_P(S_LWT_OFFLINE);
if (MqttClient.connected()) { MqttClient.disconnect(); } if (MqttClient.connected()) { MqttClient.disconnect(); }
EspClient.setTimeout(200);
#ifdef USE_MQTT_TLS #ifdef USE_MQTT_TLS
if (Mqtt.mqtt_tls) { if (Mqtt.mqtt_tls) {
tlsClient->stop(); tlsClient->stop();
} else { } else {
EspClient = WiFiClient(); // Wifi Client reconnect issue 4497 (https://github.com/esp8266/Arduino/issues/4497) // EspClient = WiFiClient(); // Wifi Client reconnect issue 4497 (https://github.com/esp8266/Arduino/issues/4497)
MqttClient.setClient(EspClient); MqttClient.setClient(EspClient);
} }
#else #else
EspClient = WiFiClient(); // Wifi Client reconnect issue 4497 (https://github.com/esp8266/Arduino/issues/4497) // EspClient = WiFiClient(); // Wifi Client reconnect issue 4497 (https://github.com/esp8266/Arduino/issues/4497)
MqttClient.setClient(EspClient); MqttClient.setClient(EspClient);
#endif #endif