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/BufferedResponse.cpp b/adem/libraries/WiFiManager/BufferedResponse.cpp deleted file mode 100644 index f1e00dd..0000000 --- a/adem/libraries/WiFiManager/BufferedResponse.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include "BufferedResponse.h" - -BufferedResponse::BufferedResponse(ESP8266WebServer &_server, const char *content_type, int code, size_t _buffer_size) - :server(_server), buffer_size(_buffer_size) { - buf = (uint8_t *) malloc(buffer_size); - server.setContentLength(CONTENT_LENGTH_UNKNOWN); - if (content_type != NULL) - server.sendHeader("Content-Type", content_type, true); - - server.sendHeader("Cache-Control", "no-cache"); - server.send(code); -} - -BufferedResponse::~BufferedResponse() { - if (pos != 0) - close(); - delete buf; -} - -size_t BufferedResponse::write(const uint8_t *data, size_t len) { - const size_t buffer_write_size = buffer_size - 1; - size_t data_pos = 0; - Serial.println("buffered write data"); - while(len) { - //no more space? -> flush - if((buffer_write_size - pos) == 0){ - flush(); - Serial.println(" flush buffer"); - } - yield(); - //how much can we write? - size_t copy_len = std::min(buffer_write_size - pos, len); - memcpy((void *) (buf + pos), (const void *) (data + data_pos), copy_len); - pos += copy_len; - data_pos += copy_len; - len -= copy_len; - } -} - -void BufferedResponse::flush() { - //Flush buffer - if (pos > 0) { - buf[pos] = 0; // end of string mark - server.sendContent( - (const char *) &buf[0]); //Actually this is a conversion to String - not sure if this is a good idea? - pos = 0; - } -} - -void BufferedResponse::close() { - //Flush buffer - flush(); - //End connection - server.sendContent(""); -} - -size_t BufferedResponse::write(uint8_t data) { - return write(&data, 1); -} - -template -void BufferedResponse::write(const stringType &str) -{ - write(str.c_str(), str.length()); -} \ No newline at end of file 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 ![ESP8266 WiFi Captive Portal Homepage](http://i.imgur.com/YPvW9eql.png) ![ESP8266 WiFi Captive Portal Configuration](http://i.imgur.com/oicWJ4gl.png) ## 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 += "

"; + page += String(F("

")); page += _apName; - page += "

"; - page += F("

WiFiManager

"); + page += String(F("")); + page += String(F("

WiFiManager

")); page += FPSTR(HTTP_PORTAL_OPTIONS); page += FPSTR(HTTP_END); + server->sendHeader("Content-Length", String(page.length())); server->send(200, "text/html", page); } @@ -459,7 +524,7 @@ void WiFiManager::handleWifi(boolean scan) { } page += FPSTR(HTTP_FORM_START); - char parLength[2]; + char parLength[5]; // add the extra parameters to the form for (int i = 0; i < _paramsCount; i++) { if (_params[i] == NULL) { @@ -471,7 +536,7 @@ void WiFiManager::handleWifi(boolean scan) { pitem.replace("{i}", _params[i]->getID()); pitem.replace("{n}", _params[i]->getID()); pitem.replace("{p}", _params[i]->getPlaceholder()); - snprintf(parLength, 2, "%d", _params[i]->getValueLength()); + snprintf(parLength, 5, "%d", _params[i]->getValueLength()); pitem.replace("{l}", parLength); pitem.replace("{v}", _params[i]->getValue()); pitem.replace("{c}", _params[i]->getCustomHTML()); @@ -522,6 +587,7 @@ void WiFiManager::handleWifi(boolean scan) { page += FPSTR(HTTP_END); + server->sendHeader("Content-Length", String(page.length())); server->send(200, "text/html", page); @@ -544,7 +610,7 @@ void WiFiManager::handleWifiSave() { //read parameter String value = server->arg(_params[i]->getID()).c_str(); //store it in array - value.toCharArray(_params[i]->_value, _params[i]->_length); + value.toCharArray(_params[i]->_value, _params[i]->_length + 1); DEBUG_WM(F("Parameter")); DEBUG_WM(_params[i]->getID()); DEBUG_WM(value); @@ -579,6 +645,7 @@ void WiFiManager::handleWifiSave() { page += FPSTR(HTTP_SAVED); page += FPSTR(HTTP_END); + server->sendHeader("Content-Length", String(page.length())); server->send(200, "text/html", page); DEBUG_WM(F("Sent wifi save page")); @@ -621,6 +688,7 @@ void WiFiManager::handleInfo() { page += F(""); page += FPSTR(HTTP_END); + server->sendHeader("Content-Length", String(page.length())); server->send(200, "text/html", page); DEBUG_WM(F("Sent info page")); @@ -638,6 +706,8 @@ void WiFiManager::handleReset() { page += FPSTR(HTTP_HEAD_END); page += F("Module will reset in a few seconds."); page += FPSTR(HTTP_END); + + server->sendHeader("Content-Length", String(page.length())); server->send(200, "text/html", page); DEBUG_WM(F("Sent reset page")); @@ -646,17 +716,6 @@ void WiFiManager::handleReset() { delay(2000); } - - -//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. return; @@ -676,6 +735,7 @@ void WiFiManager::handleNotFound() { server->sendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); server->sendHeader("Pragma", "no-cache"); server->sendHeader("Expires", "-1"); + server->sendHeader("Content-Length", String(message.length())); server->send ( 404, "text/plain", message ); } @@ -737,7 +797,7 @@ int WiFiManager::getRSSIasQuality(int RSSI) { /** Is this an IP? */ boolean WiFiManager::isIp(String str) { - for (int i = 0; i < str.length(); i++) { + for (size_t i = 0; i < str.length(); i++) { int c = str.charAt(i); if (c != '.' && (c < '0' || c > '9')) { return false; diff --git a/adem/libraries/WiFiManager/WiFiManager.h b/adem/libraries/WiFiManager/WiFiManager.h index 827c985..3da163e 100644 --- a/adem/libraries/WiFiManager/WiFiManager.h +++ b/adem/libraries/WiFiManager/WiFiManager.h @@ -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 **************************************************************/ @@ -29,19 +29,26 @@ const char HTTP_HEAD_END[] PROGMEM = "
{v} {r}%
"; const char HTTP_FORM_START[] PROGMEM = "


"; -const char HTTP_FORM_PARAM[] PROGMEM = "
"; +const char HTTP_FORM_PARAM[] PROGMEM = "
"; const char HTTP_FORM_END[] PROGMEM = "
"; const char HTTP_SCAN_LINK[] PROGMEM = "
Scan
"; const char HTTP_SAVED[] PROGMEM = "
Credentials Saved
Trying to connect ESP to network.
If it fails reconnect to AP to try again
"; const char HTTP_END[] PROGMEM = ""; +#ifndef WIFI_MANAGER_MAX_PARAMS #define WIFI_MANAGER_MAX_PARAMS 10 +#endif class WiFiManagerParameter { public: + /** + Create custom parameters that can be added to the WiFiManager setup web page + @id is used for HTTP queries and must not contain spaces nor other special characters + */ WiFiManagerParameter(const char *custom); WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length); WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom); + ~WiFiManagerParameter(); const char *getID(); const char *getValue(); @@ -65,11 +72,13 @@ class WiFiManager { public: WiFiManager(); + ~WiFiManager(); boolean autoConnect(); 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 @@ -78,12 +87,12 @@ class WiFiManager void resetSettings(); //sets timeout before webserver loop ends and exits even if there has been no setup. - //usefully for devices that failed to connect at some point and got stuck in a webserver loop + //useful for devices that failed to connect at some point and got stuck in a webserver loop //in seconds setConfigPortalTimeout is a new name for setTimeout void setConfigPortalTimeout(unsigned long seconds); void setTimeout(unsigned long seconds); - //sets timeout for which to attempt connecting, usefull if you get a lot of failed connects + //sets timeout for which to attempt connecting, useful if you get a lot of failed connects void setConnectTimeout(unsigned long seconds); @@ -98,9 +107,9 @@ class WiFiManager void setAPCallback( void (*func)(WiFiManager*) ); //called when settings have been changed and connection was successful void setSaveConfigCallback( void (*func)(void) ); - //adds a custom parameter - void addParameter(WiFiManagerParameter *p); - //if this is set, it will exit after config, even if connection is unsucessful. + //adds a custom parameter, returns false on failure + bool addParameter(WiFiManagerParameter *p); + //if this is set, it will exit after config, even if connection is unsuccessful. void setBreakAfterConfig(boolean shouldBreak); //if this is set, try WPS setup when starting (this will delay config portal for up to 2 mins) //TODO @@ -159,6 +168,7 @@ class WiFiManager void handleNotFound(); void handle204(); boolean captivePortal(); + boolean configPortalHasTimeout(); // DNS server const byte DNS_PORT = 53; @@ -174,7 +184,8 @@ class WiFiManager void (*_apcallback)(WiFiManager*) = NULL; void (*_savecallback)(void) = NULL; - WiFiManagerParameter* _params[WIFI_MANAGER_MAX_PARAMS]; + int _max_params; + WiFiManagerParameter** _params; template void DEBUG_WM(Generic text); diff --git a/adem/libraries/WiFiManager/examples/AutoConnect/AutoConnect.ino b/adem/libraries/WiFiManager/examples/AutoConnect/AutoConnect.ino index 37ff392..0c44909 100644 --- a/adem/libraries/WiFiManager/examples/AutoConnect/AutoConnect.ino +++ b/adem/libraries/WiFiManager/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/adem/libraries/WiFiManager/examples/AutoConnectWithFSParameters/.vscode/settings.json b/adem/libraries/WiFiManager/examples/AutoConnectWithFSParameters/.vscode/settings.json deleted file mode 100644 index 20af2f6..0000000 --- a/adem/libraries/WiFiManager/examples/AutoConnectWithFSParameters/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -// Place your settings in this file to overwrite default and user settings. -{ -} \ No newline at end of file diff --git a/adem/libraries/WiFiManager/examples/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino b/adem/libraries/WiFiManager/examples/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino index 42dabf3..7e6c373 100644 --- a/adem/libraries/WiFiManager/examples/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino +++ b/adem/libraries/WiFiManager/examples/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino @@ -61,6 +61,7 @@ void setup() { } else { Serial.println("failed to load json config"); } + configFile.close(); } } } else { @@ -74,7 +75,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/adem/libraries/WiFiManager/examples/AutoConnectWithStaticIP/AutoConnectWithStaticIP.ino b/adem/libraries/WiFiManager/examples/AutoConnectWithStaticIP/AutoConnectWithStaticIP.ino index af343cd..86556d3 100644 --- a/adem/libraries/WiFiManager/examples/AutoConnectWithStaticIP/AutoConnectWithStaticIP.ino +++ b/adem/libraries/WiFiManager/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/adem/libraries/WiFiManager/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino b/adem/libraries/WiFiManager/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino index edf4f46..2f2d0cc 100644 --- a/adem/libraries/WiFiManager/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/adem/libraries/WiFiManager/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -5,7 +5,7 @@ #include #include //https://github.com/tzapu/WiFiManager -// select wich pin will trigger the configuraton portal when set to LOW +// select which pin will trigger the configuration portal when set to LOW // ESP-01 users please note: the only pins available (0 and 2), are shared // with the bootloader, so always set them HIGH at power-up #define TRIGGER_PIN 0 diff --git a/adem/libraries/WiFiManager/examples/bufferedWrite/BufferedWrite.ino b/adem/libraries/WiFiManager/examples/bufferedWrite/BufferedWrite.ino deleted file mode 100644 index 52de70b..0000000 --- a/adem/libraries/WiFiManager/examples/bufferedWrite/BufferedWrite.ino +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include -#include -#include "BufferedResponse.h" - -ESP8266WebServer server(80); - -#define WIFI_WAIT 5 - -const char *ssid = ""; -const char *password = ""; - - -void loop() { - server.handleClient(); -}; - - -void handleRoot() { - BufferedResponse response(server, "text/plain", 200, 1024); - - for (uint32_t i = 0; i < 50000; i++) - response.printf("%10i", i); -} -void setupWifi() { - WiFi.hostname("webtest"); - WiFi.begin(ssid, password); - - // Wait for connection - didn't do so??? - int s = WIFI_WAIT; - while (s > 0 && WiFi.status() != WL_CONNECTED) { - delay(1000); - s--; - } -} - - -void setup() { - Serial.begin(9600); - setupWifi(); - - server.on("/", handleRoot); - - server.begin(); - Serial.println("HTTP server started"); -}; \ No newline at end of file diff --git a/adem/libraries/WiFiManager/examples/myAutoConnectWithFSParametersAndCustomIP/myAutoConnectWithFSParametersAndCustomIP.ino b/adem/libraries/WiFiManager/examples/myAutoConnectWithFSParametersAndCustomIP/myAutoConnectWithFSParametersAndCustomIP.ino deleted file mode 100644 index 21a3268..0000000 --- a/adem/libraries/WiFiManager/examples/myAutoConnectWithFSParametersAndCustomIP/myAutoConnectWithFSParametersAndCustomIP.ino +++ /dev/null @@ -1,339 +0,0 @@ -#include //this needs to be first, or it all crashes and burns... - -#include //https://github.com/esp8266/Arduino - -//needed for library -#include -#include -#include //https://github.com/tzapu/myWiFiManager - -#include //https://github.com/bblanchon/ArduinoJson - -//define your default values here, if there are different values in config.json, they are overwritten. -//length should be max size + 1 - -//const char HTTP_PARAM[] PROGMEM = "Gps
barometer
humidity
accelero
"; - -const char demo_html[] PROGMEM = -"\n" -"\n" -" \n" -" ADEM Demo\n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" ik-adem.be\n" -"
\n" -" " -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -"
🚬N/A PM1.0
N/Apc/.01ft³
💨N/Aµg/m³
🏭N/A PM2.5
N/Apc/.01ft³
💨N/Aµg/m³
☀️N/A °C
💧N/A %
N/A mbar
\n" -"
\n" -" \n" -" \n" -""; - - -//flag for saving data -bool shouldSaveConfig = false; -char SSID[32]; -int config = 7; -myWiFiManager myWifiManager; -myWiFiManagerParameter * custom_config; -myWiFiManagerParameter * demo; -myWiFiManagerParameter * sensors_parm; - -char pagebuf[1024]; -String page = ""; - -//callback notifying us of the need to save config -void saveConfigCallback () { - Serial.println("Should save config"); - shouldSaveConfig = true; -} - -String SetupDemoPage(void){ - return FPSTR(demo_html); -} - -String sensors(void) { - StaticJsonBuffer<256> jsonBuffer; - char data[256]; - - JsonObject& root = jsonBuffer.createObject(); - StaticJsonBuffer<256> jsonBufferBar; - - JsonObject& bar = jsonBufferBar.createObject(); - bar["Sensor"] = "BMP085/BMP180"; - bar["Temperature"] = "23"; - bar["Pressure"] = "1024"; - bar.printTo(data,sizeof(data)); - root["barometer"] = data; - StaticJsonBuffer<256> jsonBufferHum; - JsonObject& hum = jsonBufferHum.createObject(); - hum["Sensor"] = "HTU21DF"; - hum["Temperature"] = "22"; - hum["Humidity"] = "64"; - hum.printTo(data,sizeof(data)); - root["humidity"] = data; - StaticJsonBuffer<256> jsonBufferPar; - JsonObject& part = jsonBufferPar.createObject(); - part["Sensor"] = "PPD42"; - part["PM1"] = "5002"; - part["PM2.5"] = "4242"; - part.printTo(data,sizeof(data)); - root["particulate"] = data; - root.printTo(data, sizeof(data)); - - Serial.println("{\"barometer\":{\"Sensor\":\"BMP085/BMP180\",\"Temperature\":23.2,\"Pressuse\":1021.34},\"humidity\":{\"Sensor\":\"HTU21DF\",\"Temperature\":21.3,\"Humidity\":53.2},\"PPparticulateD42\":{\"Sensor\":\"PPD42\",\"PM1\":2103,\"PM2.5\":5302}}"); - - return FPSTR("{\"barometer\":{\"Sensor\":\"BMP085/BMP180\",\"Temperature\":23.2,\"Pressuse\":1021.34},\"humidity\":{\"Sensor\":\"HTU21DF\",\"Temperature\":21.3,\"Humidity\":53.2},\"particulate\":{\"Sensor\":\"PPD42\",\"PM1\":2103,\"PM2.5\":5302}}"); -} - -void setup() { - // put your setup code here, to run once: - Serial.begin(115200); - Serial.println(); - sprintf(SSID, "ADEM-%d", ESP.getChipId()); - //clean FS, for testing - //SPIFFS.format(); - - - // The extra parameters to be configured (can be either global or just in the setup) - // After connecting, parameter.getValue() will get you the configured value - // id/name placeholder/prompt default length - //myWiFiManagerParameter custom_config(HTTP_PARAM); - page += ""; - page += "
0) { - char c = Serial.read(); - if (c != '\n' and c != '\r') { - switch (c) { - case 'o': - Serial.print("Turning WiFi off... "); - - // Disable WIFI - //wifi_set_sleep_type(LIGHT_SLEEP_T); - WiFi.disconnect(); - WiFi.mode(WIFI_OFF); - //KOV WiFi.forceSleepBegin(); - //KOV delay(1); // needed to go to sleep - - Serial.println("OK"); - delay(3000); - break; - case 'a': - myWifiManager.setSleepAfterAutoConnect(false); - if (myWifiManager.autoConnect()) { - Serial.println("client connected = true "); - } - else { - Serial.println("client connected = false"); - } - break; - case 'c': - myWifiManager.setSleepAfterAutoConnect(true); - if (myWifiManager.autoConnect()) { - Serial.println("client connected = true "); - } - else { - Serial.println("client connected = false"); - WiFi.disconnect(); - WiFi.mode(WIFI_OFF); - Serial.println("Wifi off"); - } - break; - case 'p' : - if (myWifiManager.startConfigPortal(SSID)) { - Serial.println("station connected = true "); - } - else { - Serial.println("station connected = false "); - } - break; - case 'r' : - Serial.print(F("Reading SSID : ")); - Serial.println(WiFi.SSID()); - Serial.print(F("Reading Password :")); - Serial.println(WiFi.psk()); - break; - case 'v' : - Serial.print(F("get Value : ")); - Serial.println(custom_config->getValue()); - break; - case 'i' : - Serial.print(F("get ID : ")); - Serial.println(custom_config->getID()); - break; - case 'h' : - Serial.print(F("get HTML : ")); - Serial.println(custom_config->getCustomHTML()); - break; - } - } - } -} diff --git a/adem/libraries/WiFiManager/extras/WiFiManager.template.html b/adem/libraries/WiFiManager/extras/WiFiManager.template.html new file mode 100644 index 0000000..e15593b --- /dev/null +++ b/adem/libraries/WiFiManager/extras/WiFiManager.template.html @@ -0,0 +1,80 @@ + + + + + + {v} + + + + + + + + + + +
+ + + + + + + + +



+ + +
{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
+ + + + + + +
+ + + diff --git a/adem/libraries/WiFiManager/extras/parse.js b/adem/libraries/WiFiManager/extras/parse.js new file mode 100644 index 0000000..97a3e38 --- /dev/null +++ b/adem/libraries/WiFiManager/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('