ability to disable captiveportal

Sometimes the redirect to captive portal is unwanted or a nuisance, eg wehn using as a webserver etc.
This commit is contained in:
Shawn A
2017-09-14 17:09:17 -05:00
parent 4d18bfb113
commit 31ab2b67d0
2 changed files with 10 additions and 1 deletions
+7 -1
View File
@@ -536,7 +536,7 @@ void WiFiManager::handleWifi(boolean scan) {
String WiFiManager::getScanItemOut(){
String page;
int n = WiFi.scanNetworks();
DEBUG_WM(F("Scan done"));
if (n == 0) {
@@ -987,6 +987,9 @@ void WiFiManager::handleNotFound() {
*/
boolean WiFiManager::captivePortal() {
DEBUG_WM(server->hostHeader());
if(!_enableCaptivePortal) return true; // skip redirections
if (!isIp(server->hostHeader())) {
DEBUG_WM(F("Request redirected to captive portal"));
server->sendHeader("Location", String("http://") + toStringIp(server->client().localIP()), true);
@@ -1034,6 +1037,9 @@ void WiFiManager::setShowStaticFields(boolean alwaysShow){
_sta_show_static_fields = alwaysShow;
}
void WiFiManager::setCaptivePortalEnable(boolean enabled){
_enableCaptivePortal = enabled;
}
// HELPERS
+3
View File
@@ -148,6 +148,8 @@ class WiFiManager
//if true, always show static net inputs, IP, subnet, gateway, if false, only show when already set.
void setShowStaticFields(boolean alwaysShow);
void setCaptivePortalEnable(boolean enabled);
private:
std::unique_ptr<DNSServer> dnsServer;
std::unique_ptr<ESP8266WebServer> server;
@@ -175,6 +177,7 @@ class WiFiManager
unsigned long _configPortalStart = 0;
boolean _userpersistent = true;
WiFiMode_t _usermode = WIFI_OFF;
boolean _enableCaptivePortal = true;
IPAddress _ap_static_ip;
IPAddress _ap_static_gw;