mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-13 14:51:21 +10:00
adds esp32 autoreconnector
Using static event cb for now, feel free to improve, this functionality should be fixed in core soon
This commit is contained in:
@@ -116,6 +116,8 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
|
||||
WiFi_enableSTA(true);
|
||||
_usermode = WIFI_STA;
|
||||
|
||||
WiFi_autoReconnect();
|
||||
|
||||
// if already connected, or try stored connect
|
||||
if (WiFi.status() == WL_CONNECTED || connectWifi("", "") == WL_CONNECTED) {
|
||||
//connected
|
||||
@@ -1224,6 +1226,10 @@ void WiFiManager::setCaptivePortalEnable(boolean enabled){
|
||||
_enableCaptivePortal = enabled;
|
||||
}
|
||||
|
||||
void WiFiManager::setWiFiAutoReconnect(boolean enabled){
|
||||
_wifiAutoReconnect = enabled;
|
||||
}
|
||||
|
||||
// HELPERS
|
||||
|
||||
template <typename Generic>
|
||||
@@ -1496,4 +1502,24 @@ bool WiFiManager::WiFi_hasAutoConnect(){
|
||||
DEBUG_WM(ssid);
|
||||
return ssid != "";
|
||||
#endif
|
||||
}
|
||||
|
||||
void WiFiManager::WiFiEvent(WiFiEvent_t event, system_event_info_t info){
|
||||
WiFiManager _WiFiManager;
|
||||
if(event == SYSTEM_EVENT_STA_DISCONNECTED){
|
||||
// Serial.println("Event: SYSTEM_EVENT_STA_DISCONNECTED, reconnecting");
|
||||
_WiFiManager.DEBUG_WM("ESP32 Event: SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); // @todo remove debugging from prod, or change static method
|
||||
WiFi.reconnect();
|
||||
}
|
||||
}
|
||||
|
||||
void WiFiManager::WiFi_autoReconnect(){
|
||||
#ifdef ESP8266
|
||||
WiFi.setAutoReconnect(_wifiAutoReconnect);
|
||||
#elif defined(ESP31B) || defined(ESP32)
|
||||
if(_wifiAutoReconnect){
|
||||
DEBUG_WM("ESP32 autoreconnect handler enabled");
|
||||
WiFi.onEvent(WiFiEvent);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+7
-2
@@ -172,6 +172,8 @@ class WiFiManager
|
||||
void setShowStaticFields(boolean alwaysShow);
|
||||
//if true disable captive portal redirection
|
||||
void setCaptivePortalEnable(boolean enabled);
|
||||
// if true enable autoreconnecting
|
||||
void setWiFiAutoReconnect(boolean enabled);
|
||||
|
||||
private:
|
||||
std::unique_ptr<DNSServer> dnsServer;
|
||||
@@ -221,7 +223,8 @@ class WiFiManager
|
||||
boolean _shouldBreakAfterConfig = false;
|
||||
boolean _tryWPS = false;
|
||||
boolean _configPortalIsBlocking = true;
|
||||
|
||||
boolean _wifiAutoReconnect = false;
|
||||
|
||||
const char* _customHeadElement = "";
|
||||
|
||||
//String getEEPROMString(int start, int len);
|
||||
@@ -254,7 +257,9 @@ class WiFiManager
|
||||
bool WiFi_eraseConfig();
|
||||
uint8_t WiFi_softap_num_stations();
|
||||
bool WiFi_hasAutoConnect();
|
||||
|
||||
void WiFi_autoReconnect();
|
||||
static void WiFiEvent(WiFiEvent_t event, system_event_info_t info);
|
||||
|
||||
void debugSoftAPConfig();
|
||||
|
||||
String getParamOut();
|
||||
|
||||
Reference in New Issue
Block a user