update wifi manager

This commit is contained in:
technyon
2022-07-04 20:23:34 +02:00
parent 9e5cf0ce25
commit 6c655e16e4
10 changed files with 211 additions and 100 deletions

View File

@@ -506,7 +506,7 @@ I get stuck in ap mode when the power goes out or modem resets, try a setConfigP
- param menu/page (setup) added to separate params from wifi page, handled automatically by setMenu - param menu/page (setup) added to separate params from wifi page, handled automatically by setMenu
- set custom root menu - set custom root menu
- disable configportal on autoconnect - disable configportal on autoconnect
- wm parameters initialize is now protected, allowing child classes, example included - wm parameters init is now protected, allowing child classes, example included
- wifiscans are precached and async for faster page loads, refresh forces rescan - wifiscans are precached and async for faster page loads, refresh forces rescan
- adds esp32 gettemperature ( currently commented out, useful for relative measurement only ) - adds esp32 gettemperature ( currently commented out, useful for relative measurement only )

View File

@@ -137,7 +137,7 @@ bool WiFiManager::addParameter(WiFiManagerParameter *p) {
} }
} }
// initialize params if never malloc // init params if never malloc
if(_params == NULL){ if(_params == NULL){
#ifdef WM_DEBUG_LEVEL #ifdef WM_DEBUG_LEVEL
DEBUG_WM(DEBUG_DEV,F("allocating params bytes:"),_max_params * sizeof(WiFiManagerParameter*)); DEBUG_WM(DEBUG_DEV,F("allocating params bytes:"),_max_params * sizeof(WiFiManagerParameter*));
@@ -517,6 +517,7 @@ bool WiFiManager::startAP(){
*/ */
void WiFiManager::startWebPortal() { void WiFiManager::startWebPortal() {
if(configPortalActive || webPortalActive) return; if(configPortalActive || webPortalActive) return;
connect = abort = false;
setupConfigPortal(); setupConfigPortal();
webPortalActive = true; webPortalActive = true;
} }
@@ -637,9 +638,8 @@ void WiFiManager::setupDNSD(){
} }
void WiFiManager::setupConfigPortal() { void WiFiManager::setupConfigPortal() {
setupHTTPServer(); setupHTTPServer();
_lastscan = 0; // reset network scan cache
if(_preloadwifiscan) WiFi_scanNetworks(true,true); // preload wifiscan , async if(_preloadwifiscan) WiFi_scanNetworks(true,true); // preload wifiscan , async
} }
@@ -692,7 +692,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
WiFi_enableSTA(true); WiFi_enableSTA(true);
} }
// initialize configportal globals to known states // init configportal globals to known states
configPortalActive = true; configPortalActive = true;
bool result = connect = abort = false; // loop flags, connect true success, abort true break bool result = connect = abort = false; // loop flags, connect true success, abort true break
uint8_t state; uint8_t state;
@@ -714,7 +714,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
_apcallback(this); _apcallback(this);
} }
// initialize configportal // init configportal
#ifdef WM_DEBUG_LEVEL #ifdef WM_DEBUG_LEVEL
DEBUG_WM(DEBUG_DEV,F("setupConfigPortal")); DEBUG_WM(DEBUG_DEV,F("setupConfigPortal"));
#endif #endif
@@ -728,7 +728,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
if(!_configPortalIsBlocking){ if(!_configPortalIsBlocking){
#ifdef WM_DEBUG_LEVEL #ifdef WM_DEBUG_LEVEL
DEBUG_WM(DEBUG_VERBOSE,F("Config Portal Running, non blocking/processing")); DEBUG_WM(DEBUG_VERBOSE,F("Config Portal Running, non blocking (processing)"));
if(_configPortalTimeout > 0) DEBUG_WM(DEBUG_VERBOSE,F("Portal Timeout In"),(String)(_configPortalTimeout/1000) + (String)F(" seconds")); if(_configPortalTimeout > 0) DEBUG_WM(DEBUG_VERBOSE,F("Portal Timeout In"),(String)(_configPortalTimeout/1000) + (String)F(" seconds"));
#endif #endif
return result; // skip blocking loop return result; // skip blocking loop
@@ -851,7 +851,7 @@ uint8_t WiFiManager::processConfigPortal(){
_savewificallback(); _savewificallback();
} }
if(!_connectonsave) return WL_IDLE_STATUS; if(!_connectonsave) return WL_IDLE_STATUS;
shutdownConfigPortal(); if(_disableConfigPortal) shutdownConfigPortal();
return WL_CONNECTED; // CONNECT SUCCESS return WL_CONNECTED; // CONNECT SUCCESS
} }
#ifdef WM_DEBUG_LEVEL #ifdef WM_DEBUG_LEVEL
@@ -870,7 +870,7 @@ uint8_t WiFiManager::processConfigPortal(){
#endif #endif
_savewificallback(); _savewificallback();
} }
shutdownConfigPortal(); if(_disableConfigPortal) shutdownConfigPortal();
return WL_CONNECT_FAILED; // CONNECT FAIL return WL_CONNECT_FAILED; // CONNECT FAIL
} }
else if(_configPortalIsBlocking){ else if(_configPortalIsBlocking){
@@ -1383,6 +1383,10 @@ String WiFiManager::getMenuOut(){
for(auto menuId :_menuIds ){ for(auto menuId :_menuIds ){
if((String)_menutokens[menuId] == "param" && _paramsCount == 0) continue; // no params set, omit params from menu, @todo this may be undesired by someone, use only menu to force? if((String)_menutokens[menuId] == "param" && _paramsCount == 0) continue; // no params set, omit params from menu, @todo this may be undesired by someone, use only menu to force?
if((String)_menutokens[menuId] == "custom" && _customMenuHTML!=NULL){
page += _customMenuHTML;
continue;
}
page += HTTP_PORTAL_MENU[menuId]; page += HTTP_PORTAL_MENU[menuId];
} }
@@ -1423,7 +1427,7 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){
DEBUG_WM(DEBUG_DEV,"NO APs found forcing new scan"); DEBUG_WM(DEBUG_DEV,"NO APs found forcing new scan");
force = true; force = true;
} }
if(force || (millis()-_lastscan > 60000)){ if(force || (_lastscan>0 && (millis()-_lastscan > 60000))){
int8_t res; int8_t res;
_startscan = millis(); _startscan = millis();
if(async && _asyncScan){ if(async && _asyncScan){
@@ -1888,7 +1892,7 @@ void WiFiManager::handleInfo() {
//@todo convert to enum or refactor to strings //@todo convert to enum or refactor to strings
//@todo wrap in build flag to remove all info code for memory saving //@todo wrap in build flag to remove all info code for memory saving
#ifdef ESP8266 #ifdef ESP8266
infos = 29; infos = 28;
String infoids[] = { String infoids[] = {
F("esphead"), F("esphead"),
F("uptime"), F("uptime"),
@@ -1896,7 +1900,6 @@ void WiFiManager::handleInfo() {
F("fchipid"), F("fchipid"),
F("idesize"), F("idesize"),
F("flashsize"), F("flashsize"),
F("sdkver"),
F("corever"), F("corever"),
F("bootver"), F("bootver"),
F("cpufreq"), F("cpufreq"),
@@ -1923,7 +1926,7 @@ void WiFiManager::handleInfo() {
#elif defined(ESP32) #elif defined(ESP32)
// add esp_chip_info ? // add esp_chip_info ?
infos = 27; infos = 26;
String infoids[] = { String infoids[] = {
F("esphead"), F("esphead"),
F("uptime"), F("uptime"),
@@ -1931,7 +1934,6 @@ void WiFiManager::handleInfo() {
F("chiprev"), F("chiprev"),
F("idesize"), F("idesize"),
F("flashsize"), F("flashsize"),
F("sdkver"),
F("cpufreq"), F("cpufreq"),
F("freeheap"), F("freeheap"),
F("memsketch"), F("memsketch"),
@@ -1960,6 +1962,14 @@ void WiFiManager::handleInfo() {
if(infoids[i] != NULL) page += getInfoData(infoids[i]); if(infoids[i] != NULL) page += getInfoData(infoids[i]);
} }
page += F("</dl>"); page += F("</dl>");
page += F("<h3>About</h3><hr><dl>");
page += getInfoData("aboutver");
page += getInfoData("aboutarduinover");
page += getInfoData("aboutidfver");
page += getInfoData("aboutdate");
page += F("</dl>");
if(_showInfoUpdate){ if(_showInfoUpdate){
page += HTTP_PORTAL_MENU[8]; page += HTTP_PORTAL_MENU[8];
page += HTTP_PORTAL_MENU[9]; page += HTTP_PORTAL_MENU[9];
@@ -2023,15 +2033,6 @@ String WiFiManager::getInfoData(String id){
p.replace(FPSTR(T_1),(String)ESP.getPsramSize()); p.replace(FPSTR(T_1),(String)ESP.getPsramSize());
#endif #endif
} }
else if(id==F("sdkver")){
p = FPSTR(HTTP_INFO_sdkver);
#ifdef ESP32
p.replace(FPSTR(T_1),(String)esp_get_idf_version());
// p.replace(FPSTR(T_1),(String)system_get_sdk_version()); // deprecated
#else
p.replace(FPSTR(T_1),(String)system_get_sdk_version());
#endif
}
else if(id==F("corever")){ else if(id==F("corever")){
#ifdef ESP8266 #ifdef ESP8266
p = FPSTR(HTTP_INFO_corever); p = FPSTR(HTTP_INFO_corever);
@@ -2178,6 +2179,35 @@ String WiFiManager::getInfoData(String id){
p.replace(FPSTR(T_3),"NA"); p.replace(FPSTR(T_3),"NA");
} }
#endif #endif
else if(id==F("aboutver")){
p = FPSTR(HTTP_INFO_aboutver);
p.replace(FPSTR(T_1),FPSTR(WM_VERSION_STR));
}
else if(id==F("aboutarduinover")){
#ifdef VER_ARDUINO_STR
p = FPSTR(HTTP_INFO_aboutarduino);
p.replace(FPSTR(T_1),String(VER_ARDUINO_STR));
#endif
}
// else if(id==F("aboutidfver")){
// #ifdef VER_IDF_STR
// p = FPSTR(HTTP_INFO_aboutidf);
// p.replace(FPSTR(T_1),String(VER_IDF_STR));
// #endif
// }
else if(id==F("aboutsdkver")){
p = FPSTR(HTTP_INFO_sdkver);
#ifdef ESP32
p.replace(FPSTR(T_1),(String)esp_get_idf_version());
// p.replace(FPSTR(T_1),(String)system_get_sdk_version()); // deprecated
#else
p.replace(FPSTR(T_1),(String)system_get_sdk_version());
#endif
}
else if(id==F("aboutdate")){
p = FPSTR(HTTP_INFO_aboutdate);
p.replace(FPSTR(T_1),String(__DATE__) + " " + String(__TIME__));
}
return p; return p;
} }
@@ -2485,9 +2515,10 @@ void WiFiManager::resetSettings() {
DEBUG_WM(F("resetSettings")); DEBUG_WM(F("resetSettings"));
#endif #endif
WiFi_enableSTA(true,true); // must be sta to disconnect erase WiFi_enableSTA(true,true); // must be sta to disconnect erase
delay(500); // ensure sta is enabled
if (_resetcallback != NULL) if (_resetcallback != NULL){
_resetcallback(); _resetcallback();
}
#ifdef ESP32 #ifdef ESP32
WiFi.disconnect(true,true); WiFi.disconnect(true,true);
@@ -2711,17 +2742,27 @@ void WiFiManager::setPreOtaUpdateCallback( std::function<void()> func ) {
* @param {[type]} void (*func)(void) * @param {[type]} void (*func)(void)
*/ */
void WiFiManager::setDisconnectedCallback( std::function<void()> func ) { void WiFiManager::setDisconnectedCallback( std::function<void()> func ) {
_disconnectedcallback = func; _disconnectedcallback = func;
} }
/** /**
* set custom head html * set custom head html
* custom element will be added to head, eg. new style tag etc. * custom element will be added to head, eg. new meta,style,script tag etc.
* @access public * @access public
* @param char element * @param char element
*/ */
void WiFiManager::setCustomHeadElement(const char* element) { void WiFiManager::setCustomHeadElement(const char* html) {
_customHeadElement = element; _customHeadElement = html;
}
/**
* set custom menu html
* custom element will be added to menu under custom menu item.
* @access public
* @param char element
*/
void WiFiManager::setCustomMenuHTML(const char* html) {
_customMenuHTML = html;
} }
/** /**
@@ -2868,6 +2909,17 @@ void WiFiManager::setEnableConfigPortal(boolean enable)
_enableConfigPortal = enable; _enableConfigPortal = enable;
} }
/**
* toggle configportal if autoconnect failed
* if enabled, then the configportal will be de-activated on wifi save
* @since $dev
* @access public
* @param boolean enabled [true]
*/
void WiFiManager::setDisableConfigPortal(boolean enable)
{
_disableConfigPortal = enable;
}
/** /**
* set the hostname (dhcp client id) * set the hostname (dhcp client id)
@@ -3380,10 +3432,10 @@ bool WiFiManager::WiFiSetCountry(){
// ret = esp_wifi_set_bandwidth(WIFI_IF_AP,WIFI_BW_HT20); // WIFI_BW_HT40 // ret = esp_wifi_set_bandwidth(WIFI_IF_AP,WIFI_BW_HT20); // WIFI_BW_HT40
#ifdef ESP32 #ifdef ESP32
esp_err_t err = ESP_OK; esp_err_t err = ESP_OK;
// @todo check if wifi is initialize, no idea how, doesnt seem to be exposed atm ( might be now! ) // @todo check if wifi is init, no idea how, doesnt seem to be exposed atm ( might be now! )
if(WiFi.getMode() == WIFI_MODE_NULL){ if(WiFi.getMode() == WIFI_MODE_NULL){
DEBUG_WM(DEBUG_ERROR,"[ERROR] cannot set country, wifi not initialize"); DEBUG_WM(DEBUG_ERROR,"[ERROR] cannot set country, wifi not init");
} // exception if wifi not initialize! } // exception if wifi not init!
else if(_wificountry == "US") err = esp_wifi_set_country(&WM_COUNTRY_US); else if(_wificountry == "US") err = esp_wifi_set_country(&WM_COUNTRY_US);
else if(_wificountry == "JP") err = esp_wifi_set_country(&WM_COUNTRY_JP); else if(_wificountry == "JP") err = esp_wifi_set_country(&WM_COUNTRY_JP);
else if(_wificountry == "CN") err = esp_wifi_set_country(&WM_COUNTRY_CN); else if(_wificountry == "CN") err = esp_wifi_set_country(&WM_COUNTRY_CN);
@@ -3400,7 +3452,7 @@ bool WiFiManager::WiFiSetCountry(){
ret = err == ESP_OK; ret = err == ESP_OK;
#elif defined(ESP8266) && !defined(WM_NOCOUNTRY) #elif defined(ESP8266) && !defined(WM_NOCOUNTRY)
// if(WiFi.getMode() == WIFI_OFF); // exception if wifi not initialize! // if(WiFi.getMode() == WIFI_OFF); // exception if wifi not init!
if(_wificountry == "US") ret = wifi_set_country((wifi_country_t*)&WM_COUNTRY_US); if(_wificountry == "US") ret = wifi_set_country((wifi_country_t*)&WM_COUNTRY_US);
else if(_wificountry == "JP") ret = wifi_set_country((wifi_country_t*)&WM_COUNTRY_JP); else if(_wificountry == "JP") ret = wifi_set_country((wifi_country_t*)&WM_COUNTRY_JP);
else if(_wificountry == "CN") ret = wifi_set_country((wifi_country_t*)&WM_COUNTRY_CN); else if(_wificountry == "CN") ret = wifi_set_country((wifi_country_t*)&WM_COUNTRY_CN);
@@ -3588,7 +3640,7 @@ String WiFiManager::WiFi_psk(bool persistent) const {
return String(reinterpret_cast<char*>(tmp)); return String(reinterpret_cast<char*>(tmp));
#elif defined(ESP32) #elif defined(ESP32)
// only if wifi is initialize // only if wifi is init
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){ if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
return String(); return String();
} }
@@ -3623,7 +3675,7 @@ String WiFiManager::WiFi_psk(bool persistent) const {
if(_disconnectedcallback != nullptr) if(_disconnectedcallback != nullptr)
{ {
_disconnectedcallback(); _disconnectedcallback();
} }
#ifdef WM_DEBUG_LEVEL #ifdef WM_DEBUG_LEVEL
@@ -3663,7 +3715,7 @@ void WiFiManager::WiFi_autoReconnect(){
DEBUG_WM(DEBUG_VERBOSE,F("ESP32 event handler enabled")); DEBUG_WM(DEBUG_VERBOSE,F("ESP32 event handler enabled"));
#endif #endif
using namespace std::placeholders; using namespace std::placeholders;
wm_event_id = WiFi.onEvent(std::bind(&WiFiManager::WiFiEvent,this,_1,_2)); if(wm_event_id == 0) wm_event_id = WiFi.onEvent(std::bind(&WiFiManager::WiFiEvent,this,_1,_2));
// } // }
#endif #endif
} }

View File

@@ -50,6 +50,31 @@
#define G(string_literal) (String(FPSTR(string_literal)).c_str()) #define G(string_literal) (String(FPSTR(string_literal)).c_str())
#define STRING2(x) #x
#define STRING(x) STRING2(x)
// #include <esp_idf_version.h>
#ifdef ESP_IDF_VERSION
// #pragma message "ESP_IDF_VERSION_MAJOR = " STRING(ESP_IDF_VERSION_MAJOR)
// #pragma message "ESP_IDF_VERSION_MINOR = " STRING(ESP_IDF_VERSION_MINOR)
// #pragma message "ESP_IDF_VERSION_PATCH = " STRING(ESP_IDF_VERSION_PATCH)
#define VER_IDF_STR STRING(ESP_IDF_VERSION_MAJOR) "." STRING(ESP_IDF_VERSION_MINOR) "." STRING(ESP_IDF_VERSION_PATCH)
#endif
// #include "esp_arduino_version.h"
#ifdef ESP_ARDUINO_VERSION
// #pragma message "ESP_ARDUINO_VERSION_MAJOR = " STRING(ESP_ARDUINO_VERSION_MAJOR)
// #pragma message "ESP_ARDUINO_VERSION_MINOR = " STRING(ESP_ARDUINO_VERSION_MINOR)
// #pragma message "ESP_ARDUINO_VERSION_PATCH = " STRING(ESP_ARDUINO_VERSION_PATCH)
#define VER_ARDUINO_STR STRING(ESP_ARDUINO_VERSION_MAJOR) "." STRING(ESP_ARDUINO_VERSION_MINOR) "." STRING(ESP_ARDUINO_VERSION_PATCH)
#else
// #include <core_version.h>
// #pragma message "ESP_ARDUINO_VERSION_GIT = " STRING(ARDUINO_ESP32_GIT_VER)// 0x46d5afb1
// #pragma message "ESP_ARDUINO_VERSION_DESC = " STRING(ARDUINO_ESP32_GIT_DESC) // 1.0.6
#define VER_ARDUINO_STR "Unknown"
// #pragma message "ESP_ARDUINO_VERSION_REL = " STRING(ARDUINO_ESP32_RELEASE) //"1_0_6"
#endif
#ifdef ESP8266 #ifdef ESP8266
extern "C" { extern "C" {
@@ -67,29 +92,6 @@
#elif defined(ESP32) #elif defined(ESP32)
// #define STRING2(x) #x
// #define STRING(x) STRING2(x)
// // #include <esp_idf_version.h>
// #ifdef ESP_IDF_VERSION
// #pragma message "ESP_IDF_VERSION_MAJOR = " STRING(ESP_IDF_VERSION_MAJOR)
// #pragma message "ESP_IDF_VERSION_MINOR = " STRING(ESP_IDF_VERSION_MINOR)
// #pragma message "ESP_IDF_VERSION_PATCH = " STRING(ESP_IDF_VERSION_PATCH)
// #endif
// // #include "esp_arduino_version.h"
// #ifdef ESP_ARDUINO_VERSION
// #pragma message "ESP_ARDUINO_VERSION_MAJOR = " STRING(ESP_ARDUINO_VERSION_MAJOR)
// #pragma message "ESP_ARDUINO_VERSION_MINOR = " STRING(ESP_ARDUINO_VERSION_MINOR)
// #pragma message "ESP_ARDUINO_VERSION_PATCH = " STRING(ESP_ARDUINO_VERSION_PATCH)
// #else
// #include <core_version.h>
// #pragma message "ESP_ARDUINO_VERSION_GIT = " STRING(ARDUINO_ESP32_GIT_VER)// 0x46d5afb1
// #pragma message "ESP_ARDUINO_VERSION_DESC = " STRING(ARDUINO_ESP32_GIT_DESC) // 1.0.6
// // #pragma message "ESP_ARDUINO_VERSION_REL = " STRING(ARDUINO_ESP32_RELEASE) //"1_0_6"
// #endif
#include <Arduino.h>
#include <WiFi.h> #include <WiFi.h>
#include <esp_wifi.h> #include <esp_wifi.h>
#include <Update.h> #include <Update.h>
@@ -298,8 +300,11 @@ class WiFiManager
// setConfigPortalTimeout is ignored in this mode, user is responsible for closing configportal // setConfigPortalTimeout is ignored in this mode, user is responsible for closing configportal
void setConfigPortalBlocking(boolean shouldBlock); void setConfigPortalBlocking(boolean shouldBlock);
//add custom html at inside <head> for all pages
void setCustomHeadElement(const char* html);
//if this is set, customise style //if this is set, customise style
void setCustomHeadElement(const char* element); void setCustomMenuHTML(const char* html);
//if this is true, remove duplicated Access Points - defaut true //if this is true, remove duplicated Access Points - defaut true
void setRemoveDuplicateAPs(boolean removeDuplicates); void setRemoveDuplicateAPs(boolean removeDuplicates);
@@ -334,6 +339,9 @@ class WiFiManager
// if true (default) then start the config portal from autoConnect if connection failed // if true (default) then start the config portal from autoConnect if connection failed
void setEnableConfigPortal(boolean enable); void setEnableConfigPortal(boolean enable);
// if true (default) then stop the config portal from autoConnect when wifi is saved
void setDisableConfigPortal(boolean enable);
// set a custom hostname, sets sta and ap dhcp client id for esp32, and sta for esp8266 // set a custom hostname, sets sta and ap dhcp client id for esp32, and sta for esp8266
bool setHostname(const char * hostname); bool setHostname(const char * hostname);
bool setHostname(String hostname); bool setHostname(String hostname);
@@ -431,6 +439,7 @@ class WiFiManager
std::unique_ptr<WM_WebServer> server; std::unique_ptr<WM_WebServer> server;
private: private:
// vars
std::vector<uint8_t> _menuIds; std::vector<uint8_t> _menuIds;
std::vector<const char *> _menuIdsParams = {"wifi","param","info","exit"}; std::vector<const char *> _menuIdsParams = {"wifi","param","info","exit"};
std::vector<const char *> _menuIdsUpdate = {"wifi","param","info","update","exit"}; std::vector<const char *> _menuIdsUpdate = {"wifi","param","info","update","exit"};
@@ -445,9 +454,16 @@ class WiFiManager
IPAddress _sta_static_sn; IPAddress _sta_static_sn;
IPAddress _sta_static_dns; IPAddress _sta_static_dns;
unsigned long _configPortalStart = 0; // ms config portal start time (updated for timeouts)
unsigned long _webPortalAccessed = 0; // ms last web access time
uint8_t _lastconxresult = WL_IDLE_STATUS; // store last result when doing connect operations
int _numNetworks = 0; // init index for numnetworks wifiscans
unsigned long _lastscan = 0; // ms for timing wifi scans
unsigned long _startscan = 0; // ms for timing wifi scans
unsigned long _startconn = 0; // ms for timing wifi connects
// defaults // defaults
const byte DNS_PORT = 53; const byte DNS_PORT = 53;
const byte HTTP_PORT = 80;
String _apName = "no-net"; String _apName = "no-net";
String _apPassword = ""; String _apPassword = "";
String _ssid = ""; // var temp ssid String _ssid = ""; // var temp ssid
@@ -459,32 +475,26 @@ class WiFiManager
unsigned long _configPortalTimeout = 0; // ms close config portal loop if set (depending on _cp/webClientCheck options) unsigned long _configPortalTimeout = 0; // ms close config portal loop if set (depending on _cp/webClientCheck options)
unsigned long _connectTimeout = 0; // ms stop trying to connect to ap if set unsigned long _connectTimeout = 0; // ms stop trying to connect to ap if set
unsigned long _saveTimeout = 0; // ms stop trying to connect to ap on saves, in case bugs in esp waitforconnectresult unsigned long _saveTimeout = 0; // ms stop trying to connect to ap on saves, in case bugs in esp waitforconnectresult
unsigned long _configPortalStart = 0; // ms config portal start time (updated for timeouts)
unsigned long _webPortalAccessed = 0; // ms last web access time
WiFiMode_t _usermode = WIFI_STA; // Default user mode WiFiMode_t _usermode = WIFI_STA; // Default user mode
String _wifissidprefix = FPSTR(S_ssidpre); // auto apname prefix prefix+chipid String _wifissidprefix = FPSTR(S_ssidpre); // auto apname prefix prefix+chipid
uint8_t _lastconxresult = WL_IDLE_STATUS; // store last result when doing connect operations
int _numNetworks = 0; // initialize index for numnetworks wifiscans
unsigned long _lastscan = 0; // ms for timing wifi scans
unsigned long _startscan = 0; // ms for timing wifi scans
int _cpclosedelay = 2000; // delay before wifisave, prevents captive portal from closing to fast. int _cpclosedelay = 2000; // delay before wifisave, prevents captive portal from closing to fast.
bool _cleanConnect = false; // disconnect before connect in connectwifi, increases stability on connects bool _cleanConnect = false; // disconnect before connect in connectwifi, increases stability on connects
bool _connectonsave = true; // connect to wifi when saving creds bool _connectonsave = true; // connect to wifi when saving creds
bool _disableSTA = false; // disable sta when starting ap, always bool _disableSTA = false; // disable sta when starting ap, always
bool _disableSTAConn = true; // disable sta when starting ap, if sta is not connected ( stability ) bool _disableSTAConn = true; // disable sta when starting ap, if sta is not connected ( stability )
bool _channelSync = false; // use same wifi sta channel when starting ap bool _channelSync = false; // use same wifi sta channel when starting ap
int32_t _apChannel = 0; // channel to use for ap int32_t _apChannel = 0; // default channel to use for ap, 0 for auto
bool _apHidden = false; // store softap hidden value bool _apHidden = false; // store softap hidden value
uint16_t _httpPort = 80; // port for webserver uint16_t _httpPort = 80; // port for webserver
// uint8_t _retryCount = 0; // counter for retries, probably not needed if synchronous // uint8_t _retryCount = 0; // counter for retries, probably not needed if synchronous
uint8_t _connectRetries = 1; // number of sta connect retries, force reconnect, wait loop (connectimeout) does not always work and first disconnect bails uint8_t _connectRetries = 1; // number of sta connect retries, force reconnect, wait loop (connectimeout) does not always work and first disconnect bails
unsigned long _startconn = 0; // ms for timing wifi connects
bool _aggresiveReconn = false; // use an agrressive reconnect strategy, WILL delay conxs bool _aggresiveReconn = false; // use an agrressive reconnect strategy, WILL delay conxs
// on some conn failure modes will add delays and many retries to work around esp and ap bugs, ie, anti de-auth protections // on some conn failure modes will add delays and many retries to work around esp and ap bugs, ie, anti de-auth protections
bool _allowExit = true; // allow exit non blocking bool _allowExit = true; // allow exit non blocking
#ifdef ESP32 #ifdef ESP32
wifi_event_id_t wm_event_id; wifi_event_id_t wm_event_id = 0;
static uint8_t _lastconxresulttmp; // tmp var for esp32 callback static uint8_t _lastconxresulttmp; // tmp var for esp32 callback
#endif #endif
@@ -494,8 +504,8 @@ class WiFiManager
// parameter options // parameter options
int _minimumQuality = -1; // filter wifiscan ap by this rssi int _minimumQuality = -1; // filter wifiscan ap by this rssi
int _staShowStaticFields = 0; // ternary 1=always show static ip fields, 0=only if set, -1=never(cannot change ips via web!) int _staShowStaticFields = 0; // ternary 1=always show static ip fields, 0=only if set, -1=never(cannot change ips via web!)
int _staShowDns = 0; // ternary 1=always show dns, 0=only if set, -1=never(cannot change dns via web!) int _staShowDns = 0; // ternary 1=always show dns, 0=only if set, -1=never(cannot change dns via web!)
boolean _removeDuplicateAPs = true; // remove dup aps from wifiscan boolean _removeDuplicateAPs = true; // remove dup aps from wifiscan
boolean _showPassword = false; // show or hide saved password on wifi form, might be a security issue! boolean _showPassword = false; // show or hide saved password on wifi form, might be a security issue!
boolean _shouldBreakAfterConfig = false; // stop configportal on save failure boolean _shouldBreakAfterConfig = false; // stop configportal on save failure
@@ -510,10 +520,12 @@ class WiFiManager
boolean _showInfoErase = true; // info page erase button boolean _showInfoErase = true; // info page erase button
boolean _showInfoUpdate = true; // info page update button boolean _showInfoUpdate = true; // info page update button
boolean _showBack = false; // show back button boolean _showBack = false; // show back button
boolean _enableConfigPortal = true; // use config portal if autoconnect failed boolean _enableConfigPortal = true; // FOR autoconnect - start config portal if autoconnect failed
boolean _disableConfigPortal = true; // FOR autoconnect - stop config portal if cp wifi save
String _hostname = ""; // hostname for esp8266 for dhcp, and or MDNS String _hostname = ""; // hostname for esp8266 for dhcp, and or MDNS
const char* _customHeadElement = ""; // store custom head element html from user const char* _customHeadElement = ""; // store custom head element html from user isnide <head>
const char* _customMenuHTML = ""; // store custom head element html from user inside <>
String _bodyClass = ""; // class to add to body String _bodyClass = ""; // class to add to body
String _title = FPSTR(S_brand); // app title - default WiFiManager String _title = FPSTR(S_brand); // app title - default WiFiManager
@@ -649,8 +661,8 @@ class WiFiManager
String getInfoData(String id); String getInfoData(String id);
// flags // flags
boolean connect; boolean connect = false;
boolean abort; boolean abort = false;
boolean reset = false; boolean reset = false;
boolean configPortalActive = false; boolean configPortalActive = false;
boolean webPortalActive = false; boolean webPortalActive = false;

View File

@@ -13,7 +13,7 @@ void setup() {
// reset settings - wipe stored credentials for testing // reset settings - wipe stored credentials for testing
// these are stored by the esp library // these are stored by the esp library
//wm.resetSettings(); wm.resetSettings();
// Automatically connect using saved credentials, // Automatically connect using saved credentials,
// if connection fails, it starts an access point with the specified name ( "AutoConnectAP"), // if connection fails, it starts an access point with the specified name ( "AutoConnectAP"),

View File

@@ -23,7 +23,6 @@ WiFiManager wm;
// TEST OPTION FLAGS // TEST OPTION FLAGS
bool TEST_CP = false; // always start the configportal, even if ap found
bool TEST_CP = true; // always start the configportal, even if ap found bool TEST_CP = true; // always start the configportal, even if ap found
int TESP_CP_TIMEOUT = 90; // test cp timeout int TESP_CP_TIMEOUT = 90; // test cp timeout
@@ -66,7 +65,7 @@ void handleRoute(){
} }
void setup() { void setup() {
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP // WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
// put your setup code here, to run once: // put your setup code here, to run once:
Serial.begin(115200); Serial.begin(115200);
@@ -91,6 +90,7 @@ void setup() {
// wm.erase(); // wm.erase();
// setup some parameters // setup some parameters
WiFiManagerParameter custom_html("<p style=\"color:pink;font-weight:Bold;\">This Is Custom HTML</p>"); // only custom html WiFiManagerParameter custom_html("<p style=\"color:pink;font-weight:Bold;\">This Is Custom HTML</p>"); // only custom html
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "", 40); WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "", 40);
WiFiManagerParameter custom_mqtt_port("port", "mqtt port", "", 6); WiFiManagerParameter custom_mqtt_port("port", "mqtt port", "", 6);
@@ -144,6 +144,14 @@ void setup() {
custom_html.setValue("test",4); custom_html.setValue("test",4);
custom_token.setValue("test",4); custom_token.setValue("test",4);
// set custom html head content , inside <head>
const char* headhtml = "<meta name='color-scheme' content='dark light'><style></style><script></script>";
wm.setCustomHeadElement(headhtml);
// set custom html menu content , inside <head>
const char* menuhtml = "<form action='/custom' method='get'><button>Custom</button></form><br/>\n";
wm.setCustomMenuHTML(menuhtml);
// invert theme, dark // invert theme, dark
wm.setDarkMode(true); wm.setDarkMode(true);
@@ -156,7 +164,7 @@ void setup() {
wm.setMenu(menu,9); // custom menu array must provide length wm.setMenu(menu,9); // custom menu array must provide length
*/ */
std::vector<const char *> menu = {"wifi","wifinoscan","info","param","close","sep","erase","update","restart","exit"}; std::vector<const char *> menu = {"wifi","wifinoscan","info","param","custom","close","sep","erase","update","restart","exit"};
wm.setMenu(menu); // custom menu, pass vector wm.setMenu(menu); // custom menu, pass vector
// wm.setParamsPage(true); // move params to seperate page, not wifi, do not combine with setmenu! // wm.setParamsPage(true); // move params to seperate page, not wifi, do not combine with setmenu!
@@ -235,6 +243,9 @@ void setup() {
wifiInfo(); wifiInfo();
// to preload autoconnect with credentials
// wm.preloadWiFi("ssid","password");
if(!wm.autoConnect("WM_AutoConnectAP","12345678")) { if(!wm.autoConnect("WM_AutoConnectAP","12345678")) {
Serial.println("failed to connect and hit timeout"); Serial.println("failed to connect and hit timeout");
} }
@@ -243,7 +254,7 @@ void setup() {
delay(1000); delay(1000);
Serial.println("TEST_CP ENABLED"); Serial.println("TEST_CP ENABLED");
wm.setConfigPortalTimeout(TESP_CP_TIMEOUT); wm.setConfigPortalTimeout(TESP_CP_TIMEOUT);
wm.startConfigPortal("WM_ConnectAP"); wm.startConfigPortal("WM_ConnectAP","12345678");
} }
else { else {
//if you get here you have connected to the WiFi //if you get here you have connected to the WiFi
@@ -260,10 +271,11 @@ void setup() {
} }
void wifiInfo(){ void wifiInfo(){
WiFi.printDiag(Serial); Serial.println("[WIFI] WIFI INFO DEBUG");
Serial.println("SAVED: " + (String)wm.getWiFiIsSaved() ? "YES" : "NO"); // WiFi.printDiag(Serial);
Serial.println("SSID: " + (String)wm.getWiFiSSID()); Serial.println("[WIFI] SAVED: " + (String)(wm.getWiFiIsSaved() ? "YES" : "NO"));
Serial.println("PASS: " + (String)wm.getWiFiPass()); Serial.println("[WIFI] SSID: " + (String)wm.getWiFiSSID());
Serial.println("[WIFI] PASS: " + (String)wm.getWiFiPass());
} }
void loop() { void loop() {

View File

@@ -173,10 +173,29 @@ button.D{
background-color:#dc3630; background-color:#dc3630;
} }
input:disabled { button{
opacity: 0.5; /*transition: 0s filter;*/
transition: 0s opacity;
transition-delay: 3s;
transition-duration: 0s;
cursor: pointer;
} }
button:active{
opacity: 50% !important;
/*filter: brightness(50%);*/
cursor: wait;
transition-delay: 0s;
}
button:hover{
/*opacity: 80%;*/
}
input:disabled {
opacity: 0.5;
/* not working in cp ?? */
}
</style> </style>
<!-- /HTTP_STYLE --> <!-- /HTTP_STYLE -->
<!-- HTTP_SCRIPT --> <!-- HTTP_SCRIPT -->
@@ -318,7 +337,12 @@ input:disabled {
<tr><td><a href='/erase'>/erase</a></td> <tr><td><a href='/erase'>/erase</a></td>
<td>Erase WiFi configuration and reboot Device. Device will not reconnect to a network until new WiFi configuration data is entered.</td></tr> <td>Erase WiFi configuration and reboot Device. Device will not reconnect to a network until new WiFi configuration data is entered.</td></tr>
</table> </table>
<p/>More information about WiFiManager at <a href='https://github.com/tzapu/WiFiManager'>https://github.com/tzapu/WiFiManager</a> <h3>About</h3><hr>
Version v1.x.x-xxxxx<Br/>
Build_date<br/>
Build_file<br/>
Arduino_version<br/>
<p/>Github <a href='https://github.com/tzapu/WiFiManager'>https://github.com/tzapu/WiFiManager</a>
<!-- /HTTP_HELP --> <!-- /HTTP_HELP -->
<!-- FORM_UPLOAD --> <!-- FORM_UPLOAD -->
<Br/><br/>Form UPLOAD<br/> <Br/><br/>Form UPLOAD<br/>

View File

@@ -1,6 +1,6 @@
{ {
"name": "WiFiManager", "name": "WiFiManager",
"version": "2.0.9-beta", "version": "2.0.11-beta",
"keywords": "wifi,wi-fi,esp,esp8266,esp32,espressif8266,espressif32,nodemcu,wemos,arduino", "keywords": "wifi,wi-fi,esp,esp8266,esp32,espressif8266,espressif32,nodemcu,wemos,arduino",
"description": "WiFi Configuration manager with web configuration portal for ESP boards", "description": "WiFi Configuration manager with web configuration portal for ESP boards",
"authors": "authors":

View File

@@ -1,5 +1,5 @@
name=WiFiManager name=WiFiManager
version=2.0.9-beta version=2.0.11-beta
author=tzapu author=tzapu
maintainer=tablatronix maintainer=tablatronix
sentence=WiFi Configuration manager with web configuration portal for Espressif ESPx boards, by tzapu sentence=WiFi Configuration manager with web configuration portal for Espressif ESPx boards, by tzapu

View File

@@ -13,9 +13,12 @@
#ifndef _WM_STRINGS_H_ #ifndef _WM_STRINGS_H_
#define _WM_STRINGS_H_ #define _WM_STRINGS_H_
#ifndef WIFI_MANAGER_OVERRIDE_STRINGS #ifndef WIFI_MANAGER_OVERRIDE_STRINGS
// !!! ABOVE WILL NOT WORK if you define in your sketch, must be build flag, if anyone one knows how to order includes to be able to do this it would be neat.. I have seen it done.. // !!! ABOVE WILL NOT WORK if you define in your sketch, must be build flag, if anyone one knows how to order includes to be able to do this it would be neat.. I have seen it done..
const char WM_VERSION_STR[] PROGMEM = "v1.0.11-beta";
const char HTTP_HEAD_START[] PROGMEM = "<!DOCTYPE html>" const char HTTP_HEAD_START[] PROGMEM = "<!DOCTYPE html>"
"<html lang='en'><head>" "<html lang='en'><head>"
"<meta name='format-detection' content='telephone=no'>" "<meta name='format-detection' content='telephone=no'>"
@@ -100,7 +103,9 @@ const char HTTP_STYLE[] PROGMEM = "<style>"
"dt{font-weight:bold}dd{margin:0;padding:0 0 0.5em 0;min-height:12px}" "dt{font-weight:bold}dd{margin:0;padding:0 0 0.5em 0;min-height:12px}"
"td{vertical-align: top;}" "td{vertical-align: top;}"
".h{display:none}" ".h{display:none}"
"button{transition: 0s opacity;transition-delay: 3s;transition-duration: 0s;cursor: pointer}"
"button.D{background-color:#dc3630}" "button.D{background-color:#dc3630}"
"button:active{opacity:50% !important;cursor:wait;transition-delay: 0s}"
// invert // invert
"body.invert,body.invert a,body.invert h1 {background-color:#060606;color:#fff;}" "body.invert,body.invert a,body.invert h1 {background-color:#060606;color:#fff;}"
"body.invert .msg{color:#fff;background-color:#282828;border-top:1px solid #555;border-right:1px solid #555;border-bottom:1px solid #555;}" "body.invert .msg{color:#fff;background-color:#282828;border-top:1px solid #555;border-right:1px solid #555;border-bottom:1px solid #555;}"
@@ -134,7 +139,7 @@ const char HTTP_HELP[] PROGMEM =
"<tr><td>/erase</td>" "<tr><td>/erase</td>"
"<td>Erase WiFi configuration and reboot Device. Device will not reconnect to a network until new WiFi configuration data is entered.</td></tr>" "<td>Erase WiFi configuration and reboot Device. Device will not reconnect to a network until new WiFi configuration data is entered.</td></tr>"
"</table>" "</table>"
"<p/>More information about WiFiManager at <a href='https://github.com/tzapu/WiFiManager'>https://github.com/tzapu/WiFiManager</a>."; "<p/>Github <a href='https://github.com/tzapu/WiFiManager'>https://github.com/tzapu/WiFiManager</a>.";
#else #else
const char HTTP_HELP[] PROGMEM = ""; const char HTTP_HELP[] PROGMEM = "";
#endif #endif
@@ -164,6 +169,7 @@ const char HTTP_JS[] PROGMEM =
#endif #endif
// Info html // Info html
// @todo remove html elements from progmem, repetetive strings
#ifdef ESP32 #ifdef ESP32
const char HTTP_INFO_esphead[] PROGMEM = "<h3>esp32</h3><hr><dl>"; const char HTTP_INFO_esphead[] PROGMEM = "<h3>esp32</h3><hr><dl>";
const char HTTP_INFO_chiprev[] PROGMEM = "<dt>Chip Rev</dt><dd>{1}</dd>"; const char HTTP_INFO_chiprev[] PROGMEM = "<dt>Chip Rev</dt><dd>{1}</dd>";
@@ -203,6 +209,10 @@ const char HTTP_INFO_stamac[] PROGMEM = "<dt>Station MAC</dt><dd>{1}</dd>";
const char HTTP_INFO_conx[] PROGMEM = "<dt>Connected</dt><dd>{1}</dd>"; const char HTTP_INFO_conx[] PROGMEM = "<dt>Connected</dt><dd>{1}</dd>";
const char HTTP_INFO_autoconx[] PROGMEM = "<dt>Autoconnect</dt><dd>{1}</dd>"; const char HTTP_INFO_autoconx[] PROGMEM = "<dt>Autoconnect</dt><dd>{1}</dd>";
const char HTTP_INFO_aboutver[] PROGMEM = "<dt>WiFiManager</dt><dd>{1}</dd>";
const char HTTP_INFO_aboutarduino[] PROGMEM = "<dt>Arduino</dt><dd>{1}</dd>";
const char HTTP_INFO_aboutsdk[] PROGMEM = "<dt>ESP-SDK/IDF</dt><dd>{1}</dd>";
const char HTTP_INFO_aboutdate[] PROGMEM = "<dt>Build Date</dt><dd>{1}</dd>";
const char S_brand[] PROGMEM = "WiFiManager"; const char S_brand[] PROGMEM = "WiFiManager";
const char S_debugPrefix[] PROGMEM = "*wm:"; const char S_debugPrefix[] PROGMEM = "*wm:";
@@ -249,8 +259,8 @@ const char D_HR[] PROGMEM = "--------------------";
// ----------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------
// DO NOT EDIT BELOW THIS LINE // DO NOT EDIT BELOW THIS LINE
const uint8_t _nummenutokens = 10; const uint8_t _nummenutokens = 11;
const char * const _menutokens[10] PROGMEM = { const char * const _menutokens[_nummenutokens] PROGMEM = {
"wifi", "wifi",
"wifinoscan", "wifinoscan",
"info", "info",
@@ -260,7 +270,8 @@ const char * const _menutokens[10] PROGMEM = {
"exit", "exit",
"erase", "erase",
"update", "update",
"sep" "sep",
"custom"
}; };
const char R_root[] PROGMEM = "/"; const char R_root[] PROGMEM = "/";

View File

@@ -173,8 +173,8 @@ void setup()
restartTs = preferences->getInt(preference_restart_timer) * 60 * 1000; restartTs = preferences->getInt(preference_restart_timer) * 60 * 1000;
} }
// const NetworkDeviceType networkDevice = NetworkDeviceType::WiFi; const NetworkDeviceType networkDevice = NetworkDeviceType::WiFi;
const NetworkDeviceType networkDevice = digitalRead(NETWORK_SELECT) == HIGH ? NetworkDeviceType::WiFi : NetworkDeviceType::W5500; // const NetworkDeviceType networkDevice = digitalRead(NETWORK_SELECT) == HIGH ? NetworkDeviceType::WiFi : NetworkDeviceType::W5500;
network = new Network(networkDevice, preferences); network = new Network(networkDevice, preferences);
network->initialize(); network->initialize();