Fix: explicitly disconnect prior connecting to wifi

to prevent from invalid association packets exchange
#618

(cherry picked from commit b6c320d481eb77b4f4e0407237917d2d897bfd9d)
This commit is contained in:
jstammi 2023-08-02 17:21:03 +02:00
parent e541a885f5
commit 1eab3ae773

View File

@ -27,6 +27,8 @@ void NetworkSettingsClass::init(Scheduler& scheduler)
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();
@ -77,6 +79,7 @@ void NetworkSettingsClass::NetworkEvent(const 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);
}