From 54904d316b6f30e554140023c151f066d490298f Mon Sep 17 00:00:00 2001 From: tablatronix Date: Tue, 1 Dec 2020 10:09:01 -0600 Subject: [PATCH] add info page ota update --- WiFiManager.cpp | 25 +++++++++++++++++++++++-- WiFiManager.h | 8 ++++++-- strings_en.h | 3 ++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 51df76c..0d99c65 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1116,7 +1116,11 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ // DEBUG_WM(DEBUG_DEV,"scanNetworks async:",async == true); // DEBUG_WM(DEBUG_DEV,_numNetworks,(millis()-_lastscan )); // DEBUG_WM(DEBUG_DEV,"scanNetworks force:",force == true); - if(force || _numNetworks == 0 || (millis()-_lastscan > 60000)){ + if(_numNetworks == 0){ + DEBUG_WM(DEBUG_DEV,"NO APs found forcing new scan"); + force = true; + } + if(force || (millis()-_lastscan > 60000)){ int8_t res; _startscan = millis(); if(async && _asyncScan){ @@ -1126,6 +1130,7 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ using namespace std::placeholders; // for `_1` WiFi.scanNetworksAsync(std::bind(&WiFiManager::WiFi_scanComplete,this,_1)); #else + DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan SYNC started")); res = WiFi.scanNetworks(); #endif #else @@ -1135,6 +1140,7 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ return false; } else{ + DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan SYNC started")); res = WiFi.scanNetworks(); } if(res == WIFI_SCAN_FAILED) DEBUG_WM(DEBUG_ERROR,"[ERROR] scan failed"); @@ -1566,6 +1572,10 @@ void WiFiManager::handleInfo() { if(infoids[i] != NULL) page += getInfoData(infoids[i]); } page += F(""); + if(_showInfoUpdate){ + page += HTTP_PORTAL_MENU[8]; + page += HTTP_PORTAL_MENU[9]; + } if(_showInfoErase) page += FPSTR(HTTP_ERASEBTN); if(_showBack) page += FPSTR(HTTP_BACKBTN); page += FPSTR(HTTP_HELP); @@ -1768,7 +1778,7 @@ String WiFiManager::getInfoData(String id){ } /** - * HTTPD CALLBACK root or redirect to captive portal + * HTTPD CALLBACK exit, closes configportal if blocking, if non blocking undefined */ void WiFiManager::handleExit() { DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Exit")); @@ -1777,6 +1787,7 @@ void WiFiManager::handleExit() { page += FPSTR(S_exiting); // @token exiting server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); server->send(200, FPSTR(HTTP_HEAD_CT), page); + delay(2000); abort = true; } @@ -1884,7 +1895,9 @@ void WiFiManager::stopCaptivePortal(){ // @todo maybe disable configportaltimeout(optional), or just provide callback for user } +// HTTPD CALLBACK, handle close, stop captive portal, if not enabled undefined void WiFiManager::handleClose(){ + DEBUG_WM(DEBUG_VERBOSE,F("Disabling Captive Portal")); stopCaptivePortal(); DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP close")); handleRequest(); @@ -2408,6 +2421,14 @@ void WiFiManager::setShowInfoErase(boolean enabled){ _showInfoErase = enabled; } +/** + * toggle showing update upload web ota button on info page + * @param boolean enabled + */ +void WiFiManager::setShowInfoUpdate(boolean enabled){ + _showInfoUpdate = enabled; +} + /** * set menu items and order * if param is present in menu , params will be removed from wifi page automatically diff --git a/WiFiManager.h b/WiFiManager.h index 1e70e24..20e68a9 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -298,7 +298,10 @@ class WiFiManager // show erase wifi onfig button on info page, true void setShowInfoErase(boolean enabled); - + + // show OTA upload button on info page + void setShowInfoUpdate(boolean enabled); + // set ap channel void setWiFiAPChannel(int32_t channel); @@ -437,6 +440,7 @@ class WiFiManager boolean _scanDispOptions = false; // show percentage in scans not icons boolean _paramsInWifi = true; // show custom parameters on wifi page boolean _showInfoErase = true; // info page erase button + boolean _showInfoUpdate = true; // info page update button boolean _showBack = false; // show back button boolean _enableConfigPortal = true; // use config portal if autoconnect failed const char * _hostname = ""; // hostname for esp8266 for dhcp, and or MDNS @@ -454,7 +458,7 @@ class WiFiManager // cache time helps throttle this // async enables asyncronous scans, so they do not block anything // the refresh button bypasses cache - boolean _preloadwifiscan = true; // preload wifiscan if true + boolean _preloadwifiscan = false; // preload wifiscan if true boolean _asyncScan = false; // perform wifi network scan async unsigned int _scancachetime = 30000; // ms cache time for background scans diff --git a/strings_en.h b/strings_en.h index 373380f..83c665d 100644 --- a/strings_en.h +++ b/strings_en.h @@ -61,6 +61,7 @@ const char HTTP_SAVED[] PROGMEM = "
Saving Credential const char HTTP_PARAMSAVED[] PROGMEM = "
Saved
"; const char HTTP_END[] PROGMEM = "
"; const char HTTP_ERASEBTN[] PROGMEM = "
"; +const char HTTP_UPDATEBTN[] PROGMEM = "
"; const char HTTP_BACKBTN[] PROGMEM = "

"; const char HTTP_STATUS_ON[] PROGMEM = "
Connected to {v}
with IP {i}
"; @@ -209,7 +210,7 @@ const char S_titlereset[] PROGMEM = "Reset"; const char S_titleerase[] PROGMEM = "Erase"; const char S_titleclose[] PROGMEM = "Close"; const char S_options[] PROGMEM = "options"; -const char S_nonetworks[] PROGMEM = "No networks found. Refresh to scan again."; +const char S_nonetworks[] PROGMEM = "No networks found. Refresh to scan again.\n"; const char S_staticip[] PROGMEM = "Static IP"; const char S_staticgw[] PROGMEM = "Static Gateway"; const char S_staticdns[] PROGMEM = "Static DNS";