From b6c320d481eb77b4f4e0407237917d2d897bfd9d Mon Sep 17 00:00:00 2001 From: jstammi Date: Wed, 2 Aug 2023 17:21:03 +0200 Subject: [PATCH] Fix: explicitly disconnect prior connecting to wifi to prevent from invalid association packets exchange #618 --- src/NetworkSettings.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/NetworkSettings.cpp b/src/NetworkSettings.cpp index e09575453..83b56b03e 100644 --- a/src/NetworkSettings.cpp +++ b/src/NetworkSettings.cpp @@ -24,6 +24,8 @@ void NetworkSettingsClass::init() WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN); WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL); + WiFi.disconnect(true, true); + WiFi.onEvent(std::bind(&NetworkSettingsClass::NetworkEvent, this, _1)); setupMode(); } @@ -71,6 +73,7 @@ void NetworkSettingsClass::NetworkEvent(WiFiEvent_t event) MessageOutput.println("WiFi disconnected"); if (_networkMode == network_mode::WiFi) { MessageOutput.println("Try reconnecting"); + WiFi.disconnect(true, true); WiFi.reconnect(); raiseEvent(network_event::NETWORK_DISCONNECTED); }