Skip to content

Commit

Permalink
Changed MQTT Wifi connection timeout
Browse files Browse the repository at this point in the history
Changed MQTT Wifi connection timeout from 5000 to 200 mSec (#9886)
  • Loading branch information
arendst committed Nov 17, 2020
1 parent cdd89e4 commit 17c94a2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.

### Changed
- 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
- KNX ESP32 UDP mulicastpackage (#9811)
Expand Down
1 change: 1 addition & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- Platformio compiler option `no target align` enabled (#9749)
- Sonoff L1 color up scaling and color margin detection (#9545)
- MQTT Wifi connection timeout from 5000 to 200 mSec (#9886)

### Fixed
- NTP fallback server functionality (#9739)
Expand Down
15 changes: 11 additions & 4 deletions tasmota/xdrv_02_mqtt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void (* const MqttCommand[])(void) PROGMEM = {
struct MQTT {
uint16_t connect_count = 0; // MQTT re-connect count
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
bool connected = false; // MQTT virtual connection status
bool allowed = false; // MQTT enabled and parameters valid
Expand Down Expand Up @@ -480,7 +481,11 @@ uint16_t MqttConnectCount(void)
void MqttDisconnected(int state)
{
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();

Expand All @@ -496,6 +501,7 @@ void MqttConnected(void)
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_MQTT D_CONNECTED));
Mqtt.connected = true;
Mqtt.retry_counter = 0;
Mqtt.retry_counter_delay = 0;
Mqtt.connect_count++;

GetTopic_P(stopic, TELE, TasmotaGlobal.mqtt_topic, S_LWT);
Expand Down Expand Up @@ -602,7 +608,7 @@ void MqttReconnect(void)
#endif // USE_EMULATION

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;

#ifdef FIRMWARE_MINIMAL
Expand All @@ -629,15 +635,16 @@ void MqttReconnect(void)
Response_P(S_LWT_OFFLINE);

if (MqttClient.connected()) { MqttClient.disconnect(); }
EspClient.setTimeout(200);
#ifdef USE_MQTT_TLS
if (Mqtt.mqtt_tls) {
tlsClient->stop();
} 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);
}
#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);
#endif

Expand Down

0 comments on commit 17c94a2

Please sign in to comment.