diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..859d2f5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,33 @@ +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.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 +# 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 --board esp8266:esp8266:generic --save-prefs + - arduino --pref "compiler.warning_level=all" --save-prefs +script: + - "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: + email: + on_success: change + on_failure: change diff --git a/README.md b/README.md index f65dae2..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. @@ -74,9 +76,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 diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 25f5823..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,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(_removeDuplicateAPs){ + 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])); @@ -697,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 0902e86..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,6 +142,7 @@ class WiFiManager int _paramsCount = 0; int _minimumQuality = -1; + boolean _removeDuplicateAPs = true; boolean _shouldBreakAfterConfig = false; boolean _tryWPS = false; 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 +}