diff --git a/README.md b/README.md index 04824ea..f4d5978 100644 --- a/README.md +++ b/README.md @@ -646,10 +646,12 @@ _There are many issues with the graph component currently and work is ongoing. C ### Captive Portal -You can set ESPUI to redirect all unknown URLs it is asked for to the 'root' the local HTTP server instead of responding with an HTTP code 404. This turns it into a simple 'captive portal'. Note you must also set up the ESP to be a DNS server that responds to all DNS requests with the IP address of the ESP for this to be effective and this is only useful when the ESP is acting as a WiFi hotspot in AP mode. All the example sketches will work as captive portals if not connected to a local WiFi network as a station. +ESPUI will redirect all unknown URLs it is asked for to the 'root' of the local HTTP server instead of responding with an HTTP code 404. This makes it act as a simple 'captive portal'. Note you must also set up the ESP to be a DNS server that responds to all DNS requests with the IP address of the ESP. This only effective when the ESP is acting as a WiFi hotspot in AP mode and assigning itself as the DNS server to connected clients. + +All the example sketches include the DNS related code and will work as captive portals when used as a hotspot. In the event you wish to disable this feature you can do so by removing the DNS server code and adding the code below. ``` -ESPUI.captivePortal == true; +ESPUI.captivePortal = false; ``` diff --git a/examples/gui-generic-api/gui-generic-api.ino b/examples/gui-generic-api/gui-generic-api.ino index 9885bf8..44f0119 100644 --- a/examples/gui-generic-api/gui-generic-api.ino +++ b/examples/gui-generic-api/gui-generic-api.ino @@ -199,7 +199,7 @@ void setup(void) if (WiFi.status() != WL_CONNECTED) { Serial.print("\n\nCreating hotspot"); - ESPUI.captivePortal = true; //Configure ESPUI to be a captive portal only if the ESP is acting as a hotspot + WiFi.mode(WIFI_AP); delay(100); WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); diff --git a/examples/gui/gui.ino b/examples/gui/gui.ino index 32f05c4..2356fd6 100644 --- a/examples/gui/gui.ino +++ b/examples/gui/gui.ino @@ -189,7 +189,7 @@ void setup(void) if (WiFi.status() != WL_CONNECTED) { Serial.print("\n\nCreating hotspot"); - ESPUI.captivePortal = true; //Configure ESPUI to be a captive portal only if the ESP is acting as a hotspot + WiFi.mode(WIFI_AP); delay(100); WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); diff --git a/examples/tabbedGui/tabbedGui.ino b/examples/tabbedGui/tabbedGui.ino index 1cbd3d6..b02ae4b 100644 --- a/examples/tabbedGui/tabbedGui.ino +++ b/examples/tabbedGui/tabbedGui.ino @@ -197,7 +197,7 @@ void setup(void) if (WiFi.status() != WL_CONNECTED) { Serial.print("\n\nCreating hotspot"); - ESPUI.captivePortal = true; //Configure ESPUI to be a captive portal only if the ESP is acting as a hotspot + WiFi.mode(WIFI_AP); delay(100); WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); diff --git a/keywords.txt b/keywords.txt index cb4ea35..84cd7eb 100644 --- a/keywords.txt +++ b/keywords.txt @@ -25,7 +25,7 @@ beginLITTLEFS KEYWORD2 print KEYWORD2 updateSwitcher KEYWORD2 updateSlider KEYWORD2 -captivePortal KEYWORD2 +captivePortal LITERAL1 ####################################### # Instances (KEYWORD2) diff --git a/src/ESPUI.cpp b/src/ESPUI.cpp index 8dcd9d5..c6f3577 100644 --- a/src/ESPUI.cpp +++ b/src/ESPUI.cpp @@ -1352,7 +1352,7 @@ void ESPUIClass::beginLITTLEFS(const char* _title, const char* username, const c }); server->onNotFound([this](AsyncWebServerRequest* request) { - if(captivePortal == true) + if(captivePortal) { request->redirect("/"); } @@ -1506,7 +1506,7 @@ void ESPUIClass::begin(const char* _title, const char* username, const char* pas }); server->onNotFound([this](AsyncWebServerRequest* request) { - if(captivePortal == true) + if(captivePortal) { request->redirect("/"); }