From 9a34b2dd81ecb0a8b48a5f51fe7926e128c4ebc5 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Sun, 4 Jun 2023 17:24:03 +0200 Subject: [PATCH] force mqtt disconnect on wifi disconnect --- lib/framework/MqttSettingsService.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/framework/MqttSettingsService.cpp b/lib/framework/MqttSettingsService.cpp index 4658250cf..59b5c0f43 100644 --- a/lib/framework/MqttSettingsService.cpp +++ b/lib/framework/MqttSettingsService.cpp @@ -118,7 +118,7 @@ void MqttSettingsService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) { case ARDUINO_EVENT_ETH_DISCONNECTED: if (_state.enabled) { // emsesp::EMSESP::logger().info("Network connection dropped, stopping MQTT client"); - _mqttClient.disconnect(); + _mqttClient.disconnect(true); } break; @@ -129,7 +129,7 @@ void MqttSettingsService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) { bool MqttSettingsService::configureMqtt() { // disconnect if connected - _mqttClient.disconnect(); + _mqttClient.disconnect(true); // only connect if WiFi is connected and MQTT is enabled if (_state.enabled && emsesp::EMSESP::system_.network_connected() && !_state.host.isEmpty()) { // emsesp::EMSESP::logger().info("Configuring MQTT client");