mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-04 02:48:13 +10:00
added config mode callback
This commit is contained in:
@@ -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
|
||||
|
||||
+9
-1
@@ -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 <typename Generic>
|
||||
void WiFiManager::DEBUG_PRINT(Generic text) {
|
||||
|
||||
+7
-4
@@ -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"=====(
|
||||
//</body></html>
|
||||
//)=====";
|
||||
|
||||
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 <typename Generic>
|
||||
void DEBUG_PRINT(Generic text);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
|
||||
|
||||
//needed for library
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <WiFiManager.h> //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:
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user