diff --git a/adem/libraries/I2Cdev/I2Cdev.h b/adem/libraries/I2Cdev/I2Cdev.h index e30c8c7..62cbfef 100644 --- a/adem/libraries/I2Cdev/I2Cdev.h +++ b/adem/libraries/I2Cdev/I2Cdev.h @@ -101,6 +101,13 @@ THE SOFTWARE. #define MAX_RETRY 4 +#ifdef ESP8266 +#define min _min +#define max _max +#endif + +#define BUFFER_LENGTH 64 + class I2Cdev { public: I2Cdev(); diff --git a/adem/libraries/WiFiManager/.travis.yml b/adem/libraries/WiFiManager/.travis.yml deleted file mode 100644 index 859d2f5..0000000 --- a/adem/libraries/WiFiManager/.travis.yml +++ /dev/null @@ -1,33 +0,0 @@ -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/adem/libraries/WiFiManager/README.md b/adem/libraries/WiFiManager/README.md index a329f2b..3782339 100644 --- a/adem/libraries/WiFiManager/README.md +++ b/adem/libraries/WiFiManager/README.md @@ -1,3 +1,5 @@ +## Current development going on here :arrow_right: [Development Branch](https://github.com/tzapu/WiFiManager/tree/development) + # WiFiManager ESP8266 WiFi Connection manager with fallback web configuration portal @@ -43,16 +45,19 @@ First attempt at a library. Lots more changes and fixes to do. Contributions are   ## Wishlist -- ~~remove dependency on EEPROM library~~ -- ~~move HTML Strings to PROGMEM~~ -- ~~cleanup and streamline code~~ (although this is ongoing) -- if timeout is set, extend it when a page is fetched in AP mode -- ~~add ability to configure more parameters than ssid/password~~ -- ~~maybe allow setting ip of ESP after reboot~~ -- ~~add to Arduino Library Manager~~ -- ~~add to PlatformIO~~ -- add multiple sets of network credentials -- ~~allow users to customize CSS~~ +- [x] remove dependency on EEPROM library +- [x] move HTML Strings to PROGMEM +- [x] cleanup and streamline code (although this is ongoing) +- [x] if timeout is set, extend it when a page is fetched in AP mode +- [x] add ability to configure more parameters than ssid/password +- [x] maybe allow setting ip of ESP after reboot +- [x] add to Arduino Library Manager +- [x] add to PlatformIO +- [ ] add multiple sets of network credentials +- [x] allow users to customize CSS +- [ ] ESP32 support or instructions +- [ ] rewrite documentation for simplicity, based on scenarios/goals +- [ ] rely on the SDK's built in auto connect more than forcing a connect ## Quick Start diff --git a/adem/libraries/WiFiManager/WiFiManager.cpp b/adem/libraries/WiFiManager/WiFiManager.cpp index 3fbbb42..2e7884d 100644 --- a/adem/libraries/WiFiManager/WiFiManager.cpp +++ b/adem/libraries/WiFiManager/WiFiManager.cpp @@ -5,7 +5,7 @@ inspired by: http://www.esp8266.com/viewtopic.php?f=29&t=2520 https://github.com/chriscook8/esp-arduino-apboot - https://github.com/esp8266/Arduino/tree/esp8266/hardware/esp8266com/esp8266/libraries/DNSServer/examples/CaptivePortalAdvanced + https://github.com/esp8266/Arduino/tree/master/libraries/DNSServer/examples/CaptivePortalAdvanced Built by AlexT https://github.com/tzapu Licensed under MIT license **************************************************************/ @@ -34,7 +34,7 @@ void WiFiManagerParameter::init(const char *id, const char *placeholder, const c _placeholder = placeholder; _length = length; _value = new char[length + 1]; - for (int i = 0; i < length; i++) { + for (int i = 0; i < length + 1; i++) { _value[i] = 0; } if (defaultValue != NULL) { @@ -44,6 +44,12 @@ void WiFiManagerParameter::init(const char *id, const char *placeholder, const c _customHTML = custom; } +WiFiManagerParameter::~WiFiManagerParameter() { + if (_value != NULL) { + delete[] _value; + } +} + const char* WiFiManagerParameter::getValue() { return _value; } @@ -60,14 +66,42 @@ const char* WiFiManagerParameter::getCustomHTML() { return _customHTML; } + WiFiManager::WiFiManager() { + _max_params = WIFI_MANAGER_MAX_PARAMS; + _params = (WiFiManagerParameter**)malloc(_max_params * sizeof(WiFiManagerParameter*)); } -void WiFiManager::addParameter(WiFiManagerParameter *p) { +WiFiManager::~WiFiManager() +{ + if (_params != NULL) + { + DEBUG_WM(F("freeing allocated params!")); + free(_params); + } +} + +bool WiFiManager::addParameter(WiFiManagerParameter *p) { + if(_paramsCount + 1 > _max_params) + { + // rezise the params array + _max_params += WIFI_MANAGER_MAX_PARAMS; + DEBUG_WM(F("Increasing _max_params to:")); + DEBUG_WM(_max_params); + WiFiManagerParameter** new_params = (WiFiManagerParameter**)realloc(_params, _max_params * sizeof(WiFiManagerParameter*)); + if (new_params != NULL) { + _params = new_params; + } else { + DEBUG_WM(F("ERROR: failed to realloc params, size not increased!")); + return false; + } + } + _params[_paramsCount] = p; _paramsCount++; - DEBUG_WM("Adding parameter"); + DEBUG_WM(F("Adding parameter")); DEBUG_WM(p->getID()); + return true; } void WiFiManager::setupConfigPortal() { @@ -109,14 +143,14 @@ void WiFiManager::setupConfigPortal() { dnsServer->start(DNS_PORT, "*", WiFi.softAPIP()); /* Setup web pages: root, wifi config pages, SO captive portal detectors and not found. */ - server->on("/", std::bind(&WiFiManager::handleRoot, this)); - server->on("/wifi", std::bind(&WiFiManager::handleWifi, this, true)); - server->on("/0wifi", std::bind(&WiFiManager::handleWifi, this, false)); - 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(String(F("/")), std::bind(&WiFiManager::handleRoot, this)); + server->on(String(F("/wifi")), std::bind(&WiFiManager::handleWifi, this, true)); + server->on(String(F("/0wifi")), std::bind(&WiFiManager::handleWifi, this, false)); + server->on(String(F("/wifisave")), std::bind(&WiFiManager::handleWifiSave, this)); + server->on(String(F("/i")), std::bind(&WiFiManager::handleInfo, this)); + server->on(String(F("/r")), std::bind(&WiFiManager::handleReset, this)); //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->on(String(F("/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 DEBUG_WM(F("HTTP server started")); @@ -149,10 +183,34 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { return startConfigPortal(apName, apPassword); } +boolean WiFiManager::configPortalHasTimeout(){ + if(_configPortalTimeout == 0 || wifi_softap_get_station_num() > 0){ + _configPortalStart = millis(); // kludge, bump configportal start time to skew timeouts + return false; + } + return (millis() > _configPortalStart + _configPortalTimeout); +} + +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); - DEBUG_WM("SET AP STA"); + + if(!WiFi.isConnected()){ + WiFi.persistent(false); + // disconnect sta, start ap + WiFi.disconnect(); // this alone is not enough to stop the autoconnecter + WiFi.mode(WIFI_AP); + WiFi.persistent(true); + } + else { + //setup AP + WiFi.mode(WIFI_AP_STA); + DEBUG_WM(F("SET AP STA")); + } + _apName = apName; _apPassword = apPassword; @@ -165,7 +223,11 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo connect = false; setupConfigPortal(); - while (_configPortalTimeout == 0 || millis() < _configPortalStart + _configPortalTimeout) { + while(1){ + + // check if timeout + if(configPortalHasTimeout()) break; + //DNS dnsServer->processNextRequest(); //HTTP @@ -222,7 +284,7 @@ int WiFiManager::connectWifi(String ssid, String pass) { } //fix for auto connect racing issue if (WiFi.status() == WL_CONNECTED) { - DEBUG_WM("Already connected. Bailing out."); + DEBUG_WM(F("Already connected. Bailing out.")); return WL_CONNECTED; } //check if we have ssid and pass and force those, if not, try with last saved values @@ -230,7 +292,7 @@ int WiFiManager::connectWifi(String ssid, String pass) { WiFi.begin(ssid.c_str(), pass.c_str()); } else { if (WiFi.SSID()) { - DEBUG_WM("Using last saved values, should be faster"); + DEBUG_WM(F("Using last saved values, should be faster")); //trying to fix connection in progress hanging ETS_UART_INTR_DISABLE(); wifi_station_disconnect(); @@ -238,7 +300,7 @@ int WiFiManager::connectWifi(String ssid, String pass) { WiFi.begin(); } else { - DEBUG_WM("No saved credentials"); + DEBUG_WM(F("No saved credentials")); } } @@ -246,11 +308,13 @@ int WiFiManager::connectWifi(String ssid, String pass) { DEBUG_WM ("Connection result: "); DEBUG_WM ( connRes ); //not connected, WPS enabled, no pass - first attempt + #ifdef NO_EXTRA_4K_HEAP if (_tryWPS && connRes != WL_CONNECTED && pass == "") { startWPS(); //should be connected at the end of WPS connRes = waitForConnectResult(); } + #endif return connRes; } @@ -278,9 +342,9 @@ uint8_t WiFiManager::waitForConnectResult() { } void WiFiManager::startWPS() { - DEBUG_WM("START WPS"); + DEBUG_WM(F("START WPS")); WiFi.beginWPSConfig(); - DEBUG_WM("END WPS"); + DEBUG_WM(F("END WPS")); } /* String WiFiManager::getSSID() { @@ -362,13 +426,14 @@ void WiFiManager::handleRoot() { page += FPSTR(HTTP_STYLE); page += _customHeadElement; page += FPSTR(HTTP_HEAD_END); - page += "