Skip to content

Commit

Permalink
force mqtt disconnect on wifi disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed Jun 4, 2023
1 parent 2c132a8 commit 9a34b2d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/framework/MqttSettingsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");
Expand Down

0 comments on commit 9a34b2d

Please sign in to comment.