mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-04 02:48:13 +10:00
added more examples,
updated readme made it compile on older versions
This commit is contained in:
@@ -48,7 +48,7 @@ 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~~
|
||||
- ~~add to Arduino Boards Manager~~
|
||||
- add to PlatformIO
|
||||
- ~~add to PlatformIO~~
|
||||
- add multiple sets of network credentials
|
||||
- allow users to customize CSS
|
||||
|
||||
@@ -58,7 +58,7 @@ First attempt at a library. Lots more changes and fixes to do. Contributions are
|
||||
You can either install through the Arduino Boards Manager or checkout the latest changes or a release from github
|
||||
|
||||
#### Install through Boards Manager
|
||||
__Currently version 0.6 works with release 2.0.0 or newer of the [ESP8266 core for Arduino](https://github.com/esp8266/Arduino)__
|
||||
__Currently version 0.8 works with release 2.0.0 or newer of the [ESP8266 core for Arduino](https://github.com/esp8266/Arduino)__
|
||||
- in Arduino IDE got to Sketch/Include Library/Manage Libraries
|
||||

|
||||
|
||||
@@ -68,7 +68,7 @@ __Currently version 0.6 works with release 2.0.0 or newer of the [ESP8266 core f
|
||||
- click Install and start [using it](#using)
|
||||
|
||||
#### Checkout from github
|
||||
__Github version works with the HEAD (as of 18 jan 2016) or newer of the [ESP8266 core for Arduino](https://github.com/esp8266/Arduino)__
|
||||
__Github version works with release 2.0.0 or newer of the [ESP8266 core for Arduino](https://github.com/esp8266/Arduino)__
|
||||
- Checkout library to your Arduino libraries folder
|
||||
|
||||
### Using
|
||||
@@ -131,7 +131,7 @@ void configModeCallback (WiFiManager *myWiFiManager) {
|
||||
```
|
||||
|
||||
##### Save settings
|
||||
This gets called when custom parameters have been set **AND** a connection has been established. Use it to set a flag, so when all the configuration finishes, you can save the extra parameters somewhere.
|
||||
This gets called when custom parameters have been set **AND** a connection has been established. Use it to set a flag, so when all the configuration finishes, you can save the extra parameters somewhere.
|
||||
|
||||
See [AutoConnectWithFSParameters Example](https://github.com/tzapu/WiFiManager/tree/master/examples/AutoConnectWithFSParameters).
|
||||
```cpp
|
||||
@@ -229,6 +229,8 @@ wifiManager.setDebugOutput(false);
|
||||
## Troubleshooting
|
||||
If you get compilation errors, more often than not, you may need to install a newer version of the ESP8266 core for Arduino.
|
||||
|
||||
Changes added on 0.8 should make the latest trunk work without compilation errors. Tested down to ESP8266 core 2.0.0. **Please update to version 0.8**
|
||||
|
||||
I am trying to keep releases working with release versions of the core, so they can be installed through boards manager, but if you checkout the latest version directly from github, sometimes, the library will only work if you update the ESP8266 core to the latest version because I am using some newly added function.
|
||||
|
||||
|
||||
@@ -236,7 +238,17 @@ If you connect to the created configuration Access Point but the configuration p
|
||||
|
||||
|
||||
## Releases
|
||||
#### 0.6
|
||||
#### 0.8
|
||||
- made it compile on older versions of ESP8266 core as well, tested down to 2.0.0
|
||||
- added simple example for Custom IP
|
||||
|
||||
##### 0.7
|
||||
- added static IP in station mode
|
||||
- added example of persisting custom IP to FS config.json
|
||||
- more option on portal homepage
|
||||
- added on PlatformIO
|
||||
|
||||
##### 0.6
|
||||
- custom parameters
|
||||
- prettier
|
||||
- on demand config portal
|
||||
|
||||
+32
-22
@@ -16,7 +16,7 @@ WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placehold
|
||||
_id = id;
|
||||
_placeholder = placeholder;
|
||||
_length = length;
|
||||
_value = new char[length+1];
|
||||
_value = new char[length + 1];
|
||||
for (int i = 0; i < length; i++) {
|
||||
_value[i] = 0;
|
||||
}
|
||||
@@ -98,6 +98,11 @@ void WiFiManager::setupConfigPortal() {
|
||||
server->onNotFound (std::bind(&WiFiManager::handleNotFound, this));
|
||||
server->begin(); // Web server start
|
||||
DEBUG_WM(F("HTTP server started"));
|
||||
/*
|
||||
String ip = "10.1.2.3";
|
||||
optionalIPFromString(&_sta_static_ip, ip.c_str());
|
||||
DEBUG_WM(_sta_static_ip);*/
|
||||
|
||||
}
|
||||
|
||||
boolean WiFiManager::autoConnect() {
|
||||
@@ -152,7 +157,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
|
||||
connect = false;
|
||||
delay(2000);
|
||||
DEBUG_WM(F("Connecting to new AP"));
|
||||
|
||||
|
||||
// using user-provided _ssid, _pass in place of system-stored ssid and pass
|
||||
if (connectWifi(_ssid, _pass) != WL_CONNECTED) {
|
||||
DEBUG_WM(F("Failed to connect."));
|
||||
@@ -166,8 +171,8 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(_shouldBreakAfterConfig) {
|
||||
|
||||
if (_shouldBreakAfterConfig) {
|
||||
//flag set to exit after config after trying to connect
|
||||
//notify that configuration has changed and any optional parameters should be saved
|
||||
if ( _savecallback != NULL) {
|
||||
@@ -197,13 +202,14 @@ int WiFiManager::connectWifi(String ssid, String pass) {
|
||||
DEBUG_WM(WiFi.localIP());
|
||||
}
|
||||
|
||||
if(ssid !="" && pass != "") {
|
||||
//check if we have ssid and pass and force those, if not, try with last saved values
|
||||
if (ssid != "" && pass != "") {
|
||||
WiFi.begin(ssid.c_str(), pass.c_str());
|
||||
} else {
|
||||
DEBUG_WM("Using last saved values, should be faster");
|
||||
WiFi.begin();
|
||||
}
|
||||
|
||||
|
||||
int connRes = WiFi.waitForConnectResult();
|
||||
DEBUG_WM ("Connection result: ");
|
||||
DEBUG_WM ( connRes );
|
||||
@@ -273,7 +279,7 @@ String WiFiManager::urldecode(const char *src)
|
||||
|
||||
void WiFiManager::resetSettings() {
|
||||
DEBUG_WM(F("settings invalidated"));
|
||||
DEBUG_WM(F("THIS MAY CAUSE AP NOT TO STRT UP PROPERLY. YOU NEED TO COMMENT IT OUT AFTER ERASING THE DATA."));
|
||||
DEBUG_WM(F("THIS MAY CAUSE AP NOT TO START UP PROPERLY. YOU NEED TO COMMENT IT OUT AFTER ERASING THE DATA."));
|
||||
WiFi.disconnect(true);
|
||||
//delay(200);
|
||||
}
|
||||
@@ -324,7 +330,7 @@ void WiFiManager::handleRoot() {
|
||||
page += F("<h3>WiFiManager</h3>");
|
||||
page += FPSTR(HTTP_PORTAL_OPTIONS);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
|
||||
server->send(200, "text/html", page);
|
||||
|
||||
}
|
||||
@@ -404,8 +410,8 @@ void WiFiManager::handleWifi(boolean scan) {
|
||||
server->sendContent_P("<br/>");
|
||||
}
|
||||
|
||||
if(_sta_static_ip) {
|
||||
|
||||
if (_sta_static_ip) {
|
||||
|
||||
String item = FPSTR(HTTP_FORM_PARAM);
|
||||
item.replace("{i}", "ip");
|
||||
item.replace("{n}", "ip");
|
||||
@@ -413,8 +419,8 @@ void WiFiManager::handleWifi(boolean scan) {
|
||||
item.replace("{l}", "15");
|
||||
item.replace("{v}", _sta_static_ip.toString());
|
||||
|
||||
server->sendContent(item);
|
||||
|
||||
server->sendContent(item);
|
||||
|
||||
item = FPSTR(HTTP_FORM_PARAM);
|
||||
item.replace("{i}", "gw");
|
||||
item.replace("{n}", "gw");
|
||||
@@ -423,7 +429,7 @@ void WiFiManager::handleWifi(boolean scan) {
|
||||
item.replace("{v}", _sta_static_gw.toString());
|
||||
|
||||
server->sendContent(item);
|
||||
|
||||
|
||||
item = FPSTR(HTTP_FORM_PARAM);
|
||||
item.replace("{i}", "sn");
|
||||
item.replace("{n}", "sn");
|
||||
@@ -431,7 +437,7 @@ void WiFiManager::handleWifi(boolean scan) {
|
||||
item.replace("{l}", "15");
|
||||
item.replace("{v}", _sta_static_sn.toString());
|
||||
|
||||
server->sendContent(item);
|
||||
server->sendContent(item);
|
||||
|
||||
server->sendContent_P("<br/>");
|
||||
}
|
||||
@@ -466,20 +472,24 @@ void WiFiManager::handleWifiSave() {
|
||||
DEBUG_WM(value);
|
||||
}
|
||||
|
||||
if(server->arg("ip") != "") {
|
||||
if (server->arg("ip") != "") {
|
||||
DEBUG_WM(F("static ip"));
|
||||
DEBUG_WM(server->arg("ip"));
|
||||
_sta_static_ip.fromString(server->arg("ip"));
|
||||
//_sta_static_ip.fromString(server->arg("ip"));
|
||||
String ip = server->arg("ip");
|
||||
optionalIPFromString(&_sta_static_ip, ip.c_str());
|
||||
}
|
||||
if(server->arg("gw") != "") {
|
||||
if (server->arg("gw") != "") {
|
||||
DEBUG_WM(F("static gateway"));
|
||||
DEBUG_WM(server->arg("gw"));
|
||||
_sta_static_gw.fromString(server->arg("gw"));
|
||||
String gw = server->arg("gw");
|
||||
optionalIPFromString(&_sta_static_gw, gw.c_str());
|
||||
}
|
||||
if(server->arg("sn") != "") {
|
||||
if (server->arg("sn") != "") {
|
||||
DEBUG_WM(F("static netmask"));
|
||||
DEBUG_WM(server->arg("sn"));
|
||||
_sta_static_sn.fromString(server->arg("sn"));
|
||||
String sn = server->arg("sn");
|
||||
optionalIPFromString(&_sta_static_sn, sn.c_str());
|
||||
}
|
||||
|
||||
server->sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
@@ -509,7 +519,7 @@ void WiFiManager::handleWifiSave() {
|
||||
void WiFiManager::handleInfo() {
|
||||
DEBUG_WM(F("Info"));
|
||||
|
||||
String page = FPSTR(HTTP_HEAD);
|
||||
String page = FPSTR(HTTP_HEAD);
|
||||
page.replace("{v}", "Info");
|
||||
page += FPSTR(HTTP_SCRIPT);
|
||||
page += FPSTR(HTTP_STYLE);
|
||||
@@ -535,7 +545,7 @@ String page = FPSTR(HTTP_HEAD);
|
||||
page += F("</dd>");
|
||||
page += F("</dl>");
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
|
||||
server->send(200, "text/html", page);
|
||||
|
||||
DEBUG_WM(F("Sent info page"));
|
||||
|
||||
+9
-2
@@ -157,8 +157,15 @@ class WiFiManager
|
||||
|
||||
template <typename Generic>
|
||||
void DEBUG_WM(Generic text);
|
||||
|
||||
template <class T>
|
||||
auto optionalIPFromString(T *obj, const char *s) -> decltype( obj->fromString(s) ) {
|
||||
return obj->fromString(s);
|
||||
}
|
||||
auto optionalIPFromString(...) -> bool {
|
||||
DEBUG_WM("NO fromString METHOD ON IPAddress, you need ESP8266 core 2.1.0 or newer for Custom IP configuration to work.");
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
#include <FS.h> //this needs to be first, or it all crashes and burns...
|
||||
|
||||
#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
|
||||
|
||||
|
||||
/**************************************************************************************
|
||||
* this example shows how to set a static IP configuration for the ESP
|
||||
* although the IP shows in the config portal, the changes will revert
|
||||
* to the IP set in the source file.
|
||||
* if you want the ability to configure and persist the new IP configuration
|
||||
* look at the FS examples, which save the config to file
|
||||
*************************************************************************************/
|
||||
|
||||
|
||||
|
||||
//default custom static IP
|
||||
//char static_ip[16] = "10.0.1.59";
|
||||
//char static_gw[16] = "10.0.1.1";
|
||||
//char static_sn[16] = "255.255.255.0";
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
|
||||
//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 static ip
|
||||
//the commented bit only works for ESP8266 core 2.1.0 or newer
|
||||
/*IPAddress _ip,_gw,_sn;
|
||||
_ip.fromString(static_ip);
|
||||
_gw.fromString(static_gw);
|
||||
_sn.fromString(static_sn);
|
||||
*/
|
||||
IPAddress _ip = IPAddress(10, 0, 1, 78);
|
||||
IPAddress _gw = IPAddress(10, 0, 1, 1);
|
||||
IPAddress _sn = IPAddress(255, 255, 255, 0);
|
||||
|
||||
wifiManager.setSTAStaticIPConfig(_ip, _gw, _sn);
|
||||
|
||||
|
||||
//tries to connect to last known settings
|
||||
//if it does not connect it starts an access point with the specified name
|
||||
//here "AutoConnectAP" with password "password"
|
||||
//and goes into a blocking loop awaiting configuration
|
||||
if (!wifiManager.autoConnect("AutoConnectAP", "password")) {
|
||||
Serial.println("failed to connect, we should reset as see if it connects");
|
||||
delay(3000);
|
||||
ESP.reset();
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
//if you get here you have connected to the WiFi
|
||||
Serial.println("connected...yeey :)");
|
||||
|
||||
|
||||
Serial.println("local ip");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
|
||||
|
||||
}
|
||||
+1
-1
@@ -9,5 +9,5 @@
|
||||
},
|
||||
"frameworks": "arduino",
|
||||
"platforms": "espressif",
|
||||
"version": "0.6"
|
||||
"version": "0.8"
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
name=WiFiManager
|
||||
version=0.7
|
||||
version=0.8
|
||||
author=tzapu
|
||||
maintainer=tzapu
|
||||
sentence=ESP8266 WiFi Connection manager with fallback web configuration portal
|
||||
|
||||
Reference in New Issue
Block a user