@@ -18,6 +18,8 @@ WiFiSettingsService::WiFiSettingsService(AsyncWebServer* server, FS* fs, Securit
18
18
WiFi.onEvent (
19
19
std::bind (&WiFiSettingsService::onStationModeDisconnected, this , std::placeholders::_1, std::placeholders::_2),
20
20
WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
21
+ WiFi.onEvent (std::bind (&WiFiSettingsService::onStationModeStop, this , std::placeholders::_1, std::placeholders::_2),
22
+ WiFiEvent_t::SYSTEM_EVENT_STA_STOP);
21
23
#elif defined(ESP8266)
22
24
_onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected (
23
25
std::bind (&WiFiSettingsService::onStationModeDisconnected, this , std::placeholders::_1));
@@ -54,7 +56,8 @@ void WiFiSettingsService::readFromJsonObject(JsonObject& root) {
54
56
// Turning off static ip config if we don't meet the minimum requirements
55
57
// of ipAddress, gateway and subnet. This may change to static ip only
56
58
// as sensible defaults can be assumed for gateway and subnet
57
- if (_settings.staticIPConfig && (_settings.localIP == INADDR_NONE || _settings.gatewayIP == INADDR_NONE || _settings.subnetMask == INADDR_NONE)) {
59
+ if (_settings.staticIPConfig &&
60
+ (_settings.localIP == INADDR_NONE || _settings.gatewayIP == INADDR_NONE || _settings.subnetMask == INADDR_NONE)) {
58
61
_settings.staticIPConfig = false ;
59
62
}
60
63
}
@@ -79,11 +82,17 @@ void WiFiSettingsService::onConfigUpdated() {
79
82
}
80
83
81
84
void WiFiSettingsService::reconfigureWiFiConnection () {
82
- // disconnect and de-configure wifi
83
- WiFi.disconnect (true );
84
-
85
85
// reset last connection attempt to force loop to reconnect immediately
86
86
_lastConnectionAttempt = 0 ;
87
+
88
+ // disconnect and de-configure wifi
89
+ #ifdef ESP32
90
+ if (WiFi.disconnect (true )) {
91
+ _stopping = true ;
92
+ }
93
+ #elif defined(ESP8266)
94
+ WiFi.disconnect (true );
95
+ #endif
87
96
}
88
97
89
98
void WiFiSettingsService::readIP (JsonObject& root, String key, IPAddress& _ip) {
@@ -136,6 +145,12 @@ void WiFiSettingsService::manageSTA() {
136
145
void WiFiSettingsService::onStationModeDisconnected (WiFiEvent_t event, WiFiEventInfo_t info) {
137
146
WiFi.disconnect (true );
138
147
}
148
+ void WiFiSettingsService::onStationModeStop (WiFiEvent_t event, WiFiEventInfo_t info) {
149
+ if (_stopping) {
150
+ _lastConnectionAttempt = 0 ;
151
+ _stopping = false ;
152
+ }
153
+ }
139
154
#elif defined(ESP8266)
140
155
void WiFiSettingsService::onStationModeDisconnected (const WiFiEventStationModeDisconnected& event) {
141
156
WiFi.disconnect (true );
0 commit comments