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:
Shawn A
2017-08-29 16:31:59 -05:00
parent d1ab6ec6db
commit 04a9dda74b
2 changed files with 27 additions and 6 deletions
+17 -5
View File
@@ -82,13 +82,17 @@ void WiFiManager::addParameter(WiFiManagerParameter *p) {
}
// constructor
WiFiManager::WiFiManager() {
WiFi.persistent(false);
WiFiManager::WiFiManager() {
_usermode = WiFi.getMode();
WiFi.persistent(false); // disable persistent so scannetworks and mode switching is not saved
}
// destructor
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
@@ -121,7 +125,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
// CONFIG PORTAL
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);
// setup optional soft AP static ip config
@@ -303,7 +307,7 @@ boolean WiFiManager::stopConfigPortal(){
// turn off AP
DEBUG_WM(F("disconnect configportal"));
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
configPortalActive = false;
return ret;
@@ -422,7 +426,9 @@ String WiFiManager::getConfigPortalSSID() {
void WiFiManager::resetSettings() {
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?
WiFi.persistent(true);
WiFi.disconnect(true);
WiFi.persistent(false);
//delay(200);
}
@@ -858,6 +864,12 @@ void WiFiManager::setConfigPortalBlocking(boolean 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
template <typename Generic>
+10 -1
View File
@@ -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
void setConfigPortalBlocking(boolean shouldBlock);
//TODO
//if this is set, customise style
void setCustomHeadElement(const char* element);
//if this is true, remove duplicated Access Points - defaut true
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:
std::unique_ptr<DNSServer> dnsServer;
@@ -144,6 +146,11 @@ class WiFiManager
void startWPS();
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 _apPassword = "";
String _ssid = "";
@@ -151,6 +158,8 @@ class WiFiManager
unsigned long _configPortalTimeout = 0;
unsigned long _connectTimeout = 0;
unsigned long _configPortalStart = 0;
boolean _userpersistent = true;
WiFiMode_t _usermode = WIFI_OFF;
IPAddress _ap_static_ip;
IPAddress _ap_static_gw;