mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-22 10:42:10 +10:00
testing mode and persistent presrvation
You should be able to have sta+softap mode with your own softap, and starting config portal will not overwrite your default softap, but i cannot find a way to reconnect other than rebooting the device
This commit is contained in:
+17
-5
@@ -82,13 +82,17 @@ void WiFiManager::addParameter(WiFiManagerParameter *p) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
WiFiManager::WiFiManager() {
|
WiFiManager::WiFiManager() {
|
||||||
WiFi.persistent(false);
|
_usermode = WiFi.getMode();
|
||||||
|
WiFi.persistent(false); // disable persistent so scannetworks and mode switching is not saved
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
WiFiManager::~WiFiManager() {
|
WiFiManager::~WiFiManager() {
|
||||||
WiFi.persistent(true); // @todo restore original
|
if(_userpersistent) WiFi.persistent(true); // reenable persistent
|
||||||
|
WiFi.mode(_usermode);
|
||||||
|
DEBUG_WM(_usermode);
|
||||||
|
DEBUG_WM(F("unloading"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// AUTOCONNECT
|
// AUTOCONNECT
|
||||||
@@ -121,7 +125,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
|
|||||||
|
|
||||||
// CONFIG PORTAL
|
// CONFIG PORTAL
|
||||||
bool WiFiManager::startAP(){
|
bool WiFiManager::startAP(){
|
||||||
DEBUG_WM(F("Configuring access point with with SSID ... "));
|
DEBUG_WM(F("Configuring access point with with SSID of ... "));
|
||||||
DEBUG_WM(_apName);
|
DEBUG_WM(_apName);
|
||||||
|
|
||||||
// setup optional soft AP static ip config
|
// setup optional soft AP static ip config
|
||||||
@@ -303,7 +307,7 @@ boolean WiFiManager::stopConfigPortal(){
|
|||||||
// turn off AP
|
// turn off AP
|
||||||
DEBUG_WM(F("disconnect configportal"));
|
DEBUG_WM(F("disconnect configportal"));
|
||||||
bool ret = WiFi.softAPdisconnect(false);
|
bool ret = WiFi.softAPdisconnect(false);
|
||||||
if(!ret)DEBUG_WM(F("disconnect configportal error"));
|
if(!ret)DEBUG_WM(F("disconnect configportal - softAPdisconnect failed"));
|
||||||
wifimode(WIFI_STA); // set back to sta, @todo use preservation variable
|
wifimode(WIFI_STA); // set back to sta, @todo use preservation variable
|
||||||
configPortalActive = false;
|
configPortalActive = false;
|
||||||
return ret;
|
return ret;
|
||||||
@@ -422,7 +426,9 @@ String WiFiManager::getConfigPortalSSID() {
|
|||||||
void WiFiManager::resetSettings() {
|
void WiFiManager::resetSettings() {
|
||||||
DEBUG_WM(F("SETTINGS ERASED"));
|
DEBUG_WM(F("SETTINGS ERASED"));
|
||||||
DEBUG_WM(F("THIS MAY CAUSE AP NOT TO START UP PROPERLY. YOU NEED TO COMMENT IT OUT AFTER ERASING THE DATA.")); // @todo WHUT?
|
DEBUG_WM(F("THIS MAY CAUSE AP NOT TO START UP PROPERLY. YOU NEED TO COMMENT IT OUT AFTER ERASING THE DATA.")); // @todo WHUT?
|
||||||
|
WiFi.persistent(true);
|
||||||
WiFi.disconnect(true);
|
WiFi.disconnect(true);
|
||||||
|
WiFi.persistent(false);
|
||||||
//delay(200);
|
//delay(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -858,6 +864,12 @@ void WiFiManager::setConfigPortalBlocking(boolean shoudlBlock) {
|
|||||||
_configPortalIsBlocking = shoudlBlock;
|
_configPortalIsBlocking = shoudlBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//wrapper for ESP wifi.persistent so we can remember it as WIFi._persistent is protected
|
||||||
|
void WiFiManager::setRestorePersistent(boolean persistent) {
|
||||||
|
_userpersistent = persistent;
|
||||||
|
if(!persistent) DEBUG_WM(F("persistent is off"));
|
||||||
|
}
|
||||||
|
|
||||||
// HELPERS
|
// HELPERS
|
||||||
|
|
||||||
template <typename Generic>
|
template <typename Generic>
|
||||||
|
|||||||
+10
-1
@@ -125,11 +125,13 @@ class WiFiManager
|
|||||||
//if this is set, portal will be blocking and wait until save or exit, is false user must manually process to handle config portal
|
//if this is set, portal will be blocking and wait until save or exit, is false user must manually process to handle config portal
|
||||||
void setConfigPortalBlocking(boolean shouldBlock);
|
void setConfigPortalBlocking(boolean shouldBlock);
|
||||||
|
|
||||||
//TODO
|
|
||||||
//if this is set, customise style
|
//if this is set, customise style
|
||||||
void setCustomHeadElement(const char* element);
|
void setCustomHeadElement(const char* element);
|
||||||
//if this is true, remove duplicated Access Points - defaut true
|
//if this is true, remove duplicated Access Points - defaut true
|
||||||
void setRemoveDuplicateAPs(boolean removeDuplicates);
|
void setRemoveDuplicateAPs(boolean removeDuplicates);
|
||||||
|
//wrapper for esp wifi persistent, set esp wifi persistent through wifimanager so we can save status and restore as needed
|
||||||
|
void setRestorePersistent(boolean persistent);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<DNSServer> dnsServer;
|
std::unique_ptr<DNSServer> dnsServer;
|
||||||
@@ -144,6 +146,11 @@ class WiFiManager
|
|||||||
void startWPS();
|
void startWPS();
|
||||||
bool startAP();
|
bool startAP();
|
||||||
|
|
||||||
|
// typedef enum WiFiMode
|
||||||
|
// {
|
||||||
|
// WIFI_OFF = 0, WIFI_STA = 1, WIFI_AP = 2, WIFI_AP_STA = 3
|
||||||
|
// } WiFiMode_t;
|
||||||
|
|
||||||
String _apName = "no-net";
|
String _apName = "no-net";
|
||||||
String _apPassword = "";
|
String _apPassword = "";
|
||||||
String _ssid = "";
|
String _ssid = "";
|
||||||
@@ -151,6 +158,8 @@ class WiFiManager
|
|||||||
unsigned long _configPortalTimeout = 0;
|
unsigned long _configPortalTimeout = 0;
|
||||||
unsigned long _connectTimeout = 0;
|
unsigned long _connectTimeout = 0;
|
||||||
unsigned long _configPortalStart = 0;
|
unsigned long _configPortalStart = 0;
|
||||||
|
boolean _userpersistent = true;
|
||||||
|
WiFiMode_t _usermode = WIFI_OFF;
|
||||||
|
|
||||||
IPAddress _ap_static_ip;
|
IPAddress _ap_static_ip;
|
||||||
IPAddress _ap_static_gw;
|
IPAddress _ap_static_gw;
|
||||||
|
|||||||
Reference in New Issue
Block a user