|
1 | 1 | #include <WiFiSettingsService.h>
|
2 | 2 |
|
3 |
| -WiFiSettingsService::WiFiSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) : AdminSettingsService(server, fs, securityManager, WIFI_SETTINGS_SERVICE_PATH, WIFI_SETTINGS_FILE) {} |
| 3 | +WiFiSettingsService::WiFiSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) : AdminSettingsService(server, fs, securityManager, WIFI_SETTINGS_SERVICE_PATH, WIFI_SETTINGS_FILE) { |
| 4 | +#if defined(ESP8266) |
| 5 | + _onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected(std::bind(&WiFiSettingsService::onStationModeDisconnected, this, std::placeholders::_1)); |
| 6 | +#elif defined(ESP_PLATFORM) |
| 7 | + WiFi.onEvent(std::bind(&WiFiSettingsService::onStationModeDisconnected, this, std::placeholders::_1, std::placeholders::_2), WiFiEvent_t::SYSTEM_EVENT_AP_STADISCONNECTED); |
| 8 | +#endif |
| 9 | +} |
4 | 10 |
|
5 | 11 | WiFiSettingsService::~WiFiSettingsService() {}
|
6 | 12 |
|
@@ -56,7 +62,7 @@ void WiFiSettingsService::onConfigUpdated() {
|
56 | 62 | }
|
57 | 63 |
|
58 | 64 | void WiFiSettingsService::reconfigureWiFiConnection() {
|
59 |
| - // disconnect and de-configure wifi and software access point |
| 65 | + // disconnect and de-configure wifi |
60 | 66 | WiFi.disconnect(true);
|
61 | 67 |
|
62 | 68 | // reset last connection attempt to force loop to reconnect immediately
|
@@ -106,8 +112,16 @@ void WiFiSettingsService::manageSTA() {
|
106 | 112 | }
|
107 | 113 | // attempt to connect to the network
|
108 | 114 | WiFi.begin(_ssid.c_str(), _password.c_str());
|
109 |
| - } else { |
110 |
| - Serial.println("Retrying WiFi connection."); |
111 |
| - WiFi.reconnect(); |
112 |
| - } |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +#if defined(ESP8266) |
| 119 | +void WiFiSettingsService::onStationModeDisconnected(const WiFiEventStationModeDisconnected& event) { |
| 120 | + WiFi.disconnect(true); |
| 121 | +} |
| 122 | +#elif defined(ESP_PLATFORM) |
| 123 | +void WiFiSettingsService::onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info) { |
| 124 | + WiFi.disconnect(true); |
113 | 125 | }
|
| 126 | +#endif |
| 127 | + |
0 commit comments