mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-04 02:48:13 +10:00
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:
+7
-1
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user