diff --git a/README.md b/README.md index 7cdaa63..441b0cf 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ This works with the ESP8266 Arduino platform https://github.com/esp8266/Arduino > v0.1 works with the staging release ver. 1.6.5-1044-g170995a, built on Aug 10, 2015 of the ESP8266 Arduino library. > latest comit should work with the latest staging version -####Quick Start +## Quick Start - Checkout library to your Arduino libraries folder - Include in your sketch @@ -40,7 +40,7 @@ While in AP mode, connect to it then open a browser to the gateway IP, default 1 Also see examples. -###Timeout +### Timeout If you need to set a timeout so the ESP doesn't hang waiting to be configured, for instance after a power failure, you can add ``` wifi.setTimeout(180); @@ -48,12 +48,19 @@ wifi.setTimeout(180); which will wait 3 minutes (180 seconds). When the time passes, the autoConnect function will return, no matter the outcome. Check for connection and if it's still not established do whatever is needed (on some modules I restart them to retry, on others I enter deep sleep) -###Debug +### Debug Debug is enabled by default on Serial. To disable add before autoConnect ``` wifi.setDebugOutput(false); ``` +### Custom IP Configuration +This will set your captive portal to a specific IP should you need/want such a feature. Add the following snippet before `autoConnect()` +``` +//set custom ip for portal +wifi.setAPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); +``` + ####Inspiration - http://www.esp8266.com/viewtopic.php?f=29&t=2520 diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 8225cb5..077ff4b 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -34,6 +34,12 @@ void WiFiManager::begin(char const *apName) { DEBUG_PRINT("Configuring access point... "); DEBUG_PRINT(_apName); + //optional soft ip config + if (_ip) { + DEBUG_PRINT("Custom IP/GW/Subnet"); + WiFi.softAPConfig(_ip, _gw, _sn); + } + WiFi.softAP(_apName);//TODO: add password option delay(500); // Without delay I've seen the IP address blank DEBUG_PRINT("AP IP address: "); @@ -250,6 +256,12 @@ void WiFiManager::setDebugOutput(boolean debug) { _debug = debug; } +void WiFiManager::setAPConfig(IPAddress ip, IPAddress gw, IPAddress sn) { + _ip = ip; + _gw = gw; + _sn = sn; +} + /** Handle root or redirect to captive portal */ void WiFiManager::handleRoot() { diff --git a/WiFiManager.h b/WiFiManager.h index 57028d3..4727c27 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -25,16 +25,16 @@ class WiFiManager public: WiFiManager(); - void begin(); - void begin(char const *apName); + void begin(); + void begin(char const *apName); boolean autoConnect(); boolean autoConnect(char const *apName); boolean hasConnected(); - String beginConfigMode(void); - void startWebConfig(); + String beginConfigMode(void); + void startWebConfig(); String getSSID(); String getPassword(); @@ -42,15 +42,18 @@ public: void setPassword(String p); void resetSettings(); //for conveniennce - String urldecode(const char*); + String urldecode(const char*); //sets timeout before webserver loop ends and exits even if there has been no setup. //usefully for devices that failed to connect at some point and got stuck in a webserver loop //in seconds - void setTimeout(unsigned long seconds); - void setDebugOutput(boolean debug); + void setTimeout(unsigned long seconds); + void setDebugOutput(boolean debug); - int serverLoop(); + //sets a custom ip /gateway /subnet configuration + void setAPConfig(IPAddress ip, IPAddress gw, IPAddress sn); + + int serverLoop(); private: DNSServer dnsServer; @@ -79,7 +82,9 @@ private: String _pass = ""; unsigned long timeout = 0; unsigned long start = 0; - + IPAddress _ip; + IPAddress _gw; + IPAddress _sn; String getEEPROMString(int start, int len); void setEEPROMString(int start, int len, String string); diff --git a/examples/AutoConnect/AutoConnect.ino b/examples/AutoConnect/AutoConnect.ino index 66d658f..286ba28 100644 --- a/examples/AutoConnect/AutoConnect.ino +++ b/examples/AutoConnect/AutoConnect.ino @@ -14,7 +14,12 @@ void setup() { //WiFiManager //Local intialization. Once its business is done, there is no need to keep it around WiFiManager wifi; + //reset saved settings + //wifi.resetSettings(); + //set custom ip for portal + //wifi.setAPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); + //fetches ssid and pass from eeprom and tries to connect //if it does not connect it starts an access point with the specified name //here "AutoConnectAP"