From 276795079e2f463837e51689b05bc5f8b99acf4f Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 9 Mar 2016 16:03:51 -0600 Subject: [PATCH 1/6] add remove duplicate ap feature fixes #26 --- WiFiManager.cpp | 47 ++++++++++++++++++++++++++++++----------------- WiFiManager.h | 3 ++- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 25f5823..fa4255a 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -390,37 +390,50 @@ void WiFiManager::handleWifi(boolean scan) { DEBUG_WM(F("No networks found")); 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]); - } - } - } - */ int indices[n]; for (int i = 0; i < n; i++) { indices[i] = i; } + // 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]); + // } + // } + // } + 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(_removeDupAps){ + String cssid; + for (int i = 0; i < n; i++) { + if(indices[i] == -1) continue; + cssid = WiFi.SSID(indices[i]); + for (int j = i + 1; j < n; j++) { + if(cssid == WiFi.SSID(indices[j])){ + DEBUG_WM("DUP AP: " + WiFi.SSID(indices[j])); + indices[j] = -1; // set dup aps to index -1 + } + } + } + } //display networks in page for (int i = 0; i < n; i++) { + 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 0902e86..ed3f026 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -119,7 +119,7 @@ class WiFiManager //const int WM_DONE = 0; //const int WM_WAIT = 10; - //const String HTTP_HEAD = "{v}"; + //const Srting HTTP_HEAD = "{v}"; void setupConfigPortal(); void startWPS(); @@ -141,6 +141,7 @@ class WiFiManager int _paramsCount = 0; int _minimumQuality = -1; + boolean _removeDupAps = true; boolean _shouldBreakAfterConfig = false; boolean _tryWPS = false; From 745c3a91fd94e0748aed051b543b9c9fd0a5eb48 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 9 Mar 2016 16:13:16 -0600 Subject: [PATCH 2/6] typo, shrug --- WiFiManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.h b/WiFiManager.h index ed3f026..8848a8e 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -119,7 +119,7 @@ class WiFiManager //const int WM_DONE = 0; //const int WM_WAIT = 10; - //const Srting HTTP_HEAD = "{v}"; + //const String HTTP_HEAD = "{v}"; void setupConfigPortal(); void startWPS(); From 852d90beec0ec6122e063a2971b23a06f0af8537 Mon Sep 17 00:00:00 2001 From: Alex Tudorache Date: Wed, 16 Mar 2016 10:21:53 +0200 Subject: [PATCH 3/6] travis ci --- .travis.yml | 21 +++++++++++++++++++++ README.md | 8 +++++--- 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c901b56 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,21 @@ +language: c +before_install: + - "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16" + - sleep 3 + - export DISPLAY=:1.0 + - wget http://downloads.arduino.cc/arduino-1.6.8-linux64.tar.xz + - tar xf arduino-1.6.8-linux64.tar.xz + - sudo mv arduino-1.6.8 /usr/local/share/arduino + - sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino +install: + - ln -s $PWD /usr/local/share/arduino/libraries/WiFiManager + - arduino --install-boards esp8266:esp8266 +# - arduino --install-library "Adafruit SleepyDog Library,Adafruit MQTT Library" +script: + - arduino --verify --board esp8266:generic $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 +notifications: + email: + on_success: change + on_failure: change diff --git a/README.md b/README.md index f65dae2..bce465e 100644 --- a/README.md +++ b/README.md @@ -74,9 +74,11 @@ __Github version works with release 2.0.0 or newer of the [ESP8266 core for Ardu ### Using - Include in your sketch ```cpp -#include -#include -#include +#include //ESP8266 Core WiFi Library (you most likely already have this in your sketch) + +#include //Local DNS Server used for redirecting all requests to the configuration portal +#include //Local WebServer used to serve the configuration portal +#include //https://github.com/tzapu/WiFiManager WiFi Configuration Magic ``` - Initialize library, in your setup function add From f9cc4b641feaf872f1dc18e71b520e80c9751fe8 Mon Sep 17 00:00:00 2001 From: Alex Tudorache Date: Wed, 16 Mar 2016 10:43:10 +0200 Subject: [PATCH 4/6] added boards manager --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index c901b56..fa9b02f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ before_install: - sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino install: - ln -s $PWD /usr/local/share/arduino/libraries/WiFiManager + - arduino --pref "boardsmanager.additional.urls=https://adafruit.github.io/arduino-board-index/package_adafruit_index.json,http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs 2>&1 - arduino --install-boards esp8266:esp8266 # - arduino --install-library "Adafruit SleepyDog Library,Adafruit MQTT Library" script: From d11c763bcef09585483d43a47d818d64db52127d Mon Sep 17 00:00:00 2001 From: Alex T Date: Wed, 16 Mar 2016 11:04:33 +0200 Subject: [PATCH 5/6] update travis yml another ci test ci fix ci attempt 6 stable package json fixe prefs fix lib folder debug alalalalaalal try with 1.6.5 try with 1.6.7 verbose build 1.6.7 again back to 1.6.5 escaped : in url no save pref no save pref, one line and back to working 1.6.5 getting all examples built added sh include fix sh added build build examples aded debug output going insane beautify added lib ArduinoJson try again 1.6.8 get arduino json from github back to 1.6.5 --- .travis.yml | 23 ++++++++++++++++------ README.md | 2 ++ travis/common.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 travis/common.sh diff --git a/.travis.yml b/.travis.yml index fa9b02f..859d2f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,17 +3,28 @@ before_install: - "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16" - sleep 3 - export DISPLAY=:1.0 - - wget http://downloads.arduino.cc/arduino-1.6.8-linux64.tar.xz - - tar xf arduino-1.6.8-linux64.tar.xz - - sudo mv arduino-1.6.8 /usr/local/share/arduino + - wget http://downloads.arduino.cc/arduino-1.6.5-linux64.tar.xz + - tar xf arduino-1.6.5-linux64.tar.xz + - sudo mv arduino-1.6.5 /usr/local/share/arduino - sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino install: - ln -s $PWD /usr/local/share/arduino/libraries/WiFiManager - - arduino --pref "boardsmanager.additional.urls=https://adafruit.github.io/arduino-board-index/package_adafruit_index.json,http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs 2>&1 +# boards manager not working on 1.6.7 - 1.6.8 + - arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs +# install lib arduino json not working in 1.6.5 +# - arduino --install-library "ArduinoJson" + - git clone https://github.com/bblanchon/ArduinoJson /usr/local/share/arduino/libraries/ArduinoJson - arduino --install-boards esp8266:esp8266 -# - arduino --install-library "Adafruit SleepyDog Library,Adafruit MQTT Library" + - arduino --board esp8266:esp8266:generic --save-prefs + - arduino --pref "compiler.warning_level=all" --save-prefs script: - - arduino --verify --board esp8266:generic $PWD/examples/AutoConnect/AutoConnect.ino + - "echo $PWD" + - "echo $HOME" + - "ls $PWD" + - source $TRAVIS_BUILD_DIR/travis/common.sh + - build_examples +# - "cat $PWD/examples/AutoConnect/AutoConnect.ino" +# - 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 notifications: diff --git a/README.md b/README.md index bce465e..ce2e580 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # WiFiManager ESP8266 WiFi Connection manager with fallback web configuration portal +[![Build Status](https://travis-ci.org/tzapu/WiFiManager.svg?branch=master)](https://travis-ci.org/tzapu/WiFiManager) + The configuration portal is of the captive variety, so on various devices it will present the configuration dialogue as soon as you connect to the created access point. First attempt at a library. Lots more changes and fixes to do. Contributions are welcome. diff --git a/travis/common.sh b/travis/common.sh new file mode 100644 index 0000000..d115085 --- /dev/null +++ b/travis/common.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +function build_examples() +{ + # track the exit code for this platform + local exit_code=0 + # loop through results and add them to the array + examples=($(find $PWD/examples/ -name "*.pde" -o -name "*.ino")) + + # get the last example in the array + local last="${examples[@]:(-1)}" + + # loop through example sketches + for example in "${examples[@]}"; do + + # store the full path to the example's sketch directory + local example_dir=$(dirname $example) + + # store the filename for the example without the path + local example_file=$(basename $example) + + echo "$example_file: " + local sketch="$example_dir/$example_file" + echo "$sketch" + #arduino -v --verbose-build --verify $sketch + + # verify the example, and save stdout & stderr to a variable + # we have to avoid reading the exit code of local: + # "when declaring a local variable in a function, the local acts as a command in its own right" + local build_stdout + build_stdout=$(arduino --verify $sketch 2>&1) + + # echo output if the build failed + if [ $? -ne 0 ]; then + # heavy X + echo -e "\xe2\x9c\x96" + echo -e "----------------------------- DEBUG OUTPUT -----------------------------\n" + echo "$build_stdout" + echo -e "\n------------------------------------------------------------------------\n" + + # mark as fail + exit_code=1 + + else + # heavy checkmark + echo -e "\xe2\x9c\x93" + fi + done + + return $exit_code +} From f99156e29ff8f1e46c81cf52f5e77f26591a7f9c Mon Sep 17 00:00:00 2001 From: Alex T Date: Wed, 16 Mar 2016 20:42:47 +0200 Subject: [PATCH 6/6] added setter for removing duplicate APs --- WiFiManager.cpp | 12 ++++++++---- WiFiManager.h | 5 +++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index fa4255a..47414ca 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -235,7 +235,7 @@ int WiFiManager::connectWifi(String ssid, String pass) { ETS_UART_INTR_DISABLE(); wifi_station_disconnect(); ETS_UART_INTR_ENABLE(); - + WiFi.begin(); } else { DEBUG_WM("No saved credentials"); @@ -390,7 +390,7 @@ void WiFiManager::handleWifi(boolean scan) { DEBUG_WM(F("No networks found")); page += F("No networks found. Refresh to scan again."); } else { - + //sort networks int indices[n]; for (int i = 0; i < n; i++) { @@ -417,7 +417,7 @@ void WiFiManager::handleWifi(boolean scan) { }); // remove duplicates ( must be RSSI sorted ) - if(_removeDupAps){ + if(_removeDuplicateAPs){ String cssid; for (int i = 0; i < n; i++) { if(indices[i] == -1) continue; @@ -427,7 +427,7 @@ void WiFiManager::handleWifi(boolean scan) { DEBUG_WM("DUP AP: " + WiFi.SSID(indices[j])); indices[j] = -1; // set dup aps to index -1 } - } + } } } @@ -710,6 +710,10 @@ void WiFiManager::setCustomHeadElement(const char* element) { _customHeadElement = element; } +//if this is true, remove duplicated Access Points - defaut true +void WiFiManager::setRemoveDuplicateAPs(boolean removeDuplicates) { + _removeDuplicateAPs = removeDuplicates; +} diff --git a/WiFiManager.h b/WiFiManager.h index 8848a8e..9f5bc41 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -110,7 +110,8 @@ class WiFiManager //TODO //if this is set, customise style void setCustomHeadElement(const char* element); - + //if this is true, remove duplicated Access Points - defaut true + void setRemoveDuplicateAPs(boolean removeDuplicates); private: std::unique_ptr dnsServer; @@ -141,7 +142,7 @@ class WiFiManager int _paramsCount = 0; int _minimumQuality = -1; - boolean _removeDupAps = true; + boolean _removeDuplicateAPs = true; boolean _shouldBreakAfterConfig = false; boolean _tryWPS = false;