test ondemand webportal

This commit is contained in:
Shawn A
2017-09-18 08:42:09 -05:00
parent 8e710b9d92
commit 4592914fad
2 changed files with 29 additions and 7 deletions
+26 -7
View File
@@ -169,15 +169,13 @@ boolean WiFiManager::configPortalHasTimeout(){
}
void WiFiManager::setupConfigPortal() {
DEBUG_WM("Starting Web Portal");
// setup dns and web servers
dnsServer.reset(new DNSServer());
server.reset(new ESP8266WebServer(80));
DEBUG_WM(F("setupConfigPortal"));
_configPortalStart = millis();
if(!startAP()) DEBUG_WM("There was an error stating the AP"); // @bug startAP returns unreliable success status
/* Setup the DNS server redirecting all the domains to the apIP */
dnsServer->setErrorReplyCode(DNSReplyCode::NoError);
dnsServer->start(DNS_PORT, "*", WiFi.softAPIP());
@@ -196,6 +194,19 @@ void WiFiManager::setupConfigPortal() {
DEBUG_WM(F("HTTP server started"));
}
void WiFiManager::startWebPortal() {
if(configPortalActive || webPortalActive) return;
setupConfigPortal();
webPortalActive = true;
}
void WiFiManager::stopWebPortal() {
if(!configPortalActive && !webPortalActive) return;
DEBUG_WM("Stopping Web Portal");
webPortalActive = false;
stopConfigPortal();
}
boolean WiFiManager::startConfigPortal() {
String ssid = "ESP" + String(ESP.getChipId());
return startConfigPortal(ssid.c_str(), NULL);
@@ -219,6 +230,10 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
configPortalActive = true;
connect = false; // global
DEBUG_WM(F("setupConfigPortal"));
_configPortalStart = millis();
if(!startAP()) DEBUG_WM("There was an error stating the AP"); // @bug startAP returns unreliable success status
// init configportal
setupConfigPortal();
@@ -253,7 +268,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
}
boolean WiFiManager::process(){
if(configPortalActive && !_configPortalIsBlocking){
if(webPortalActive || (configPortalActive && !_configPortalIsBlocking)){
uint8_t state = handleConfigPortal();
return state == WL_CONNECTED;
}
@@ -293,7 +308,9 @@ uint8_t WiFiManager::handleConfigPortal(){
}
boolean WiFiManager::stopConfigPortal(){
// do save callback
if(webPortalActive) return false;
// do save callback, @todo move out of here
if ( _savecallback != NULL) {
//todo: confirm or verify data was saved
_savecallback();
@@ -308,6 +325,8 @@ boolean WiFiManager::stopConfigPortal(){
server.reset();
dnsServer.reset();
if(!configPortalActive) return false;
// turn off AP
DEBUG_WM(F("disconnect configportal"));
bool ret = WiFi.softAPdisconnect(false);
+3
View File
@@ -105,6 +105,8 @@ class WiFiManager
boolean startConfigPortal();
boolean startConfigPortal(char const *apName, char const *apPassword = NULL);
boolean process();
void startWebPortal();
void stopWebPortal();
// get the AP name of the config portal, so it can be used in the callback
String getConfigPortalSSID();
@@ -237,6 +239,7 @@ class WiFiManager
boolean connect;
boolean configPortalActive = false;
boolean webPortalActive = false;
boolean _debug = true;
void (*_apcallback)(WiFiManager*) = NULL;