mirror of
				https://github.com/s00500/ESPUI.git
				synced 2025-10-30 20:53:24 +00:00 
			
		
		
		
	Add captive portal functionality, update examples and documentation.
This commit is contained in:
		
							
								
								
									
										10
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								README.md
									
									
									
									
									
								
							| @@ -43,6 +43,7 @@ The Library runs on any kind of **ESP8266** and **ESP32** (NodeMCU, AI Thinker, | |||||||
|   * [Grouped controls](#grouped-controls) |   * [Grouped controls](#grouped-controls) | ||||||
|   * [Wide controls](#wide-controls) |   * [Wide controls](#wide-controls) | ||||||
|   * [Graph (Experimental)](#graph--experimental-) |   * [Graph (Experimental)](#graph--experimental-) | ||||||
|  |   * [Captive Portal](#captive-portal) | ||||||
| - [Notes for Development](#notes-for-development) | - [Notes for Development](#notes-for-development) | ||||||
| - [Contribute](#contribute) | - [Contribute](#contribute) | ||||||
|  |  | ||||||
| @@ -643,6 +644,15 @@ Graph points are saved in the browser in **localstorage** to be persistant, clea | |||||||
|  |  | ||||||
| _There are many issues with the graph component currently and work is ongoing. Consider helping us out with development!_ | _There are many issues with the graph component currently and work is ongoing. Consider helping us out with development!_ | ||||||
|  |  | ||||||
|  | ### 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.captivePortal == true; | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  |  | ||||||
| # Notes for Development | # Notes for Development | ||||||
|  |  | ||||||
| If you want to work on the HTML/CSS/JS files, do make changes in the _data_ | If you want to work on the HTML/CSS/JS files, do make changes in the _data_ | ||||||
|   | |||||||
| @@ -199,7 +199,7 @@ void setup(void) | |||||||
|         if (WiFi.status() != WL_CONNECTED) |         if (WiFi.status() != WL_CONNECTED) | ||||||
|         { |         { | ||||||
|             Serial.print("\n\nCreating hotspot"); |             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); |             WiFi.mode(WIFI_AP); | ||||||
|             delay(100); |             delay(100); | ||||||
|             WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); |             WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); | ||||||
|   | |||||||
| @@ -189,7 +189,7 @@ void setup(void) | |||||||
|         if (WiFi.status() != WL_CONNECTED) |         if (WiFi.status() != WL_CONNECTED) | ||||||
|         { |         { | ||||||
|             Serial.print("\n\nCreating hotspot"); |             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); |             WiFi.mode(WIFI_AP); | ||||||
|             delay(100); |             delay(100); | ||||||
|             WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); |             WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); | ||||||
| @@ -256,7 +256,6 @@ void setup(void) | |||||||
|      * since it is transmitted in cleartext. Just add a string as username and |      * since it is transmitted in cleartext. Just add a string as username and | ||||||
|      * password, for example begin("ESPUI Control", "username", "password") |      * password, for example begin("ESPUI Control", "username", "password") | ||||||
|      */ |      */ | ||||||
|  |  | ||||||
|     ESPUI.begin("ESPUI Control"); |     ESPUI.begin("ESPUI Control"); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -197,7 +197,7 @@ void setup(void) | |||||||
|         if (WiFi.status() != WL_CONNECTED) |         if (WiFi.status() != WL_CONNECTED) | ||||||
|         { |         { | ||||||
|             Serial.print("\n\nCreating hotspot"); |             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); |             WiFi.mode(WIFI_AP); | ||||||
|             delay(100); |             delay(100); | ||||||
|             WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); |             WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); | ||||||
|   | |||||||
| @@ -25,6 +25,7 @@ beginLITTLEFS	KEYWORD2 | |||||||
| print	KEYWORD2 | print	KEYWORD2 | ||||||
| updateSwitcher	KEYWORD2 | updateSwitcher	KEYWORD2 | ||||||
| updateSlider	KEYWORD2 | updateSlider	KEYWORD2 | ||||||
|  | captivePortal	KEYWORD2 | ||||||
|  |  | ||||||
| ####################################### | ####################################### | ||||||
| # Instances (KEYWORD2) | # Instances (KEYWORD2) | ||||||
|   | |||||||
| @@ -1351,7 +1351,16 @@ void ESPUIClass::beginLITTLEFS(const char* _title, const char* username, const c | |||||||
|         request->send(200, "text/plain", String(ESP.getFreeHeap()) + " In LITTLEFS mode"); |         request->send(200, "text/plain", String(ESP.getFreeHeap()) + " In LITTLEFS mode"); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     server->onNotFound([](AsyncWebServerRequest* request) { request->send(404); }); |     server->onNotFound([this](AsyncWebServerRequest* request) { | ||||||
|  | 		if(captivePortal == true) | ||||||
|  | 		{ | ||||||
|  | 			request->redirect("/"); | ||||||
|  | 		} | ||||||
|  | 		else | ||||||
|  | 		{ | ||||||
|  | 			request->send(404);  | ||||||
|  | 		} | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|     server->begin(); |     server->begin(); | ||||||
|  |  | ||||||
| @@ -1496,7 +1505,16 @@ void ESPUIClass::begin(const char* _title, const char* username, const char* pas | |||||||
|         request->send(200, "text/plain", String(ESP.getFreeHeap()) + " In Memorymode"); |         request->send(200, "text/plain", String(ESP.getFreeHeap()) + " In Memorymode"); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     server->onNotFound([](AsyncWebServerRequest* request) { request->send(404); }); |     server->onNotFound([this](AsyncWebServerRequest* request) { | ||||||
|  | 		if(captivePortal == true) | ||||||
|  | 		{ | ||||||
|  | 			request->redirect("/"); | ||||||
|  | 		} | ||||||
|  | 		else | ||||||
|  | 		{ | ||||||
|  | 			request->send(404);  | ||||||
|  | 		} | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|     server->begin(); |     server->begin(); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -236,6 +236,7 @@ public: | |||||||
|     unsigned int jsonUpdateDocumentSize; |     unsigned int jsonUpdateDocumentSize; | ||||||
|     unsigned int jsonInitialDocumentSize; |     unsigned int jsonInitialDocumentSize; | ||||||
|     bool sliderContinuous; |     bool sliderContinuous; | ||||||
|  | 	bool captivePortal = false; | ||||||
|  |  | ||||||
|     void setVerbosity(Verbosity verbosity); |     void setVerbosity(Verbosity verbosity); | ||||||
|     void begin(const char* _title, const char* username = nullptr, const char* password = nullptr, |     void begin(const char* _title, const char* username = nullptr, const char* password = nullptr, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Nick Reynolds
					Nick Reynolds