From a209509d9843df1cc9dca202c076b0c23ad25e59 Mon Sep 17 00:00:00 2001 From: Alex T Date: Tue, 5 Apr 2016 09:28:13 +0300 Subject: [PATCH 01/15] 0.11 readme and ver bump --- README.md | 53 ++++++++++++++++++++++++++++++++++++++++------ library.json | 2 +- library.properties | 2 +- 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ce2e580..7bbd4dd 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ First attempt at a library. Lots more changes and fixes to do. Contributions are - ~~add to Arduino Library Manager~~ - ~~add to PlatformIO~~ - add multiple sets of network credentials -- allow users to customize CSS +- ~~allow users to customize CSS~~ ## Quick Start @@ -179,7 +179,7 @@ void loop() { ``` See example for a more complex version. [OnDemandConfigPortal](https://github.com/tzapu/WiFiManager/tree/master/examples/OnDemandConfigPortal) -### Custom Parameters +#### Custom Parameters You can use WiFiManager to collect more parameters than just SSID and password. This could be helpful for configuring stuff like MQTT host and port, [blynk](http://www.blynk.cc) or [emoncms](http://emoncms.org) tokens, just to name a few. **You are responsible for saving and loading these custom values.** The library just collects and displays the data for you as a convenience. @@ -198,32 +198,63 @@ Usage scenario would be: ```cpp mqtt_server = custom_mqtt_server.getValue(); ``` -This feature is a lot more involved than all the others, so here are some examples to fully show how it is done +This feature is a lot more involved than all the others, so here are some examples to fully show how it is done. +You should also take a look at adding custom HTML to your form. + - Save and load custom parameters to file system in json form [AutoConnectWithFSParameters](https://github.com/tzapu/WiFiManager/tree/master/examples/AutoConnectWithFSParameters) - *Save and load custom parameters to EEPROM* (not done yet) +#### Custom IP Configuration +You can set a custom IP for both AP (access point, config mode) and STA (station mode, client mode, normal project state) -### Custom Access Point IP Configuration +##### Custom Access Point IP Configuration This will set your captive portal to a specific IP should you need/want such a feature. Add the following snippet before `autoConnect()` ```cpp //set custom ip for portal wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); ``` -### Custom Station (client) Static IP Configuration +##### Custom Station (client) Static IP Configuration This will make use the specified IP configuration instead of using DHCP in station mode. ```cpp wifiManager.setSTAStaticIPConfig(IPAddress(192,168,0,99), IPAddress(192,168,0,1), IPAddress(255,255,255,0)); ``` There are a couple of examples in the examples folder that show you how to set a static IP and even how to configure it through the web configuration portal. +#### Custom HTML, CSS, Javascript +There are various ways in which you can inject custom HTML, CSS or Javascript into the configuration portal. +The options are: +- inject custom head element +You can use this to any html bit to the head of the configuration portal. If you add a `"); +``` +- inject a custom bit of html in the configuration form +```cpp +WiFiManagerParameter custom_text("

This is just a text paragraph

"); +wifiManager.addParameter(&custom_text); +``` +- inject a custom bit of html in a configuration form element +Just add the bit you want added as the last parameter to the custom parameter constructor. +```cpp +WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "iot.eclipse", 40, " readonly"); +``` + #### Filter Networks -If you would like to filter low signal quality networks you can tell WiFiManager to not show networks below an arbitrary quality %; +You can filter networks based on signal quality and show/hide duplicate networks. + +- If you would like to filter low signal quality networks you can tell WiFiManager to not show networks below an arbitrary quality %; ```cpp wifiManager.setMinimumSignalQuality(10); ``` will not show networks under 10% signal quality. If you omit the parameter it defaults to 8%; +- You can also remove or show duplicate networks (default is remove). +Use this function to show (or hide) all networks. +```cpp +wifiManager.setRemoveDuplicateAPs(false); +``` + #### Debug Debug is enabled by default on Serial. To disable add before autoConnect ```cpp @@ -242,7 +273,15 @@ If you connect to the created configuration Access Point but the configuration p If trying to connect ends up in an endless loop, try to add `setConnectTimeout(60)` before `autoConnect();`. The parameter is timeout to try connecting in seconds. ## Releases -#### 0.10 +#### 0.11 +- a lot more reliable reconnecting to networks +- custom html in custom parameters (for read only params) +- custom html in custom parameter form (like labels) +- custom head element (like custom css) +- sort networks based on signal quality +- remove duplicate networks + +##### 0.10 - some css changes - bug fixes and speed improvements - added an alternative to waitForConnectResult() for debugging diff --git a/library.json b/library.json index 5c36330..5a5955f 100644 --- a/library.json +++ b/library.json @@ -9,5 +9,5 @@ }, "frameworks": "arduino", "platforms": "espressif", - "version": "0.10" + "version": "0.11" } diff --git a/library.properties b/library.properties index d22ee1d..6184f85 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=WiFiManager -version=0.10 +version=0.11 author=tzapu maintainer=tzapu sentence=ESP8266 WiFi Connection manager with fallback web configuration portal From 801ae82ef5750d7f4ec8d815fc6f94a6650c0e29 Mon Sep 17 00:00:00 2001 From: Alex T Date: Sun, 8 May 2016 09:41:06 +0300 Subject: [PATCH 02/15] removed extraneous headers --- WiFiManager.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/WiFiManager.h b/WiFiManager.h index 9f5bc41..8ffb56e 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -24,14 +24,12 @@ extern "C" { #include "user_interface.h" } -const char HTTP_200[] PROGMEM = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"; const char HTTP_HEAD[] PROGMEM = "{v}"; const char HTTP_STYLE[] PROGMEM = ""; const char HTTP_SCRIPT[] PROGMEM = ""; const char HTTP_HEAD_END[] PROGMEM = "
"; const char HTTP_PORTAL_OPTIONS[] PROGMEM = "



"; const char HTTP_ITEM[] PROGMEM = "
{v} {r}%
"; -//const char HTTP_ITEM_PADLOCK[] PROGMEM = ""; const char HTTP_FORM_START[] PROGMEM = "


"; const char HTTP_FORM_PARAM[] PROGMEM = "
"; const char HTTP_FORM_END[] PROGMEM = "
"; From 44e828e77a2454a38371f7d5fb64424acebeb676 Mon Sep 17 00:00:00 2001 From: Alex T Date: Sun, 8 May 2016 10:07:32 +0300 Subject: [PATCH 03/15] reverted std::sort that caused problems with isnan and other none namespeced used function calls --- WiFiManager.cpp | 36 ++++++++++++++++++------------------ WiFiManager.h | 4 +--- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 47414ca..88e3a9b 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -229,7 +229,7 @@ int WiFiManager::connectWifi(String ssid, String pass) { if (ssid != "") { WiFi.begin(ssid.c_str(), pass.c_str()); } else { - if(WiFi.SSID()) { + if (WiFi.SSID()) { DEBUG_WM("Using last saved values, should be faster"); //trying to fix connection in progress hanging ETS_UART_INTR_DISABLE(); @@ -400,30 +400,30 @@ void WiFiManager::handleWifi(boolean scan) { // RSSI SORT // old sort - // 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]); - // } - // } - // } + 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]); + } + } + } - std::sort(indices, indices + n, [](const int & a, const int & b) -> bool - { + /*std::sort(indices, indices + n, [](const int & a, const int & b) -> bool + { return WiFi.RSSI(a) > WiFi.RSSI(b); - }); + });*/ // remove duplicates ( must be RSSI sorted ) - if(_removeDuplicateAPs){ + if (_removeDuplicateAPs) { String cssid; for (int i = 0; i < n; i++) { - if(indices[i] == -1) continue; + if (indices[i] == -1) continue; cssid = WiFi.SSID(indices[i]); for (int j = i + 1; j < n; j++) { - if(cssid == WiFi.SSID(indices[j])){ + if (cssid == WiFi.SSID(indices[j])) { DEBUG_WM("DUP AP: " + WiFi.SSID(indices[j])); indices[j] = -1; // set dup aps to index -1 } @@ -433,7 +433,7 @@ void WiFiManager::handleWifi(boolean scan) { //display networks in page for (int i = 0; i < n; i++) { - if(indices[i] == -1) continue; // skip dups + if (indices[i] == -1) continue; // skip dups DEBUG_WM(WiFi.SSID(indices[i])); DEBUG_WM(WiFi.RSSI(indices[i])); int quality = getRSSIasQuality(WiFi.RSSI(indices[i])); diff --git a/WiFiManager.h b/WiFiManager.h index 8ffb56e..827c985 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -17,9 +17,7 @@ #include #include #include -#undef min -#undef max -#include + extern "C" { #include "user_interface.h" } From 028bdeeb17ef12b8dc0c2fc05fc3ae4bc102ba70 Mon Sep 17 00:00:00 2001 From: Alex T Date: Sun, 8 May 2016 10:14:11 +0300 Subject: [PATCH 04/15] removed 204 header response https://github.com/tzapu/WiFiManager/issues/114 --- WiFiManager.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 88e3a9b..3fbbb42 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -115,7 +115,7 @@ void WiFiManager::setupConfigPortal() { server->on("/wifisave", std::bind(&WiFiManager::handleWifiSave, this)); server->on("/i", std::bind(&WiFiManager::handleInfo, this)); server->on("/r", std::bind(&WiFiManager::handleReset, this)); - server->on("/generate_204", std::bind(&WiFiManager::handle204, this)); //Android/Chrome OS captive portal check. + //server->on("/generate_204", std::bind(&WiFiManager::handle204, this)); //Android/Chrome OS captive portal check. 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 @@ -403,9 +403,6 @@ void WiFiManager::handleWifi(boolean scan) { 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]); } } @@ -651,14 +648,14 @@ void WiFiManager::handleReset() { - -void WiFiManager::handle204() { +//removed as mentioned here https://github.com/tzapu/WiFiManager/issues/114 +/*void WiFiManager::handle204() { DEBUG_WM(F("204 No Response")); server->sendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); server->sendHeader("Pragma", "no-cache"); server->sendHeader("Expires", "-1"); server->send ( 204, "text/plain", ""); -} +}*/ void WiFiManager::handleNotFound() { if (captivePortal()) { // If captive portal redirect instead of displaying the error page. From 04d47882a7d662b46bb1b1dbecfe786e5bc9efa4 Mon Sep 17 00:00:00 2001 From: Alex T Date: Sun, 8 May 2016 11:25:03 +0300 Subject: [PATCH 05/15] ver bump --- README.md | 6 +++++- library.json | 2 +- library.properties | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7bbd4dd..a329f2b 100644 --- a/README.md +++ b/README.md @@ -273,7 +273,11 @@ If you connect to the created configuration Access Point but the configuration p If trying to connect ends up in an endless loop, try to add `setConnectTimeout(60)` before `autoConnect();`. The parameter is timeout to try connecting in seconds. ## Releases -#### 0.11 +#### 0.12 +- removed 204 header response +- fixed incompatibility with other libs using isnan and other std:: functions without namespace + +##### 0.11 - a lot more reliable reconnecting to networks - custom html in custom parameters (for read only params) - custom html in custom parameter form (like labels) diff --git a/library.json b/library.json index 5a5955f..d840d3c 100644 --- a/library.json +++ b/library.json @@ -9,5 +9,5 @@ }, "frameworks": "arduino", "platforms": "espressif", - "version": "0.11" + "version": "0.12" } diff --git a/library.properties b/library.properties index 6184f85..2466f0d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=WiFiManager -version=0.11 +version=0.12 author=tzapu maintainer=tzapu sentence=ESP8266 WiFi Connection manager with fallback web configuration portal From c93cd80f58fe49941dc24fdefa47fd68cafa4481 Mon Sep 17 00:00:00 2001 From: gitgrimbo Date: Wed, 11 May 2016 08:21:23 +0100 Subject: [PATCH 06/15] Improve comments for AutoConnectWithStaticIP example --- .../AutoConnectWithStaticIP.ino | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/examples/AutoConnectWithStaticIP/AutoConnectWithStaticIP.ino b/examples/AutoConnectWithStaticIP/AutoConnectWithStaticIP.ino index af343cd..86556d3 100644 --- a/examples/AutoConnectWithStaticIP/AutoConnectWithStaticIP.ino +++ b/examples/AutoConnectWithStaticIP/AutoConnectWithStaticIP.ino @@ -35,16 +35,21 @@ void setup() { //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); -*/ + //set static ip + //block1 should be used for ESP8266 core 2.1.0 or newer, otherwise use block2 + + //start-block1 + //IPAddress _ip,_gw,_sn; + //_ip.fromString(static_ip); + //_gw.fromString(static_gw); + //_sn.fromString(static_sn); + //end-block1 + + //start-block2 IPAddress _ip = IPAddress(10, 0, 1, 78); IPAddress _gw = IPAddress(10, 0, 1, 1); IPAddress _sn = IPAddress(255, 255, 255, 0); + //end-block2 wifiManager.setSTAStaticIPConfig(_ip, _gw, _sn); From fac1575c96ea2a1dccb61044b162de80552f52b6 Mon Sep 17 00:00:00 2001 From: Alex T Date: Wed, 15 Jun 2016 14:35:43 +0300 Subject: [PATCH 07/15] attempt codecov --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 859d2f5..64fb578 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,8 @@ script: # - arduino -v --verbose-build --verify $PWD/examples/AutoConnect/AutoConnect.ino # - arduino --verify --board arduino:avr:uno $PWD/examples/IncomingCall/IncomingCall.ino # - arduino --verify --board arduino:avr:uno $PWD/examples/AdafruitIO_GPS/AdafruitIO_GPS.ino +after_success: + - bash <(curl -s https://codecov.io/bash) notifications: email: on_success: change From 039702327e6c3aef2a7ccc766bcf8bbab20bdae2 Mon Sep 17 00:00:00 2001 From: bakrus Date: Sat, 2 Jul 2016 13:27:59 +0200 Subject: [PATCH 08/15] Fix to allow 5 digit 'mqtt_port' 'WiFiManagerParameter custom_mqtt_port' made consistent with declaration of 'mqtt_port' --- .../AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino b/examples/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino index 42dabf3..1d58e5c 100644 --- a/examples/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino +++ b/examples/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino @@ -74,7 +74,7 @@ void setup() { // After connecting, parameter.getValue() will get you the configured value // id/name placeholder/prompt default length WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40); - WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 5); + WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 6); WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 32); //WiFiManager From c3d01d33e15f1bd097786b9d16c309676dcc2499 Mon Sep 17 00:00:00 2001 From: TaaraLabs Date: Sat, 6 Aug 2016 12:38:26 +0300 Subject: [PATCH 09/15] startConfigPortal() without any parameters startConfigPortal() without any parameters uses auto generated name ESP + ChipID --- WiFiManager.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 3fbbb42..93bf578 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -149,6 +149,11 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { return startConfigPortal(apName, apPassword); } +boolean WiFiManager::startConfigPortal() { + String ssid = "ESP" + String(ESP.getChipId()); + return startConfigPortal(ssid.c_str(), NULL); +} + boolean WiFiManager::startConfigPortal(char const *apName, char const *apPassword) { //setup AP WiFi.mode(WIFI_AP_STA); From 31887ff36a5d6387700eb60fb031dcbd2dd8307e Mon Sep 17 00:00:00 2001 From: TaaraLabs Date: Sat, 6 Aug 2016 12:45:22 +0300 Subject: [PATCH 10/15] startConfigPortal() without parameters --- WiFiManager.h | 1 + 1 file changed, 1 insertion(+) diff --git a/WiFiManager.h b/WiFiManager.h index 827c985..bd67c05 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -70,6 +70,7 @@ class WiFiManager boolean autoConnect(char const *apName, char const *apPassword = NULL); //if you want to always start the config portal, without trying to connect first + boolean startConfigPortal(); boolean startConfigPortal(char const *apName, char const *apPassword = NULL); // get the AP name of the config portal, so it can be used in the callback From 1b261f23713de5fded144acd5ad1aa4cbfe24812 Mon Sep 17 00:00:00 2001 From: Alex T Date: Thu, 8 Sep 2016 13:07:51 +0300 Subject: [PATCH 11/15] intial html template parser --- extras/WiFiManager.template.html | 112 +++++++++++++++++++++---------- extras/parse.js | 60 +++++++++++++++++ extras/template.h | 12 ++++ 3 files changed, 149 insertions(+), 35 deletions(-) create mode 100644 extras/parse.js create mode 100644 extras/template.h diff --git a/extras/WiFiManager.template.html b/extras/WiFiManager.template.html index 0cf8604..d510e9c 100644 --- a/extras/WiFiManager.template.html +++ b/extras/WiFiManager.template.html @@ -1,38 +1,80 @@ -{v} - + + + + + + {v} + + + + + + + + + + +
+ - -
- - - + -
{v} {r}%
-
PMisa 100%
- -
PMisa 8%
- - - -
- - -


-
-
-

-
-
- + + + + +



+ + +
{v} {r}%
+
PMisa 100%
+ +
PMisa 8%
+ + +
{v} {r}%
+ + +


+ + +
+ + +
+ + +
+ + +
Credentials Saved
Trying to connect ESP to network.
If it fails reconnect to AP to try again
+ + + + + +
- \ No newline at end of file + + + diff --git a/extras/parse.js b/extras/parse.js new file mode 100644 index 0000000..97a3e38 --- /dev/null +++ b/extras/parse.js @@ -0,0 +1,60 @@ +'use strict'; + +const fs = require('fs'); + +console.log('starting'); + +const inFile = 'WiFiManager.template.html'; +const outFile = 'template.h'; + +const defineRegEx = //gm; +console.log('parsing', inFile); + +fs.readFile(inFile, 'utf8', function (err,data) { + if (err) { + return console.log(err); + } + //console.log(data); + + let defines = data.match(defineRegEx); + + //console.log(defines); + var stream = fs.createWriteStream(outFile); + stream.once('open', function(fd) { + for (const i in defines) { + + const start = defines[i]; + const end = start.replace(' -
+