update wifi manager
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user