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 diff --git a/README.md b/README.md index ce2e580..a329f2b 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,19 @@ 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.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) +- 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/WiFiManager.cpp b/WiFiManager.cpp index 47414ca..06e7481 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -64,6 +64,14 @@ WiFiManager::WiFiManager() { } void WiFiManager::addParameter(WiFiManagerParameter *p) { + if(_paramsCount + 1 > WIFI_MANAGER_MAX_PARAMS) + { + //Max parameters exceeded! + DEBUG_WM("WIFI_MANAGER_MAX_PARAMS exceeded, increase number (in WiFiManager.h) before adding more parameters!"); + DEBUG_WM("Skipping parameter with ID:"); + DEBUG_WM(p->getID()); + return; + } _params[_paramsCount] = p; _paramsCount++; DEBUG_WM("Adding parameter"); @@ -115,7 +123,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 @@ -149,6 +157,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); @@ -229,7 +242,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 +413,27 @@ 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])) { + 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 +443,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])); @@ -651,14 +661,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. diff --git a/WiFiManager.h b/WiFiManager.h index 9f5bc41..bd67c05 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -17,21 +17,17 @@ #include #include #include -#undef min -#undef max -#include + 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 = "
"; @@ -74,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 diff --git a/examples/AutoConnect/AutoConnect.ino b/examples/AutoConnect/AutoConnect.ino index 37ff392..0c44909 100644 --- a/examples/AutoConnect/AutoConnect.ino +++ b/examples/AutoConnect/AutoConnect.ino @@ -17,7 +17,7 @@ void setup() { //wifiManager.resetSettings(); //set custom ip for portal - //wifiManager.setAPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); + //wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); //fetches ssid and pass from eeprom and tries to connect //if it does not connect it starts an access point with the specified name 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 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); diff --git a/extras/WiFiManager.template.html b/extras/WiFiManager.template.html index 0cf8604..e15593b 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('