Compare commits

...
17 Commits
Author SHA1 Message Date
Alex Tudorache 99f37db88e Merge branch 'master' of https://github.com/tzapu/WiFiManager 2016-01-04 16:48:33 +02:00
Alex Tudorache 2ad6d0897c changed category
fixed keywords
2016-01-04 16:48:17 +02:00
Alex Tudorache caa808c265 changed category 2016-01-04 16:42:35 +02:00
Alex Tudorache d8683d9f50 updated to 0.5 2016-01-04 16:32:32 +02:00
Alex Tudorache 1a58897ab4 added some more thanks 2016-01-02 09:49:47 +02:00
tzapu 7ba1f3ada5 Merge pull request #41 from domonetic/patch-4
add library.json
thank you
2016-01-02 09:44:44 +02:00
tzapu e6cbb8fa05 Merge pull request #40 from domonetic/patch-5
add library.properties
THANK YOU, you are amazing
2016-01-02 09:44:00 +02:00
tzapu 81d48d7612 Merge pull request #39 from domonetic/patch-3
add keywords.txt 
THANK YOU GUYS
2016-01-02 09:42:41 +02:00
Maximiliano Duarte ab23ca7b18 change category 2015-12-31 09:53:35 -03:00
Maximiliano Duarte 94eef239eb change space for tabs 2015-12-30 12:49:53 -03:00
Maximiliano Duarte 30f5a220ce add library.properties
to standardize the library and appear in Library Manager
2015-12-30 12:16:42 -03:00
Maximiliano Duarte 9350856d33 add library.json
to standardize the library and appear in Library Manager
2015-12-30 12:14:22 -03:00
Maximiliano Duarte a69c5e2b93 add keywords.txt
to standardize the library and appear in Library Manager
2015-12-30 12:12:57 -03:00
Alex Tudorache 777c2fab1b presentation tweaks 2015-12-28 18:07:02 +02:00
Alex Tudorache ec1a55bffc new padlock icon 2015-12-28 14:32:36 +02:00
Alex Tudorache ffdc117a6e added AP quality
added padlock for secured networks
moved more stuff to PROGMEM
2015-12-27 11:17:29 +02:00
Alex Tudorache 44419e10a2 moved most stuff to PROGMEM
added warning for invalid password
2015-12-23 18:15:58 +02:00
6 changed files with 182 additions and 75 deletions
+8 -3
View File
@@ -80,7 +80,8 @@ Also see examples.
### Password protect the configuration Access Point
You can and should password protect the configuration access point. Simply add the password as a second parameter to `autoConnect`.
A short password seems to have unpredictable results so use one that's around 8 characters or more in length.
```
The guidelines are that a wifi password must consist of 8 to 63 ASCII-encoded characters in the range of 32 to 126 (decimal)
```cpp
wifiManager.autoConnect("AutoConnectAP", "password")
```
@@ -120,14 +121,18 @@ This will set your captive portal to a specific IP should you need/want such a f
wifiManager.setAPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
```
### Contributions and thanks
The support and help I got from the community has been nothing short of fenomenal. I can't thank you guys enough. This is my first real attept in developing open source stuff and I must say, now I understand why people are so dedicated to it, it is because of all the wonderful people involved.
__THANK YOU__
[Maximiliano Duarte](https://github.com/domonetic)
[alltheblinkythings](https://github.com/alltheblinkythings)
[Niklas Wall](https://github.com/niklaswall)
[Jakub Piasecki](https://github.com/zaporylie)
[Maximiliano Duarte](https://github.com/domonetic)
[Peter Allan](https://github.com/alwynallan)
[John Little](https://github.com/j0hnlittle)
Executable → Regular
+84 -55
View File
@@ -28,29 +28,35 @@ void WiFiManager::begin(char const *apName, char const *apPasswd) {
dnsServer.reset(new DNSServer());
server.reset(new ESP8266WebServer(80));
DEBUG_PRINT("");
DEBUG_PRINT(F(""));
_apName = apName;
_apPasswd = apPasswd;
start = millis();
DEBUG_PRINT("Configuring access point... ");
DEBUG_PRINT(F("Configuring access point... "));
DEBUG_PRINT(_apName);
if (_apPasswd != NULL)
if (_apPasswd != NULL) {
if(strlen(_apPasswd) < 8 || strlen(_apPasswd) > 63) {
// fail passphrase to short or long!
DEBUG_PRINT(F("Invalid AccessPoint password"));
}
DEBUG_PRINT(_apPasswd);
}
//optional soft ip config
if (_ip) {
DEBUG_PRINT("Custom IP/GW/Subnet");
DEBUG_PRINT(F("Custom IP/GW/Subnet"));
WiFi.softAPConfig(_ip, _gw, _sn);
}
if (_apPasswd != NULL)
if (_apPasswd != NULL) {
WiFi.softAP(_apName, _apPasswd);//password option
else
} else {
WiFi.softAP(_apName);
}
delay(500); // Without delay I've seen the IP address blank
DEBUG_PRINT("AP IP address: ");
DEBUG_PRINT(F("AP IP address: "));
DEBUG_PRINT(WiFi.softAPIP());
/* Setup the DNS server redirecting all the domains to the apIP */
@@ -66,7 +72,7 @@ void WiFiManager::begin(char const *apName, char const *apPasswd) {
server->on("/fwlink", std::bind(&WiFiManager::handleRoot, this)); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler.
server->onNotFound (std::bind(&WiFiManager::handleNotFound, this));
server->begin(); // Web server start
DEBUG_PRINT("HTTP server started");
DEBUG_PRINT(F("HTTP server started"));
}
boolean WiFiManager::autoConnect() {
@@ -79,8 +85,8 @@ boolean WiFiManager::autoConnect(char const *apName) {
}
boolean WiFiManager::autoConnect(char const *apName, char const *apPasswd) {
DEBUG_PRINT("");
DEBUG_PRINT("AutoConnect");
DEBUG_PRINT(F(""));
DEBUG_PRINT(F("AutoConnect"));
// read eeprom for ssid and pass
String ssid = getSSID();
@@ -93,7 +99,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPasswd) {
connectWifi(ssid, pass);
int s = WiFi.status();
if (s == WL_CONNECTED) {
DEBUG_PRINT("IP Address:");
DEBUG_PRINT(F("IP Address:"));
DEBUG_PRINT(WiFi.localIP());
//connected
return true;
@@ -119,14 +125,14 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPasswd) {
if(connect) {
delay(2000);
DEBUG_PRINT("Connecting to new AP");
DEBUG_PRINT(F("Connecting to new AP"));
connect = false;
//ssid = getSSID();
//pass = getPassword();
connectWifi(_ssid, _pass);
int s = WiFi.status();
if (s != WL_CONNECTED) {
DEBUG_PRINT("Failed to connect.");
DEBUG_PRINT(F("Failed to connect."));
//not connected, should retry everything
//ESP.reset();
//delay(1000);
@@ -148,7 +154,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPasswd) {
void WiFiManager::connectWifi(String ssid, String pass) {
DEBUG_PRINT("Connecting as wifi client...");
DEBUG_PRINT(F("Connecting as wifi client..."));
//WiFi.disconnect();
WiFi.begin(ssid.c_str(), pass.c_str());
int connRes = WiFi.waitForConnectResult();
@@ -159,9 +165,9 @@ void WiFiManager::connectWifi(String ssid, String pass) {
String WiFiManager::getSSID() {
if (_ssid == "") {
DEBUG_PRINT("Reading EEPROM SSID");
DEBUG_PRINT(F("Reading SSID"));
_ssid = WiFi.SSID();//getEEPROMString(0, 32);
DEBUG_PRINT("SSID: ");
DEBUG_PRINT(F("SSID: "));
DEBUG_PRINT(_ssid);
}
return _ssid;
@@ -169,7 +175,7 @@ String WiFiManager::getSSID() {
String WiFiManager::getPassword() {
if (_pass == "") {
DEBUG_PRINT("Reading EEPROM Password");
DEBUG_PRINT(F("Reading Password"));
_pass = WiFi.psk();//getEEPROMString(32, 64);
DEBUG_PRINT("Password: " + _pass);
//DEBUG_PRINT(_pass);
@@ -199,7 +205,7 @@ void WiFiManager::setEEPROMString(int start, int len, String string) {
char c;
if (si < string.length()) {
c = string[si];
//DEBUG_PRINT("Wrote: ");
//DEBUG_PRINT(F("Wrote: ");
//DEBUG_PRINT(c);
} else {
c = 0;
@@ -208,7 +214,7 @@ void WiFiManager::setEEPROMString(int start, int len, String string) {
si++;
}
EEPROM.end();
DEBUG_PRINT("Wrote " + string);
DEBUG_PRINT(F("Wrote " + string);
}*/
String WiFiManager::urldecode(const char *src)
@@ -248,10 +254,10 @@ String WiFiManager::urldecode(const char *src)
}
void WiFiManager::resetSettings() {
//need to call it only after lib has been started with autoConnect or begin
DEBUG_PRINT("settings invalidated");
WiFi.disconnect();
delay(200);
DEBUG_PRINT(F("settings invalidated"));
DEBUG_PRINT(F("THIS MAY CAUSE AP NOT TO STRT UP PROPERLY. YOU NEED TO COMMENT IT OUT AFTER ERASING THE DATA."));
WiFi.disconnect(true);
//delay(200);
}
void WiFiManager::setTimeout(unsigned long seconds) {
@@ -271,7 +277,7 @@ void WiFiManager::setAPConfig(IPAddress ip, IPAddress gw, IPAddress sn) {
/** Handle root or redirect to captive portal */
void WiFiManager::handleRoot() {
DEBUG_PRINT("Handle root");
DEBUG_PRINT(F("Handle root"));
if (captivePortal()) { // If caprive portal redirect instead of displaying the page.
return;
}
@@ -284,18 +290,20 @@ void WiFiManager::handleRoot() {
String head = HTTP_HEAD;
head.replace("{v}", "Options");
server->sendContent(head);
server->sendContent(HTTP_SCRIPT);
server->sendContent(HTTP_STYLE);
server->sendContent(HTTP_HEAD_END);
server->sendContent_P(HTTP_SCRIPT);
server->sendContent_P(HTTP_STYLE);
server->sendContent_P(HTTP_HEAD_END);
//server->sendContent(F("<h1>"));
String title = "<h1>";
title += _apName;
title += "</h1>";
server->sendContent(title);
server->sendContent(F("<h3>WiFiManager</h3>"));
server->sendContent(
"<form action=\"/wifi\" method=\"get\"><button>Configure WiFi</button></form><br/>"
);
server->sendContent(
"<form action=\"/0wifi\" method=\"get\"><button>Configure WiFi (No Scan)</button></form>"
);
server->sendContent(HTTP_END);
server->sendContent_P(HTTP_PORTAL_OPTIONS);
server->sendContent_P(HTTP_END);
server->client().stop(); // Stop is needed because we sent no content length
}
@@ -311,40 +319,50 @@ void WiFiManager::handleWifi(bool scan) {
String head = HTTP_HEAD;
head.replace("{v}", "Config ESP");
server->sendContent(head);
server->sendContent(HTTP_SCRIPT);
server->sendContent(HTTP_STYLE);
server->sendContent(HTTP_HEAD_END);
server->sendContent_P(HTTP_SCRIPT);
server->sendContent_P(HTTP_STYLE);
server->sendContent_P(HTTP_HEAD_END);
if (scan) {
int n = WiFi.scanNetworks();
DEBUG_PRINT("Scan done");
DEBUG_PRINT(F("Scan done"));
if (n == 0) {
DEBUG_PRINT("No networks found");
server->sendContent("<div>No networks found. Refresh to scan again.</div>");
DEBUG_PRINT(F("No networks found"));
server->sendContent("No networks found. Refresh to scan again.");
}
else {
for (int i = 0; i < n; ++i)
{
DEBUG_PRINT(WiFi.SSID(i));
DEBUG_PRINT(WiFi.RSSI(i));
String item = HTTP_ITEM;
String item = FPSTR(HTTP_ITEM);
String rssiQ;
rssiQ += getRSSIasQuality(WiFi.RSSI(i));
item.replace("{v}", WiFi.SSID(i));
item.replace("{r}", rssiQ);
if(WiFi.encryptionType(i) != ENC_TYPE_NONE) {
item.replace("{i}", FPSTR(HTTP_ITEM_PADLOCK));
} else {
item.replace("{i}", "");
}
//DEBUG_PRINT(item);
server->sendContent(item);
yield();
delay(0);
}
server->sendContent("<br/>");
}
}
server->sendContent(HTTP_FORM);
server->sendContent(HTTP_END);
server->sendContent_P(HTTP_FORM);
server->sendContent_P(HTTP_END);
server->client().stop();
DEBUG_PRINT("Sent config page");
DEBUG_PRINT(F("Sent config page"));
}
/** Handle the WLAN save form and redirect to WLAN config page again */
void WiFiManager::handleWifiSave() {
DEBUG_PRINT("WiFi save");
DEBUG_PRINT(F("WiFi save"));
//SAVE/connect here
_ssid = urldecode(server->arg("s").c_str());
@@ -358,22 +376,22 @@ void WiFiManager::handleWifiSave() {
String head = HTTP_HEAD;
head.replace("{v}", "Credentials Saved");
server->sendContent(head);
server->sendContent(HTTP_SCRIPT);
server->sendContent(HTTP_STYLE);
server->sendContent(HTTP_HEAD_END);
server->sendContent_P(HTTP_SCRIPT);
server->sendContent_P(HTTP_STYLE);
server->sendContent_P(HTTP_HEAD_END);
server->sendContent(HTTP_SAVED);
server->sendContent_P(HTTP_SAVED);
server->sendContent(HTTP_END);
server->sendContent_P(HTTP_END);
server->client().stop();
DEBUG_PRINT("Sent wifi save page");
DEBUG_PRINT(F("Sent wifi save page"));
connect = true; //signal ready to connect/reset
}
void WiFiManager::handle204() {
DEBUG_PRINT("204 No Response");
DEBUG_PRINT(F("204 No Response"));
server->sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
server->sendHeader("Pragma", "no-cache");
server->sendHeader("Expires", "-1");
@@ -406,7 +424,7 @@ void WiFiManager::handleNotFound() {
/** Redirect to captive portal if we got a request for another domain. Return true in that case so the page handler do not try to handle the request again. */
boolean WiFiManager::captivePortal() {
if (!isIp(server->hostHeader()) ) {
DEBUG_PRINT("Request redirected to captive portal");
DEBUG_PRINT(F("Request redirected to captive portal"));
server->sendHeader("Location", String("http://") + toStringIp(server->client().localIP()), true);
server->send ( 302, "text/plain", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
server->client().stop(); // Stop is needed because we sent no content length
@@ -430,7 +448,18 @@ void WiFiManager::DEBUG_PRINT(Generic text) {
}
int WiFiManager::getRSSIasQuality(int RSSI) {
int quality = 0;
if(RSSI <= -100){
quality = 0;
}else if(RSSI >= -50){
quality = 100;
} else {
quality = 2 * (RSSI + 100);
}
return quality;
}
/** Is this an IP? */
boolean WiFiManager::isIp(String str) {
Executable → Regular
+33 -17
View File
@@ -20,6 +20,20 @@
#include <DNSServer.h>
#include <memory>
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\"/><title>{v}</title>";
const char HTTP_STYLE[] PROGMEM = "<style>div,input{padding:5px;font-size:1em;} input{width:95%;} body{text-align: center;} 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_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_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>";
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,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAKCAMAAAC+Ge+yAAAACVBMVEUAAAC7u7v///9etNz6AAAAI0lEQVQI133GsQ3AMAAEoXv2H9qNJacKFbEaWTQJ+uQB/nMdEaYAXeJkZ9AAAAAASUVORK5CYII='/>";
const char HTTP_FORM[] PROGMEM = "<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/><br/><button type='submit'>save</button></form>";
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>";
class WiFiManager
{
public:
@@ -53,16 +67,16 @@ private:
const int WM_DONE = 0;
const int WM_WAIT = 10;
const String HTTP_404 = "HTTP/1.1 404 Not Found\r\n\r\n";
const String HTTP_200 = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
//const char PROGMEM HTTP_404[] = "HTTP/1.1 404 Not Found\r\n\r\n";
//const String HTTP_200 = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
const String HTTP_HEAD = "<!DOCTYPE html><html lang=\"en\"><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/><title>{v}</title>";
const String HTTP_STYLE = "<style>div,input {margin-bottom: 5px;} body{width:200px;display:block;margin-left:auto;margin-right:auto;} button{padding:0.75rem 1rem;border:0;border-radius:0.317rem;background-color:#1fa3ec;color:#fff;line-height:1.5;cursor:pointer;}</style>";
const String HTTP_SCRIPT = "<script>function c(l){document.getElementById('s').value=l.innerText||l.textContent;document.getElementById('p').focus();}</script>";
const String HTTP_HEAD_END = "</head><body>";
const String HTTP_ITEM = "<div><a href='#' onclick='c(this)'>{v}</a></div>";
const String HTTP_FORM = "<form method='get' action='wifisave'><input id='s' name='s' length=32 placeholder='SSID'><input id='p' name='p' length=64 placeholder='password'><br/><button type='submit'>save</button></form>";
const String HTTP_SAVED = "<div>Credentials Saved<br />Trying to connect ESP to network.<br />If it fails reconnect to AP to try again</div>";
const String HTTP_END = "</body></html>";
//const String HTTP_STYLE = "<style>div,input {margin-bottom: 5px;} body{width:200px;display:block;margin-left:auto;margin-right:auto;} button{padding:0.75rem 1rem;border:0;border-radius:0.317rem;background-color:#1fa3ec;color:#fff;line-height:1.5;cursor:pointer;}</style>";
//const String HTTP_SCRIPT = "<script>function c(l){document.getElementById('s').value=l.innerText||l.textContent;document.getElementById('p').focus();}</script>";
//const String HTTP_HEAD_END = "</head><body>";
//const String HTTP_ITEM = "<div><a href='#' onclick='c(this)'>{v}</a></div>";
//const String HTTP_FORM = "<form method='get' action='wifisave'><input id='s' name='s' length=32 placeholder='SSID'><input id='p' name='p' length=64 placeholder='password'><br/><button type='submit'>save</button></form>";
//const String HTTP_SAVED = "<div>Credentials Saved<br />Trying to connect ESP to network.<br />If it fails reconnect to AP to try again</div>";
//const String HTTP_END = "</body></html>";
//const char HTTP_END[] PROGMEM = R"=====(
//</body></html>
//)=====";
@@ -71,16 +85,16 @@ private:
void begin(char const *apName);
void begin(char const *apName, char const *apPasswd);
int _eepromStart;
int _eepromStart;
const char* _apName = "no-net";
const char* _apPasswd = "no-net";
String _ssid = "";
String _pass = "";
const char* _apPasswd = NULL;
String _ssid = "";
String _pass = "";
unsigned long timeout = 0;
unsigned long start = 0;
IPAddress _ip;
IPAddress _gw;
IPAddress _sn;
IPAddress _ip;
IPAddress _gw;
IPAddress _sn;
String getEEPROMString(int start, int len);
void setEEPROMString(int start, int len, String string);
@@ -98,7 +112,9 @@ private:
// DNS server
const byte DNS_PORT = 53;
//helpers
int getRSSIasQuality(int RSSI);
boolean isIp(String str);
String toStringIp(IPAddress ip);
+29
View File
@@ -0,0 +1,29 @@
#######################################
# Syntax Coloring Map For WifiManager
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
WiFiManager KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
autoConnect KEYWORD2
getSSID KEYWORD2
getPassword KEYWORD2
resetSettings KEYWORD2
urldecode KEYWORD2
setTimeout KEYWORD2
setDebugOutput KEYWORD2
setAPConfig KEYWORD2
setAPCallback KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################
# LITERAL1
+19
View File
@@ -0,0 +1,19 @@
{
"name": "WifiManager",
"keywords": "wifi, wi-fi, ESP8266",
"description": "ESP8266 WiFi Connection manager with fallback web configuration portal",
"repository":
{
"type": "git",
"url": "https://github.com/tzapu/WiFiManager.git"
},
"authors":
{
"name": "tzapu",
"url": "http://tzapu.com"
},
"frameworks": "arduino",
"platforms": "esp8266"
"version": "0.5",
"architecture": "esp8266",
}
+9
View File
@@ -0,0 +1,9 @@
name=WiFiManager
version=0.5
author=tzapu
maintainer=tzapu
sentence=ESP8266 WiFi Connection manager with fallback web configuration portal
paragraph=Library for configuring ESP8266 modules WiFi credentials at runtime.
category=Communication
url=https://github.com/tzapu/WiFiManager.git
architectures=esp8266