mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-05 11:18:33 +10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2582dd8735 | ||
|
|
f82141c98c | ||
|
|
9cde9a8170 | ||
|
|
3f617c7455 | ||
|
|
6f0c16d74f | ||
|
|
7b23c89204 | ||
|
|
55c751c133 | ||
|
|
0f75d745fe |
@@ -12,13 +12,13 @@ First attempt at a library. Lots more changes and fixes to do. Contributions are
|
||||
- [Wishlist](#wishlist)
|
||||
- [Quick start](#quick-start)
|
||||
- Installing
|
||||
- [Through Boards Manager](#install-through-boards-manager)
|
||||
- [Through Library Manager](#install-through-library-manager)
|
||||
- [From Github](#checkout-from-github)
|
||||
- [Using](#using)
|
||||
- [Documentation](#documentation)
|
||||
- [Access Point Password](#password-protect-the-configuration-access-point)
|
||||
- [Callbacks](#callbacks)
|
||||
- [Timeout](#timeout)
|
||||
- [Configuration Portal Timeout](#configuration-portal-timeout)
|
||||
- [On Demand Configuration](#on-demand-configuration-portal)
|
||||
- [Custom Parameters](#custom-parameters)
|
||||
- [Custom IP Configuration](#custom-ip-configuration)
|
||||
@@ -47,7 +47,7 @@ First attempt at a library. Lots more changes and fixes to do. Contributions are
|
||||
- if timeout is set, extend it when a page is fetched in AP mode
|
||||
- ~~add ability to configure more parameters than ssid/password~~
|
||||
- ~~maybe allow setting ip of ESP after reboot~~
|
||||
- ~~add to Arduino Boards Manager~~
|
||||
- ~~add to Arduino Library Manager~~
|
||||
- ~~add to PlatformIO~~
|
||||
- add multiple sets of network credentials
|
||||
- allow users to customize CSS
|
||||
@@ -55,9 +55,9 @@ First attempt at a library. Lots more changes and fixes to do. Contributions are
|
||||
## Quick Start
|
||||
|
||||
### Installing
|
||||
You can either install through the Arduino Boards Manager or checkout the latest changes or a release from github
|
||||
You can either install through the Arduino Library Manager or checkout the latest changes or a release from github
|
||||
|
||||
#### Install through Boards Manager
|
||||
#### Install through Library Manager
|
||||
__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
|
||||

|
||||
@@ -149,10 +149,10 @@ void saveConfigCallback () {
|
||||
}
|
||||
```
|
||||
|
||||
#### Timeout
|
||||
#### Configuration Portal 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
|
||||
```cpp
|
||||
wifiManager.setTimeout(180);
|
||||
wifiManager.setConfigPortalTimeout(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)
|
||||
@@ -238,7 +238,10 @@ If you connect to the created configuration Access Point but the configuration p
|
||||
|
||||
|
||||
## Releases
|
||||
#### 0.8
|
||||
#### 0.9
|
||||
- fixed support for encoded characters in ssid/pass
|
||||
|
||||
##### 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
|
||||
|
||||
|
||||
+117
-107
@@ -53,7 +53,7 @@ void WiFiManager::setupConfigPortal() {
|
||||
server.reset(new ESP8266WebServer(80));
|
||||
|
||||
DEBUG_WM(F(""));
|
||||
start = millis();
|
||||
_configPortalStart = millis();
|
||||
|
||||
DEBUG_WM(F("Configuring access point... "));
|
||||
DEBUG_WM(_apName);
|
||||
@@ -98,10 +98,6 @@ 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);*/
|
||||
|
||||
}
|
||||
|
||||
@@ -134,6 +130,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
|
||||
boolean WiFiManager::startConfigPortal(char const *apName, char const *apPassword) {
|
||||
//setup AP
|
||||
WiFi.mode(WIFI_AP);
|
||||
DEBUG_WM("SET AP");
|
||||
|
||||
_apName = apName;
|
||||
_apPassword = apPassword;
|
||||
@@ -146,7 +143,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
|
||||
connect = false;
|
||||
setupConfigPortal();
|
||||
|
||||
while (timeout == 0 || millis() < start + timeout) {
|
||||
while (_configPortalTimeout == 0 || millis() < _configPortalStart + _configPortalTimeout) {
|
||||
//DNS
|
||||
dnsServer->processNextRequest();
|
||||
//HTTP
|
||||
@@ -203,21 +200,55 @@ int WiFiManager::connectWifi(String ssid, String pass) {
|
||||
}
|
||||
|
||||
//check if we have ssid and pass and force those, if not, try with last saved values
|
||||
if (ssid != "" && pass != "") {
|
||||
if (ssid != "") {
|
||||
WiFi.begin(ssid.c_str(), pass.c_str());
|
||||
} else {
|
||||
DEBUG_WM("Using last saved values, should be faster");
|
||||
WiFi.begin();
|
||||
}
|
||||
|
||||
int connRes = WiFi.waitForConnectResult();
|
||||
int connRes = waitForConnectResult();
|
||||
DEBUG_WM ("Connection result: ");
|
||||
DEBUG_WM ( connRes );
|
||||
//not connected, WPS enabled, no pass - first attempt
|
||||
if (_tryWPS && connRes != WL_CONNECTED && pass == "") {
|
||||
startWPS();
|
||||
//should be connected at the end of WPS
|
||||
connRes = waitForConnectResult();
|
||||
}
|
||||
return connRes;
|
||||
}
|
||||
|
||||
uint8_t WiFiManager::waitForConnectResult() {
|
||||
if (_connectTimeout == 0) {
|
||||
return WiFi.waitForConnectResult();
|
||||
} else {
|
||||
DEBUG_WM (F("Waiting for connection result with time out"));
|
||||
unsigned long start = millis();
|
||||
boolean keepConnecting = true;
|
||||
uint8_t status;
|
||||
while (keepConnecting) {
|
||||
status = WiFi.status();
|
||||
if (millis() > start + _connectTimeout) {
|
||||
keepConnecting = false;
|
||||
DEBUG_WM (F("Connection timed out"));
|
||||
}
|
||||
if (status == WL_CONNECTED || status == WL_CONNECT_FAILED) {
|
||||
keepConnecting = false;
|
||||
}
|
||||
delay(100);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
String WiFiManager::getSSID() {
|
||||
void WiFiManager::startWPS() {
|
||||
DEBUG_WM("START WPS");
|
||||
WiFi.beginWPSConfig();
|
||||
DEBUG_WM("END WPS");
|
||||
}
|
||||
/*
|
||||
String WiFiManager::getSSID() {
|
||||
if (_ssid == "") {
|
||||
DEBUG_WM(F("Reading SSID"));
|
||||
_ssid = WiFi.SSID();
|
||||
@@ -225,9 +256,9 @@ String WiFiManager::getSSID() {
|
||||
DEBUG_WM(_ssid);
|
||||
}
|
||||
return _ssid;
|
||||
}
|
||||
}
|
||||
|
||||
String WiFiManager::getPassword() {
|
||||
String WiFiManager::getPassword() {
|
||||
if (_pass == "") {
|
||||
DEBUG_WM(F("Reading Password"));
|
||||
_pass = WiFi.psk();
|
||||
@@ -235,57 +266,28 @@ String WiFiManager::getPassword() {
|
||||
//DEBUG_WM(_pass);
|
||||
}
|
||||
return _pass;
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
String WiFiManager::getConfigPortalSSID() {
|
||||
return _apName;
|
||||
}
|
||||
|
||||
String WiFiManager::urldecode(const char *src)
|
||||
{
|
||||
String decoded = "";
|
||||
char a, b;
|
||||
while (*src) {
|
||||
if ((*src == '%') &&
|
||||
((a = src[1]) && (b = src[2])) &&
|
||||
(isxdigit(a) && isxdigit(b))) {
|
||||
if (a >= 'a')
|
||||
a -= 'a' - 'A';
|
||||
if (a >= 'A')
|
||||
a -= ('A' - 10);
|
||||
else
|
||||
a -= '0';
|
||||
if (b >= 'a')
|
||||
b -= 'a' - 'A';
|
||||
if (b >= 'A')
|
||||
b -= ('A' - 10);
|
||||
else
|
||||
b -= '0';
|
||||
|
||||
decoded += char(16 * a + b);
|
||||
src += 3;
|
||||
} else if (*src == '+') {
|
||||
decoded += ' ';
|
||||
*src++;
|
||||
} else {
|
||||
decoded += *src;
|
||||
*src++;
|
||||
}
|
||||
}
|
||||
decoded += '\0';
|
||||
|
||||
return decoded;
|
||||
}
|
||||
|
||||
void WiFiManager::resetSettings() {
|
||||
DEBUG_WM(F("settings invalidated"));
|
||||
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);
|
||||
}
|
||||
|
||||
void WiFiManager::setTimeout(unsigned long seconds) {
|
||||
timeout = seconds * 1000;
|
||||
setConfigPortalTimeout(seconds);
|
||||
}
|
||||
|
||||
void WiFiManager::setConfigPortalTimeout(unsigned long seconds) {
|
||||
_configPortalTimeout = seconds * 1000;
|
||||
}
|
||||
|
||||
void WiFiManager::setConnectTimeout(unsigned long seconds) {
|
||||
_connectTimeout = seconds * 1000;
|
||||
}
|
||||
|
||||
void WiFiManager::setDebugOutput(boolean debug) {
|
||||
@@ -337,58 +339,68 @@ void WiFiManager::handleRoot() {
|
||||
|
||||
/** Wifi config page handler */
|
||||
void WiFiManager::handleWifi(boolean scan) {
|
||||
server->sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
server->sendHeader("Pragma", "no-cache");
|
||||
server->sendHeader("Expires", "-1");
|
||||
server->setContentLength(CONTENT_LENGTH_UNKNOWN);
|
||||
server->send(200, "text/html", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
|
||||
server->setContentLength(CONTENT_LENGTH_UNKNOWN);
|
||||
|
||||
String head = FPSTR(HTTP_HEAD);
|
||||
head.replace("{v}", "Config ESP");
|
||||
server->sendContent(head);
|
||||
server->sendContent_P(HTTP_SCRIPT);
|
||||
server->sendContent_P(HTTP_STYLE);
|
||||
server->sendContent_P(HTTP_HEAD_END);
|
||||
String page = FPSTR(HTTP_HEAD);
|
||||
page.replace("{v}", "Config ESP");
|
||||
page += FPSTR(HTTP_SCRIPT);
|
||||
page += FPSTR(HTTP_STYLE);
|
||||
page += FPSTR(HTTP_HEAD_END);
|
||||
|
||||
if (scan) {
|
||||
int n = WiFi.scanNetworks();
|
||||
DEBUG_WM(F("Scan done"));
|
||||
if (n == 0) {
|
||||
DEBUG_WM(F("No networks found"));
|
||||
server->sendContent("No networks found. Refresh to scan again.");
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
DEBUG_WM(WiFi.SSID(i));
|
||||
DEBUG_WM(WiFi.RSSI(i));
|
||||
int quality = getRSSIasQuality(WiFi.RSSI(i));
|
||||
page += F("No networks found. Refresh to scan again.");
|
||||
} else {
|
||||
//sort networks
|
||||
int indices[n];
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
indices[i] = i;
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = i + 1; j < n; j++) {
|
||||
if (WiFi.RSSI(indices[j]) > WiFi.RSSI(indices[i])) {
|
||||
//int temp = indices[j];
|
||||
//indices[j] = indices[i];
|
||||
//indices[i] = temp;
|
||||
std::swap(indices[i], indices[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//display networks in page
|
||||
for (int i = 0; i < n; i++) {
|
||||
DEBUG_WM(WiFi.SSID(indices[i]));
|
||||
DEBUG_WM(WiFi.RSSI(indices[i]));
|
||||
int quality = getRSSIasQuality(WiFi.RSSI(indices[i]));
|
||||
|
||||
if (_minimumQuality == -1 || _minimumQuality < quality) {
|
||||
String item = FPSTR(HTTP_ITEM);
|
||||
String rssiQ;
|
||||
rssiQ += quality;
|
||||
item.replace("{v}", WiFi.SSID(i));
|
||||
item.replace("{v}", WiFi.SSID(indices[i]));
|
||||
item.replace("{r}", rssiQ);
|
||||
if (WiFi.encryptionType(i) != ENC_TYPE_NONE) {
|
||||
item.replace("{i}", FPSTR(HTTP_ITEM_PADLOCK));
|
||||
if (WiFi.encryptionType(indices[i]) != ENC_TYPE_NONE) {
|
||||
item.replace("{i}", "l");
|
||||
} else {
|
||||
item.replace("{i}", "");
|
||||
}
|
||||
//DEBUG_WM(item);
|
||||
server->sendContent(item);
|
||||
page += item;
|
||||
delay(0);
|
||||
} else {
|
||||
DEBUG_WM(F("Skipping due to quality"));
|
||||
}
|
||||
|
||||
}
|
||||
server->sendContent("<br/>");
|
||||
page += "<br/>";
|
||||
}
|
||||
}
|
||||
|
||||
server->sendContent_P(HTTP_FORM_START);
|
||||
page += FPSTR(HTTP_FORM_START);
|
||||
char parLength[2];
|
||||
// add the extra parameters to the form
|
||||
for (int i = 0; i < _paramsCount; i++) {
|
||||
@@ -404,10 +416,10 @@ void WiFiManager::handleWifi(boolean scan) {
|
||||
pitem.replace("{l}", parLength);
|
||||
pitem.replace("{v}", _params[i]->getValue());
|
||||
|
||||
server->sendContent(pitem);
|
||||
page += pitem;
|
||||
}
|
||||
if (_params[0] != NULL) {
|
||||
server->sendContent_P("<br/>");
|
||||
page += "<br/>";
|
||||
}
|
||||
|
||||
if (_sta_static_ip) {
|
||||
@@ -419,7 +431,7 @@ void WiFiManager::handleWifi(boolean scan) {
|
||||
item.replace("{l}", "15");
|
||||
item.replace("{v}", _sta_static_ip.toString());
|
||||
|
||||
server->sendContent(item);
|
||||
page += item;
|
||||
|
||||
item = FPSTR(HTTP_FORM_PARAM);
|
||||
item.replace("{i}", "gw");
|
||||
@@ -428,7 +440,7 @@ void WiFiManager::handleWifi(boolean scan) {
|
||||
item.replace("{l}", "15");
|
||||
item.replace("{v}", _sta_static_gw.toString());
|
||||
|
||||
server->sendContent(item);
|
||||
page += item;
|
||||
|
||||
item = FPSTR(HTTP_FORM_PARAM);
|
||||
item.replace("{i}", "sn");
|
||||
@@ -437,15 +449,18 @@ void WiFiManager::handleWifi(boolean scan) {
|
||||
item.replace("{l}", "15");
|
||||
item.replace("{v}", _sta_static_sn.toString());
|
||||
|
||||
server->sendContent(item);
|
||||
page += item;
|
||||
|
||||
server->sendContent_P("<br/>");
|
||||
page += "<br/>";
|
||||
}
|
||||
|
||||
server->sendContent_P(HTTP_FORM_END);
|
||||
server->sendContent_P(HTTP_SCAN_LINK);
|
||||
server->sendContent_P(HTTP_END);
|
||||
server->client().stop();
|
||||
page += FPSTR(HTTP_FORM_END);
|
||||
page += FPSTR(HTTP_SCAN_LINK);
|
||||
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
server->send(200, "text/html", page);
|
||||
|
||||
|
||||
DEBUG_WM(F("Sent config page"));
|
||||
}
|
||||
@@ -455,8 +470,8 @@ void WiFiManager::handleWifiSave() {
|
||||
DEBUG_WM(F("WiFi save"));
|
||||
|
||||
//SAVE/connect here
|
||||
_ssid = urldecode(server->arg("s").c_str());
|
||||
_pass = urldecode(server->arg("p").c_str());
|
||||
_ssid = server->arg("s").c_str();
|
||||
_pass = server->arg("p").c_str();
|
||||
|
||||
//parameters
|
||||
for (int i = 0; i < _paramsCount; i++) {
|
||||
@@ -464,7 +479,7 @@ void WiFiManager::handleWifiSave() {
|
||||
break;
|
||||
}
|
||||
//read parameter
|
||||
String value = urldecode(server->arg(_params[i]->getID()).c_str());
|
||||
String value = server->arg(_params[i]->getID()).c_str();
|
||||
//store it in array
|
||||
value.toCharArray(_params[i]->_value, _params[i]->_length);
|
||||
DEBUG_WM(F("Parameter"));
|
||||
@@ -492,23 +507,15 @@ void WiFiManager::handleWifiSave() {
|
||||
optionalIPFromString(&_sta_static_sn, sn.c_str());
|
||||
}
|
||||
|
||||
server->sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
server->sendHeader("Pragma", "no-cache");
|
||||
server->sendHeader("Expires", "-1");
|
||||
server->setContentLength(CONTENT_LENGTH_UNKNOWN);
|
||||
server->send(200, "text/html", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
|
||||
String page = FPSTR(HTTP_HEAD);
|
||||
page.replace("{v}", "Credentials Saved");
|
||||
page += FPSTR(HTTP_SCRIPT);
|
||||
page += FPSTR(HTTP_STYLE);
|
||||
page += FPSTR(HTTP_HEAD_END);
|
||||
page += FPSTR(HTTP_SAVED);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
String head = FPSTR(HTTP_HEAD);
|
||||
head.replace("{v}", "Credentials Saved");
|
||||
server->sendContent(head);
|
||||
server->sendContent_P(HTTP_SCRIPT);
|
||||
server->sendContent_P(HTTP_STYLE);
|
||||
server->sendContent_P(HTTP_HEAD_END);
|
||||
|
||||
server->sendContent_P(HTTP_SAVED);
|
||||
|
||||
server->sendContent_P(HTTP_END);
|
||||
server->client().stop();
|
||||
server->send(200, "text/html", page);
|
||||
|
||||
DEBUG_WM(F("Sent wifi save page"));
|
||||
|
||||
@@ -531,9 +538,12 @@ void WiFiManager::handleInfo() {
|
||||
page += F("<dt>Flash Chip ID</dt><dd>");
|
||||
page += ESP.getFlashChipId();
|
||||
page += F("</dd>");
|
||||
page += F("<dt>Flash Size</dt><dd>");
|
||||
page += F("<dt>IDE Flash Size</dt><dd>");
|
||||
page += ESP.getFlashChipSize();
|
||||
page += F(" bytes</dd>");
|
||||
page += F("<dt>Real Flash Size</dt><dd>");
|
||||
page += ESP.getFlashChipRealSize();
|
||||
page += F(" bytes</dd>");
|
||||
page += F("<dt>Soft AP IP</dt><dd>");
|
||||
page += WiFi.softAPIP().toString();
|
||||
page += F("</dd>");
|
||||
|
||||
+30
-23
@@ -21,16 +21,16 @@
|
||||
|
||||
const char HTTP_200[] PROGMEM = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
|
||||
const char HTTP_HEAD[] PROGMEM = "<!DOCTYPE html><html lang=\"en\"><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\"/><title>{v}</title>";
|
||||
const char HTTP_STYLE[] PROGMEM = "<style>div,input{padding:5px;font-size:1em;} input{width:95%;} body{text-align:center;font-family:verdana;} button{border:0;border-radius:0.3rem;background-color:#1fa3ec;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;}</style>";
|
||||
const char HTTP_STYLE[] PROGMEM = "<style>.c{text-align: center;} div,input{padding:5px;font-size:1em;} input{width:95%;} body{text-align: center;font-family:verdana;} button{border:0;border-radius:0.3rem;background-color:#1fa3ec;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;} .q{float: right;width: 64px;text-align: right;} .l{background: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAALVBMVEX///8EBwfBwsLw8PAzNjaCg4NTVVUjJiZDRUUUFxdiZGSho6OSk5Pg4eFydHTCjaf3AAAAZElEQVQ4je2NSw7AIAhEBamKn97/uMXEGBvozkWb9C2Zx4xzWykBhFAeYp9gkLyZE0zIMno9n4g19hmdY39scwqVkOXaxph0ZCXQcqxSpgQpONa59wkRDOL93eAXvimwlbPbwwVAegLS1HGfZAAAAABJRU5ErkJggg==\") no-repeat left center;background-size: 1em;}</style>";
|
||||
const char HTTP_SCRIPT[] PROGMEM = "<script>function c(l){document.getElementById('s').value=l.innerText||l.textContent;document.getElementById('p').focus();}</script>";
|
||||
const char HTTP_HEAD_END[] PROGMEM = "</head><body><div style='text-align: left; display: inline-block;'>";
|
||||
const char HTTP_HEAD_END[] PROGMEM = "</head><body><div style='text-align:left;display:inline-block;min-width:260px;'>";
|
||||
const char HTTP_PORTAL_OPTIONS[] PROGMEM = "<form action=\"/wifi\" method=\"get\"><button>Configure WiFi</button></form><br/><form action=\"/0wifi\" method=\"get\"><button>Configure WiFi (No Scan)</button></form><br/><form action=\"/i\" method=\"get\"><button>Info</button></form><br/><form action=\"/r\" method=\"post\"><button>Reset</button></form>";
|
||||
const char HTTP_ITEM[] PROGMEM = "<div><a href='#' onclick='c(this)'>{v}</a> {r}% {i}</div>";
|
||||
const char HTTP_ITEM_PADLOCK[] PROGMEM = "<img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAALVBMVEX///8EBwfBwsLw8PAzNjaCg4NTVVUjJiZDRUUUFxdiZGSho6OSk5Pg4eFydHTCjaf3AAAAZElEQVQ4je2NSw7AIAhEBamKn97/uMXEGBvozkWb9C2Zx4xzWykBhFAeYp9gkLyZE0zIMno9n4g19hmdY39scwqVkOXaxph0ZCXQcqxSpgQpONa59wkRDOL93eAXvimwlbPbwwVAegLS1HGfZAAAAABJRU5ErkJggg==' width='13px'/>";
|
||||
const char HTTP_ITEM[] PROGMEM = "<div><a href='#' onclick='c(this)'>{v}</a> <span class='q {i}'>{r}%</span></div>";
|
||||
//const char HTTP_ITEM_PADLOCK[] PROGMEM = "<img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAALVBMVEX///8EBwfBwsLw8PAzNjaCg4NTVVUjJiZDRUUUFxdiZGSho6OSk5Pg4eFydHTCjaf3AAAAZElEQVQ4je2NSw7AIAhEBamKn97/uMXEGBvozkWb9C2Zx4xzWykBhFAeYp9gkLyZE0zIMno9n4g19hmdY39scwqVkOXaxph0ZCXQcqxSpgQpONa59wkRDOL93eAXvimwlbPbwwVAegLS1HGfZAAAAABJRU5ErkJggg==' width='13px'/>";
|
||||
const char HTTP_FORM_START[] PROGMEM = "<form method='get' action='wifisave'><input id='s' name='s' length=32 placeholder='SSID'><br/><input id='p' name='p' length=64 type='password' placeholder='password'><br/>";
|
||||
const char HTTP_FORM_PARAM[] PROGMEM = "<br/><input id='{i}' name='{n}' length={l} placeholder='{p}' value='{v}'>";
|
||||
const char HTTP_FORM_END[] PROGMEM = "<br/><button type='submit'>save</button></form>";
|
||||
const char HTTP_SCAN_LINK[] PROGMEM = "<br/><div style=\"text-align: center\"><a href=\"/wifi\">Scan</a></div>";
|
||||
const char HTTP_SCAN_LINK[] PROGMEM = "<br/><div class=\"c\"><a href=\"/wifi\">Scan</a></div>";
|
||||
|
||||
const char HTTP_SAVED[] PROGMEM = "<div>Credentials Saved<br />Trying to connect ESP to network.<br />If it fails reconnect to AP to try again</div>";
|
||||
const char HTTP_END[] PROGMEM = "</div></body></html>";
|
||||
@@ -66,20 +66,21 @@ class WiFiManager
|
||||
//if you want to always start the config portal, without trying to connect first
|
||||
boolean startConfigPortal(char const *apName, char const *apPassword = NULL);
|
||||
|
||||
String getSSID();
|
||||
String getPassword();
|
||||
|
||||
// get the AP name of the config portal, so it can be used in the callback
|
||||
String getConfigPortalSSID();
|
||||
|
||||
void resetSettings();
|
||||
//for convenience
|
||||
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
|
||||
//in seconds setConfigPortalTimeout is a new name for setTimeout
|
||||
void setConfigPortalTimeout(unsigned long seconds);
|
||||
void setTimeout(unsigned long seconds);
|
||||
|
||||
//sets timeout for which to attempt connecting, usefull if you get a lot of failed connects
|
||||
void setConnectTimeout(unsigned long seconds);
|
||||
|
||||
|
||||
void setDebugOutput(boolean debug);
|
||||
//defaults to not showing anything under 8% signal quality if called
|
||||
void setMinimumSignalQuality(int quality = 8);
|
||||
@@ -95,40 +96,46 @@ class WiFiManager
|
||||
void addParameter(WiFiManagerParameter *p);
|
||||
//if this is set, it will exit after config, even if connection is unsucessful.
|
||||
void setBreakAfterConfig(boolean shouldBreak);
|
||||
//if this is set, try WPS setup when starting (this will delay config portal for up to 2 mins)
|
||||
|
||||
private:
|
||||
std::unique_ptr<DNSServer> dnsServer;
|
||||
std::unique_ptr<ESP8266WebServer> server;
|
||||
|
||||
const int WM_DONE = 0;
|
||||
const int WM_WAIT = 10;
|
||||
//const int WM_DONE = 0;
|
||||
//const int WM_WAIT = 10;
|
||||
|
||||
//const String HTTP_HEAD = "<!DOCTYPE html><html lang=\"en\"><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/><title>{v}</title>";
|
||||
|
||||
void setupConfigPortal();
|
||||
void startWPS();
|
||||
|
||||
int _eepromStart;
|
||||
const char* _apName = "no-net";
|
||||
const char* _apPassword = NULL;
|
||||
String _ssid = "";
|
||||
String _pass = "";
|
||||
unsigned long timeout = 0;
|
||||
unsigned long start = 0;
|
||||
const char* _apName = "no-net";
|
||||
const char* _apPassword = NULL;
|
||||
String _ssid = "";
|
||||
String _pass = "";
|
||||
unsigned long _configPortalTimeout = 0;
|
||||
unsigned long _connectTimeout = 0;
|
||||
unsigned long _configPortalStart = 0;
|
||||
|
||||
IPAddress _ap_static_ip;
|
||||
IPAddress _ap_static_gw;
|
||||
IPAddress _ap_static_sn;
|
||||
IPAddress _sta_static_ip;
|
||||
IPAddress _sta_static_gw;
|
||||
IPAddress _sta_static_sn;
|
||||
int _paramsCount = 0;
|
||||
int _minimumQuality = -1;
|
||||
|
||||
int _paramsCount = 0;
|
||||
int _minimumQuality = -1;
|
||||
boolean _shouldBreakAfterConfig = false;
|
||||
boolean _tryWPS = false;
|
||||
|
||||
//String getEEPROMString(int start, int len);
|
||||
//void setEEPROMString(int start, int len, String string);
|
||||
|
||||
int status = WL_IDLE_STATUS;
|
||||
int connectWifi(String ssid, String pass);
|
||||
uint8_t waitForConnectResult();
|
||||
|
||||
void handleRoot();
|
||||
void handleWifi(boolean scan);
|
||||
@@ -138,7 +145,7 @@ class WiFiManager
|
||||
void handleNotFound();
|
||||
void handle204();
|
||||
boolean captivePortal();
|
||||
|
||||
|
||||
// DNS server
|
||||
const byte DNS_PORT = 53;
|
||||
|
||||
|
||||
@@ -1,14 +1,32 @@
|
||||
<!DOCTYPE html><html lang=\"en\"><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\"/><title>{v}</title>
|
||||
<style>.c{text-align: center} div,input{padding:5px;font-size:1em;} input{width:95%;} body{text-align: center;font-family:verdana;} button{border:0;border-radius:0.3rem;background-color:#1fa3ec;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;}</style>
|
||||
<style>.c{text-align: center;} div,input{padding:5px;font-size:1em;} input{width:95%;} body{text-align: center;font-family:verdana;} button{border:0;border-radius:0.3rem;background-color:#1fa3ec;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;} .q{float: right;width: 64px;text-align: right;} .l{background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAALVBMVEX///8EBwfBwsLw8PAzNjaCg4NTVVUjJiZDRUUUFxdiZGSho6OSk5Pg4eFydHTCjaf3AAAAZElEQVQ4je2NSw7AIAhEBamKn97/uMXEGBvozkWb9C2Zx4xzWykBhFAeYp9gkLyZE0zIMno9n4g19hmdY39scwqVkOXaxph0ZCXQcqxSpgQpONa59wkRDOL93eAXvimwlbPbwwVAegLS1HGfZAAAAABJRU5ErkJggg==") no-repeat left center;background-size: 1em;}</style>
|
||||
|
||||
<script>function c(l){document.getElementById('s').value=l.innerText||l.textContent;document.getElementById('p').focus();}</script>
|
||||
</head><body><div style="text-align: left; display: inline-block;">
|
||||
</head><body><div style="text-align:left;display:inline-block;min-width:260px;">
|
||||
<!--
|
||||
<div><a href='#' onclick='c(this)'>{v}</a> {r}% {i}</div>
|
||||
<div><a href='#' onclick='c(this)'>{v}</a> 100% <img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAKCAMAAAC+Ge+yAAAACVBMVEUAAAC7u7v///9etNz6AAAAI0lEQVQI133GsQ3AMAAEoXv2H9qNJacKFbEaWTQJ+uQB/nMdEaYAXeJkZ9AAAAAASUVORK5CYII='/></div>
|
||||
<div><a href='#' onclick='c(this)'>Vila17</a> 95% <img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAMAAAC67D+PAAAADFBMVEUAAAAAtgD///8AAADV1YIHAAAAA3RSTlMAAAD6dsTeAAAAHUlEQVR4AWMAAmYgYGBkArHAAMoEYnQmMxSQywQAKvMA3+mlSFAAAAAASUVORK5CYII='/></div>
|
||||
<div><a href='#'>LilRidingHoodz</a> 100% <img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAMAAAC67D+PAAAABlBMVEUAAAD///+l2Z/dAAAAIklEQVR4AWNgZGRkAAIQBURQDEZAgM5kgAJGEAQDwkxkbQAOhgBBk64+mQAAAABJRU5ErkJggg=='/></div>
|
||||
<div><a href='#'>LilRid</a> 100% <img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAMAAAC67D+PAAAABlBMVEUAAAD///+l2Z/dAAAAIklEQVR4AWNgZGRkAAIQBURQDEZAgM5kgAJGEAQDwkxkbQAOhgBBk64+mQAAAABJRU5ErkJggg=='/></div>
|
||||
<div><a href='#'>Marcelica</a> 100% <img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAMAAAC67D+PAAAACVBMVEUAAAC7u7v///9etNz6AAAAJ0lEQVR4AY3GsREAIBSDUD77D63x4tlKw0MdmD0ijTO9f6SFnv7YXB4qAIVn0xoMAAAAAElFTkSuQmCC'/></div>
|
||||
<div><a href='#'>PMica</a> 110% <img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAALVBMVEX///8EBwfBwsLw8PAzNjaCg4NTVVUjJiZDRUUUFxdiZGSho6OSk5Pg4eFydHTCjaf3AAAAZElEQVQ4je2NSw7AIAhEBamKn97/uMXEGBvozkWb9C2Zx4xzWykBhFAeYp9gkLyZE0zIMno9n4g19hmdY39scwqVkOXaxph0ZCXQcqxSpgQpONa59wkRDOL93eAXvimwlbPbwwVAegLS1HGfZAAAAABJRU5ErkJggg==' width="13px"/></div>
|
||||
-->
|
||||
|
||||
<style>
|
||||
.q{float: right;width: 64px;text-align: right;}
|
||||
.l{background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAALVBMVEX///8EBwfBwsLw8PAzNjaCg4NTVVUjJiZDRUUUFxdiZGSho6OSk5Pg4eFydHTCjaf3AAAAZElEQVQ4je2NSw7AIAhEBamKn97/uMXEGBvozkWb9C2Zx4xzWykBhFAeYp9gkLyZE0zIMno9n4g19hmdY39scwqVkOXaxph0ZCXQcqxSpgQpONa59wkRDOL93eAXvimwlbPbwwVAegLS1HGfZAAAAABJRU5ErkJggg==") no-repeat left center;background-size: 1em;}
|
||||
</style>
|
||||
|
||||
<div><a href='#' onclick='c(this)'>{v}</a> <span class="q {i}">{r}%</span></div>
|
||||
<div><a href='#'>PMisa</a> <span class="q l">100%</span> </div>
|
||||
<div><a href='#'>Dragos_Networks</a> <span class="q l">10%</span> </div>
|
||||
<div><a href='#'>PMisa</a> <span class="q l">8%</span> </div>
|
||||
|
||||
|
||||
|
||||
<br/>
|
||||
|
||||
|
||||
<form method='get' action='wifisave'><input id='s' name='s' length=32 placeholder='SSID'><br/><input id='p' name='p' length=64 placeholder='password'><br/><button type='submit'>save</button></form>
|
||||
<br/><div></div>
|
||||
<br/>
|
||||
|
||||
+2
-3
@@ -18,8 +18,8 @@ getSSID KEYWORD2
|
||||
getPassword KEYWORD2
|
||||
getConfigPortalSSID KEYWORD2
|
||||
resetSettings KEYWORD2
|
||||
urldecode KEYWORD2
|
||||
setTimeout KEYWORD2
|
||||
setConfigPortalTimeout KEYWORD2
|
||||
setConnectTimeout KEYWORD2
|
||||
setDebugOutput KEYWORD2
|
||||
setMinimumSignalQuality KEYWORD2
|
||||
setAPStaticIPConfig KEYWORD2
|
||||
@@ -27,7 +27,6 @@ setSTAStaticIPConfig KEYWORD2
|
||||
setAPCallback KEYWORD2
|
||||
setSaveConfigCallback KEYWORD2
|
||||
addParameter KEYWORD2
|
||||
|
||||
getID KEYWORD2
|
||||
getValue KEYWORD2
|
||||
getPlaceholder KEYWORD2
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "WifiManager",
|
||||
"keywords": "wifi, wi-fi",
|
||||
"description": "ESP8266 WiFi Connection manager with fallback web configuration portal **USE version 0.6 together with stable 2.0.0 ESP8266 core for Arduino and use 0.7 for core 2.1.0.rc2 or newer**",
|
||||
"description": "ESP8266 WiFi Connection manager with fallback web configuration portal",
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
@@ -9,5 +9,5 @@
|
||||
},
|
||||
"frameworks": "arduino",
|
||||
"platforms": "espressif",
|
||||
"version": "0.8"
|
||||
"version": "0.10"
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
name=WiFiManager
|
||||
version=0.8
|
||||
version=0.10
|
||||
author=tzapu
|
||||
maintainer=tzapu
|
||||
sentence=ESP8266 WiFi Connection manager with fallback web configuration portal
|
||||
paragraph=Library for configuring ESP8266 modules WiFi credentials at runtime. **USE version 0.6 together with stable 2.0.0 ESP8266 core for Arduino and use 0.7 for core 2.1.0.rc2 or newer**
|
||||
paragraph=Library for configuring ESP8266 modules WiFi credentials at runtime.
|
||||
category=Communication
|
||||
url=https://github.com/tzapu/WiFiManager.git
|
||||
architectures=esp8266
|
||||
|
||||
Reference in New Issue
Block a user