update wifi manager
This commit is contained in:
@@ -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
|
||||
- set custom root menu
|
||||
- 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
|
||||
- adds esp32 gettemperature ( currently commented out, useful for relative measurement only )
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ bool WiFiManager::addParameter(WiFiManagerParameter *p) {
|
||||
}
|
||||
}
|
||||
|
||||
// initialize params if never malloc
|
||||
// init params if never malloc
|
||||
if(_params == NULL){
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_DEV,F("allocating params bytes:"),_max_params * sizeof(WiFiManagerParameter*));
|
||||
@@ -517,6 +517,7 @@ bool WiFiManager::startAP(){
|
||||
*/
|
||||
void WiFiManager::startWebPortal() {
|
||||
if(configPortalActive || webPortalActive) return;
|
||||
connect = abort = false;
|
||||
setupConfigPortal();
|
||||
webPortalActive = true;
|
||||
}
|
||||
@@ -637,9 +638,8 @@ void WiFiManager::setupDNSD(){
|
||||
}
|
||||
|
||||
void WiFiManager::setupConfigPortal() {
|
||||
|
||||
setupHTTPServer();
|
||||
|
||||
_lastscan = 0; // reset network scan cache
|
||||
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);
|
||||
}
|
||||
|
||||
// initialize configportal globals to known states
|
||||
// init configportal globals to known states
|
||||
configPortalActive = true;
|
||||
bool result = connect = abort = false; // loop flags, connect true success, abort true break
|
||||
uint8_t state;
|
||||
@@ -714,7 +714,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
|
||||
_apcallback(this);
|
||||
}
|
||||
|
||||
// initialize configportal
|
||||
// init configportal
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_DEV,F("setupConfigPortal"));
|
||||
#endif
|
||||
@@ -728,7 +728,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
|
||||
|
||||
if(!_configPortalIsBlocking){
|
||||
#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"));
|
||||
#endif
|
||||
return result; // skip blocking loop
|
||||
@@ -851,7 +851,7 @@ uint8_t WiFiManager::processConfigPortal(){
|
||||
_savewificallback();
|
||||
}
|
||||
if(!_connectonsave) return WL_IDLE_STATUS;
|
||||
shutdownConfigPortal();
|
||||
if(_disableConfigPortal) shutdownConfigPortal();
|
||||
return WL_CONNECTED; // CONNECT SUCCESS
|
||||
}
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
@@ -870,7 +870,7 @@ uint8_t WiFiManager::processConfigPortal(){
|
||||
#endif
|
||||
_savewificallback();
|
||||
}
|
||||
shutdownConfigPortal();
|
||||
if(_disableConfigPortal) shutdownConfigPortal();
|
||||
return WL_CONNECT_FAILED; // CONNECT FAIL
|
||||
}
|
||||
else if(_configPortalIsBlocking){
|
||||
@@ -1383,6 +1383,10 @@ String WiFiManager::getMenuOut(){
|
||||
|
||||
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] == "custom" && _customMenuHTML!=NULL){
|
||||
page += _customMenuHTML;
|
||||
continue;
|
||||
}
|
||||
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");
|
||||
force = true;
|
||||
}
|
||||
if(force || (millis()-_lastscan > 60000)){
|
||||
if(force || (_lastscan>0 && (millis()-_lastscan > 60000))){
|
||||
int8_t res;
|
||||
_startscan = millis();
|
||||
if(async && _asyncScan){
|
||||
@@ -1473,7 +1477,7 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan completed"), "in "+(String)(_lastscan - _startscan)+" ms");
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Scan is cached"),(String)(millis()-_lastscan )+" ms ago");
|
||||
@@ -1888,7 +1892,7 @@ void WiFiManager::handleInfo() {
|
||||
//@todo convert to enum or refactor to strings
|
||||
//@todo wrap in build flag to remove all info code for memory saving
|
||||
#ifdef ESP8266
|
||||
infos = 29;
|
||||
infos = 28;
|
||||
String infoids[] = {
|
||||
F("esphead"),
|
||||
F("uptime"),
|
||||
@@ -1896,7 +1900,6 @@ void WiFiManager::handleInfo() {
|
||||
F("fchipid"),
|
||||
F("idesize"),
|
||||
F("flashsize"),
|
||||
F("sdkver"),
|
||||
F("corever"),
|
||||
F("bootver"),
|
||||
F("cpufreq"),
|
||||
@@ -1923,7 +1926,7 @@ void WiFiManager::handleInfo() {
|
||||
|
||||
#elif defined(ESP32)
|
||||
// add esp_chip_info ?
|
||||
infos = 27;
|
||||
infos = 26;
|
||||
String infoids[] = {
|
||||
F("esphead"),
|
||||
F("uptime"),
|
||||
@@ -1931,7 +1934,6 @@ void WiFiManager::handleInfo() {
|
||||
F("chiprev"),
|
||||
F("idesize"),
|
||||
F("flashsize"),
|
||||
F("sdkver"),
|
||||
F("cpufreq"),
|
||||
F("freeheap"),
|
||||
F("memsketch"),
|
||||
@@ -1960,6 +1962,14 @@ void WiFiManager::handleInfo() {
|
||||
if(infoids[i] != NULL) page += getInfoData(infoids[i]);
|
||||
}
|
||||
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){
|
||||
page += HTTP_PORTAL_MENU[8];
|
||||
page += HTTP_PORTAL_MENU[9];
|
||||
@@ -2023,15 +2033,6 @@ String WiFiManager::getInfoData(String id){
|
||||
p.replace(FPSTR(T_1),(String)ESP.getPsramSize());
|
||||
#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")){
|
||||
#ifdef ESP8266
|
||||
p = FPSTR(HTTP_INFO_corever);
|
||||
@@ -2178,6 +2179,35 @@ String WiFiManager::getInfoData(String id){
|
||||
p.replace(FPSTR(T_3),"NA");
|
||||
}
|
||||
#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;
|
||||
}
|
||||
|
||||
@@ -2290,7 +2320,7 @@ boolean WiFiManager::captivePortal() {
|
||||
#endif
|
||||
|
||||
if(!_enableCaptivePortal) return false; // skip redirections, @todo maybe allow redirection even when no cp ? might be useful
|
||||
|
||||
|
||||
String serverLoc = toStringIp(server->client()->localIP());
|
||||
if(_httpPort != 80) serverLoc += ":" + (String)_httpPort; // add port if not default
|
||||
bool doredirect = serverLoc != server->hostHeader(); // redirect if hostheader not server ip, prevent redirect loops
|
||||
@@ -2485,9 +2515,10 @@ void WiFiManager::resetSettings() {
|
||||
DEBUG_WM(F("resetSettings"));
|
||||
#endif
|
||||
WiFi_enableSTA(true,true); // must be sta to disconnect erase
|
||||
|
||||
if (_resetcallback != NULL)
|
||||
delay(500); // ensure sta is enabled
|
||||
if (_resetcallback != NULL){
|
||||
_resetcallback();
|
||||
}
|
||||
|
||||
#ifdef ESP32
|
||||
WiFi.disconnect(true,true);
|
||||
@@ -2711,17 +2742,27 @@ void WiFiManager::setPreOtaUpdateCallback( std::function<void()> func ) {
|
||||
* @param {[type]} void (*func)(void)
|
||||
*/
|
||||
void WiFiManager::setDisconnectedCallback( std::function<void()> func ) {
|
||||
_disconnectedcallback = func;
|
||||
_disconnectedcallback = func;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param char element
|
||||
*/
|
||||
void WiFiManager::setCustomHeadElement(const char* element) {
|
||||
_customHeadElement = element;
|
||||
void WiFiManager::setCustomHeadElement(const char* html) {
|
||||
_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
@@ -3380,10 +3432,10 @@ bool WiFiManager::WiFiSetCountry(){
|
||||
// ret = esp_wifi_set_bandwidth(WIFI_IF_AP,WIFI_BW_HT20); // WIFI_BW_HT40
|
||||
#ifdef ESP32
|
||||
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){
|
||||
DEBUG_WM(DEBUG_ERROR,"[ERROR] cannot set country, wifi not initialize");
|
||||
} // exception if wifi not initialize!
|
||||
DEBUG_WM(DEBUG_ERROR,"[ERROR] cannot set country, wifi not init");
|
||||
} // exception if wifi not init!
|
||||
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 == "CN") err = esp_wifi_set_country(&WM_COUNTRY_CN);
|
||||
@@ -3400,7 +3452,7 @@ bool WiFiManager::WiFiSetCountry(){
|
||||
ret = err == ESP_OK;
|
||||
|
||||
#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);
|
||||
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);
|
||||
@@ -3588,7 +3640,7 @@ String WiFiManager::WiFi_psk(bool persistent) const {
|
||||
return String(reinterpret_cast<char*>(tmp));
|
||||
|
||||
#elif defined(ESP32)
|
||||
// only if wifi is initialize
|
||||
// only if wifi is init
|
||||
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
|
||||
return String();
|
||||
}
|
||||
@@ -3623,7 +3675,7 @@ String WiFiManager::WiFi_psk(bool persistent) const {
|
||||
|
||||
if(_disconnectedcallback != nullptr)
|
||||
{
|
||||
_disconnectedcallback();
|
||||
_disconnectedcallback();
|
||||
}
|
||||
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
@@ -3663,7 +3715,7 @@ void WiFiManager::WiFi_autoReconnect(){
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("ESP32 event handler enabled"));
|
||||
#endif
|
||||
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
|
||||
}
|
||||
|
||||
@@ -50,6 +50,31 @@
|
||||
|
||||
#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
|
||||
|
||||
extern "C" {
|
||||
@@ -67,29 +92,6 @@
|
||||
|
||||
#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 <esp_wifi.h>
|
||||
#include <Update.h>
|
||||
@@ -298,9 +300,12 @@ class WiFiManager
|
||||
// setConfigPortalTimeout is ignored in this mode, user is responsible for closing configportal
|
||||
void setConfigPortalBlocking(boolean shouldBlock);
|
||||
|
||||
//add custom html at inside <head> for all pages
|
||||
void setCustomHeadElement(const char* html);
|
||||
|
||||
//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
|
||||
void setRemoveDuplicateAPs(boolean removeDuplicates);
|
||||
|
||||
@@ -333,7 +338,10 @@ class WiFiManager
|
||||
|
||||
// if true (default) then start the config portal from autoConnect if connection failed
|
||||
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
|
||||
bool setHostname(const char * hostname);
|
||||
bool setHostname(String hostname);
|
||||
@@ -431,6 +439,7 @@ class WiFiManager
|
||||
std::unique_ptr<WM_WebServer> server;
|
||||
|
||||
private:
|
||||
// vars
|
||||
std::vector<uint8_t> _menuIds;
|
||||
std::vector<const char *> _menuIdsParams = {"wifi","param","info","exit"};
|
||||
std::vector<const char *> _menuIdsUpdate = {"wifi","param","info","update","exit"};
|
||||
@@ -445,9 +454,16 @@ class WiFiManager
|
||||
IPAddress _sta_static_sn;
|
||||
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
|
||||
const byte DNS_PORT = 53;
|
||||
const byte HTTP_PORT = 80;
|
||||
String _apName = "no-net";
|
||||
String _apPassword = "";
|
||||
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 _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 _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
|
||||
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.
|
||||
bool _cleanConnect = false; // disconnect before connect in connectwifi, increases stability on connects
|
||||
bool _connectonsave = true; // connect to wifi when saving creds
|
||||
bool _disableSTA = false; // disable sta when starting ap, always
|
||||
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
|
||||
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
|
||||
uint16_t _httpPort = 80; // port for webserver
|
||||
// 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
|
||||
unsigned long _startconn = 0; // ms for timing wifi connects
|
||||
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
|
||||
bool _allowExit = true; // allow exit non blocking
|
||||
|
||||
#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
|
||||
#endif
|
||||
|
||||
@@ -494,8 +504,8 @@ class WiFiManager
|
||||
|
||||
// parameter options
|
||||
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 _staShowDns = 0; // ternary 1=always show dns, 0=only if set, -1=never(cannot change dns 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!)
|
||||
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 _shouldBreakAfterConfig = false; // stop configportal on save failure
|
||||
@@ -510,10 +520,12 @@ class WiFiManager
|
||||
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
|
||||
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
|
||||
|
||||
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 _title = FPSTR(S_brand); // app title - default WiFiManager
|
||||
|
||||
@@ -649,8 +661,8 @@ class WiFiManager
|
||||
String getInfoData(String id);
|
||||
|
||||
// flags
|
||||
boolean connect;
|
||||
boolean abort;
|
||||
boolean connect = false;
|
||||
boolean abort = false;
|
||||
boolean reset = false;
|
||||
boolean configPortalActive = false;
|
||||
boolean webPortalActive = false;
|
||||
|
||||
@@ -13,7 +13,7 @@ void setup() {
|
||||
|
||||
// reset settings - wipe stored credentials for testing
|
||||
// these are stored by the esp library
|
||||
//wm.resetSettings();
|
||||
wm.resetSettings();
|
||||
|
||||
// Automatically connect using saved credentials,
|
||||
// if connection fails, it starts an access point with the specified name ( "AutoConnectAP"),
|
||||
|
||||
@@ -23,7 +23,6 @@ WiFiManager wm;
|
||||
|
||||
|
||||
// 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
|
||||
int TESP_CP_TIMEOUT = 90; // test cp timeout
|
||||
|
||||
@@ -66,7 +65,7 @@ void handleRoute(){
|
||||
}
|
||||
|
||||
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:
|
||||
Serial.begin(115200);
|
||||
@@ -91,6 +90,7 @@ void setup() {
|
||||
// wm.erase();
|
||||
|
||||
// setup some parameters
|
||||
|
||||
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_port("port", "mqtt port", "", 6);
|
||||
@@ -144,6 +144,14 @@ void setup() {
|
||||
custom_html.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
|
||||
wm.setDarkMode(true);
|
||||
|
||||
@@ -156,7 +164,7 @@ void setup() {
|
||||
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.setParamsPage(true); // move params to seperate page, not wifi, do not combine with setmenu!
|
||||
@@ -235,6 +243,9 @@ void setup() {
|
||||
|
||||
wifiInfo();
|
||||
|
||||
// to preload autoconnect with credentials
|
||||
// wm.preloadWiFi("ssid","password");
|
||||
|
||||
if(!wm.autoConnect("WM_AutoConnectAP","12345678")) {
|
||||
Serial.println("failed to connect and hit timeout");
|
||||
}
|
||||
@@ -243,7 +254,7 @@ void setup() {
|
||||
delay(1000);
|
||||
Serial.println("TEST_CP ENABLED");
|
||||
wm.setConfigPortalTimeout(TESP_CP_TIMEOUT);
|
||||
wm.startConfigPortal("WM_ConnectAP");
|
||||
wm.startConfigPortal("WM_ConnectAP","12345678");
|
||||
}
|
||||
else {
|
||||
//if you get here you have connected to the WiFi
|
||||
@@ -260,10 +271,11 @@ void setup() {
|
||||
}
|
||||
|
||||
void wifiInfo(){
|
||||
WiFi.printDiag(Serial);
|
||||
Serial.println("SAVED: " + (String)wm.getWiFiIsSaved() ? "YES" : "NO");
|
||||
Serial.println("SSID: " + (String)wm.getWiFiSSID());
|
||||
Serial.println("PASS: " + (String)wm.getWiFiPass());
|
||||
Serial.println("[WIFI] WIFI INFO DEBUG");
|
||||
// WiFi.printDiag(Serial);
|
||||
Serial.println("[WIFI] SAVED: " + (String)(wm.getWiFiIsSaved() ? "YES" : "NO"));
|
||||
Serial.println("[WIFI] SSID: " + (String)wm.getWiFiSSID());
|
||||
Serial.println("[WIFI] PASS: " + (String)wm.getWiFiPass());
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
@@ -173,10 +173,29 @@ button.D{
|
||||
background-color:#dc3630;
|
||||
}
|
||||
|
||||
input:disabled {
|
||||
opacity: 0.5;
|
||||
button{
|
||||
/*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>
|
||||
<!-- /HTTP_STYLE -->
|
||||
<!-- HTTP_SCRIPT -->
|
||||
@@ -318,7 +337,12 @@ input:disabled {
|
||||
<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>
|
||||
</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 -->
|
||||
<!-- FORM_UPLOAD -->
|
||||
<Br/><br/>Form UPLOAD<br/>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "WiFiManager",
|
||||
"version": "2.0.9-beta",
|
||||
"version": "2.0.11-beta",
|
||||
"keywords": "wifi,wi-fi,esp,esp8266,esp32,espressif8266,espressif32,nodemcu,wemos,arduino",
|
||||
"description": "WiFi Configuration manager with web configuration portal for ESP boards",
|
||||
"authors":
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name=WiFiManager
|
||||
version=2.0.9-beta
|
||||
version=2.0.11-beta
|
||||
author=tzapu
|
||||
maintainer=tablatronix
|
||||
sentence=WiFi Configuration manager with web configuration portal for Espressif ESPx boards, by tzapu
|
||||
|
||||
@@ -13,9 +13,12 @@
|
||||
#ifndef _WM_STRINGS_H_
|
||||
#define _WM_STRINGS_H_
|
||||
|
||||
|
||||
#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..
|
||||
|
||||
const char WM_VERSION_STR[] PROGMEM = "v1.0.11-beta";
|
||||
|
||||
const char HTTP_HEAD_START[] PROGMEM = "<!DOCTYPE html>"
|
||||
"<html lang='en'><head>"
|
||||
"<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}"
|
||||
"td{vertical-align: top;}"
|
||||
".h{display:none}"
|
||||
"button{transition: 0s opacity;transition-delay: 3s;transition-duration: 0s;cursor: pointer}"
|
||||
"button.D{background-color:#dc3630}"
|
||||
"button:active{opacity:50% !important;cursor:wait;transition-delay: 0s}"
|
||||
// invert
|
||||
"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;}"
|
||||
@@ -134,7 +139,7 @@ const char HTTP_HELP[] PROGMEM =
|
||||
"<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>"
|
||||
"</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
|
||||
const char HTTP_HELP[] PROGMEM = "";
|
||||
#endif
|
||||
@@ -164,6 +169,7 @@ const char HTTP_JS[] PROGMEM =
|
||||
#endif
|
||||
|
||||
// Info html
|
||||
// @todo remove html elements from progmem, repetetive strings
|
||||
#ifdef ESP32
|
||||
const char HTTP_INFO_esphead[] PROGMEM = "<h3>esp32</h3><hr><dl>";
|
||||
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_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_debugPrefix[] PROGMEM = "*wm:";
|
||||
@@ -249,8 +259,8 @@ const char D_HR[] PROGMEM = "--------------------";
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
// DO NOT EDIT BELOW THIS LINE
|
||||
|
||||
const uint8_t _nummenutokens = 10;
|
||||
const char * const _menutokens[10] PROGMEM = {
|
||||
const uint8_t _nummenutokens = 11;
|
||||
const char * const _menutokens[_nummenutokens] PROGMEM = {
|
||||
"wifi",
|
||||
"wifinoscan",
|
||||
"info",
|
||||
@@ -260,7 +270,8 @@ const char * const _menutokens[10] PROGMEM = {
|
||||
"exit",
|
||||
"erase",
|
||||
"update",
|
||||
"sep"
|
||||
"sep",
|
||||
"custom"
|
||||
};
|
||||
|
||||
const char R_root[] PROGMEM = "/";
|
||||
|
||||
Reference in New Issue
Block a user