diff --git a/README.md b/README.md index b1d2d39..7d5b8dc 100644 --- a/README.md +++ b/README.md @@ -21,10 +21,10 @@ First attempt at a library. Lots more changes and fixes to do. Contributions are - add ability to configure more parameters than ssid/password - maybe allow setting ip of ESP after reboot -This works with the ESP8266 Arduino platform https://github.com/esp8266/Arduino +This works with the ESP8266 Arduino platform with a recent stable release(2.0.0 or newer) https://github.com/esp8266/Arduino ## Releases -#### v0.3 +#### v0.3 and head - removed the need for EEPROM and works with the 2.0.0 and above stable release of the ESP8266 for Arduino IDE package - removed restart on save of credentials - updated examples @@ -88,6 +88,10 @@ This will set your captive portal to a specific IP should you need/want such a f //set custom ip for portal wifiManager.setAPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); ``` +### Contributions and thanks +[alltheblinkythings](https://github.com/alltheblinkythings) +[Niklas Wall](https://github.com/niklaswall) +[Jakub Piasecki](https://github.com/zaporylie) #### Inspiration - http://www.esp8266.com/viewtopic.php?f=29&t=2520 diff --git a/WiFiManager.cpp b/WiFiManager.cpp index b6d7e4a..ca54463 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -88,7 +88,10 @@ boolean WiFiManager::autoConnect(char const *apName) { //not connected //setup AP WiFi.mode(WIFI_AP); - + //notify we entered AP mode + if( _apcallback != NULL) { + _apcallback(); + } connect = false; begin(apName); @@ -423,6 +426,11 @@ boolean WiFiManager::captivePortal() { return false; } +//start up config portal callback +void WiFiManager::setAPCallback( void (*func)(void) ) { + _apcallback = func; +} + template void WiFiManager::DEBUG_PRINT(Generic text) { diff --git a/WiFiManager.h b/WiFiManager.h index 2e5ec68..67ceb56 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -24,10 +24,7 @@ class WiFiManager { public: WiFiManager(); - - void begin(); - void begin(char const *apName); - + boolean autoConnect(); boolean autoConnect(char const *apName); @@ -52,6 +49,7 @@ public: //sets a custom ip /gateway /subnet configuration void setAPConfig(IPAddress ip, IPAddress gw, IPAddress sn); + void setAPCallback( void (*func)(void) ); int serverLoop(); @@ -75,6 +73,9 @@ private: //const char HTTP_END[] PROGMEM = R"=====( // //)====="; + + void begin(); + void begin(char const *apName); int _eepromStart; const char* _apName = "no-net"; @@ -109,6 +110,8 @@ private: boolean connect; boolean _debug = true; + void (*_apcallback)(void) = NULL; + template void DEBUG_PRINT(Generic text); }; diff --git a/examples/AutoConnectWithFeedback/AutoConnectWithFeedback.ino b/examples/AutoConnectWithFeedback/AutoConnectWithFeedback.ino new file mode 100644 index 0000000..481626a --- /dev/null +++ b/examples/AutoConnectWithFeedback/AutoConnectWithFeedback.ino @@ -0,0 +1,44 @@ +#include //https://github.com/esp8266/Arduino + +//needed for library +#include +#include +#include //https://github.com/tzapu/WiFiManager + +void configModeCallback () { + Serial.println("Entered config mode"); + Serial.println(WiFi.softAPIP()); +} + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + + //WiFiManager + //Local intialization. Once its business is done, there is no need to keep it around + WiFiManager wifiManager; + //reset settings - for testing + //wifiManager.resetSettings(); + + //set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode + wifiManager.setAPCallback(configModeCallback); + //fetches ssid and pass and tries to connect + //if it does not connect it starts an access point with the specified name + //here "AutoConnectAP" + //and goes into a blocking loop awaiting configuration + if(!wifiManager.autoConnect("AutoConnectAP")) { + Serial.println("failed to connect and hit timeout"); + //reset and try again, or maybe put it to deep sleep + ESP.reset(); + delay(1000); + } + + //if you get here you have connected to the WiFi + Serial.println("connected...yeey :)"); + +} + +void loop() { + // put your main code here, to run repeatedly: + +}