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