mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-13 14:51:21 +10:00
Merge branch 'development' into constWiFiManagerParameter
This commit is contained in:
+194
-118
@@ -68,6 +68,12 @@ WiFiManagerParameter::~WiFiManagerParameter() {
|
||||
_length=0; // setting length 0, ideally the entire parameter should be removed, or added to wifimanager scope so it follows
|
||||
}
|
||||
|
||||
// WiFiManagerParameter& WiFiManagerParameter::operator=(const WiFiManagerParameter& rhs){
|
||||
// Serial.println("copy assignment op called");
|
||||
// (*this->_value) = (*rhs._value);
|
||||
// return *this;
|
||||
// }
|
||||
|
||||
// @note debug is not available in wmparameter class
|
||||
void WiFiManagerParameter::setValue(const char *defaultValue, int length) {
|
||||
if(!_id){
|
||||
@@ -89,6 +95,7 @@ void WiFiManagerParameter::setValue(const char *defaultValue, int length) {
|
||||
}
|
||||
}
|
||||
const char* WiFiManagerParameter::getValue() const {
|
||||
// Serial.println(printf("Address of _value is %p\n", (void *)_value));
|
||||
return _value;
|
||||
}
|
||||
const char* WiFiManagerParameter::getID() const {
|
||||
@@ -206,9 +213,10 @@ WiFiManager::~WiFiManager() {
|
||||
}
|
||||
|
||||
// @todo remove event
|
||||
// #ifdef ESP32
|
||||
// WiFi.removeEvent(std::bind(&WiFiManager::WiFiEvent,this));
|
||||
// #endif
|
||||
// WiFi.onEvent(std::bind(&WiFiManager::WiFiEvent,this,_1,_2));
|
||||
#ifdef ESP32
|
||||
WiFi.removeEvent(wm_event_id);
|
||||
#endif
|
||||
|
||||
DEBUG_WM(DEBUG_DEV,F("unloading"));
|
||||
}
|
||||
@@ -216,7 +224,7 @@ WiFiManager::~WiFiManager() {
|
||||
void WiFiManager::_begin(){
|
||||
if(_hasBegun) return;
|
||||
_hasBegun = true;
|
||||
_usermode = WiFi.getMode();
|
||||
// _usermode = WiFi.getMode();
|
||||
|
||||
#ifndef ESP32
|
||||
WiFi.persistent(false); // disable persistent so scannetworks and mode switching do not cause overwrites
|
||||
@@ -245,97 +253,117 @@ boolean WiFiManager::autoConnect() {
|
||||
*/
|
||||
boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
|
||||
DEBUG_WM(F("AutoConnect"));
|
||||
_begin();
|
||||
if(getWiFiIsSaved()){
|
||||
|
||||
// attempt to connect using saved settings, on fail fallback to AP config portal
|
||||
if(!WiFi.enableSTA(true)){
|
||||
// handle failure mode Brownout detector etc.
|
||||
DEBUG_WM(DEBUG_ERROR,"[FATAL] Unable to enable wifi!");
|
||||
return false;
|
||||
}
|
||||
|
||||
WiFiSetCountry();
|
||||
_begin();
|
||||
|
||||
#ifdef ESP32
|
||||
if(esp32persistent) WiFi.persistent(false); // disable persistent for esp32 after esp_wifi_start or else saves wont work
|
||||
#endif
|
||||
// attempt to connect using saved settings, on fail fallback to AP config portal
|
||||
if(!WiFi.enableSTA(true)){
|
||||
// handle failure mode Brownout detector etc.
|
||||
DEBUG_WM(DEBUG_ERROR,"[FATAL] Unable to enable wifi!");
|
||||
return false;
|
||||
}
|
||||
|
||||
WiFiSetCountry();
|
||||
|
||||
_usermode = WIFI_STA;
|
||||
|
||||
// no getter for autoreconnectpolicy before this
|
||||
// https://github.com/esp8266/Arduino/pull/4359
|
||||
// so we must force it on else, if not connectimeout then waitforconnectionresult gets stuck endless loop
|
||||
WiFi_autoReconnect();
|
||||
|
||||
// set hostname before stating
|
||||
if((String)_hostname != ""){
|
||||
DEBUG_WM(DEBUG_VERBOSE,"Setting hostname:",_hostname);
|
||||
bool res = true;
|
||||
#ifdef ESP8266
|
||||
res = WiFi.hostname(_hostname);
|
||||
#ifdef ESP8266MDNS_H
|
||||
DEBUG_WM(DEBUG_VERBOSE,"Setting MDNS hostname");
|
||||
if(MDNS.begin(_hostname)){
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
}
|
||||
#endif
|
||||
#elif defined(ESP32)
|
||||
// @note hostname must be set after STA_START
|
||||
delay(200); // do not remove, give time for STA_START
|
||||
res = WiFi.setHostname(_hostname);
|
||||
#ifdef ESP32MDNS_H
|
||||
DEBUG_WM(DEBUG_VERBOSE,"Setting MDNS hostname");
|
||||
if(MDNS.begin(_hostname)){
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
}
|
||||
#endif
|
||||
#ifdef ESP32
|
||||
if(esp32persistent) WiFi.persistent(false); // disable persistent for esp32 after esp_wifi_start or else saves wont work
|
||||
#endif
|
||||
|
||||
if(!res)DEBUG_WM(DEBUG_ERROR,F("[ERROR] hostname: set failed!"));
|
||||
|
||||
if(WiFi.status() == WL_CONNECTED){
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("reconnecting to set new hostname"));
|
||||
// WiFi.reconnect(); // This does not reset dhcp
|
||||
WiFi_Disconnect();
|
||||
delay(200); // do not remove, need a delay for disconnect to change status()
|
||||
}
|
||||
}
|
||||
|
||||
// if already connected, or try stored connect
|
||||
// @note @todo ESP32 has no autoconnect, so connectwifi will always be called unless user called begin etc before
|
||||
// @todo check if correct ssid == saved ssid when already connected
|
||||
bool connected = false;
|
||||
if (WiFi.status() == WL_CONNECTED){
|
||||
connected = true;
|
||||
DEBUG_WM(F("AutoConnect: ESP Already Connected"));
|
||||
setSTAConfig();
|
||||
}
|
||||
_usermode = WIFI_STA; // When using autoconnect , assume the user wants sta mode on permanently.
|
||||
|
||||
if(connected || connectWifi("", "") == WL_CONNECTED){
|
||||
//connected
|
||||
DEBUG_WM(F("AutoConnect: SUCCESS"));
|
||||
DEBUG_WM(F("STA IP Address:"),WiFi.localIP());
|
||||
_lastconxresult = WL_CONNECTED;
|
||||
// no getter for autoreconnectpolicy before this
|
||||
// https://github.com/esp8266/Arduino/pull/4359
|
||||
// so we must force it on else, if not connectimeout then waitforconnectionresult gets stuck endless loop
|
||||
WiFi_autoReconnect();
|
||||
|
||||
// set hostname before stating
|
||||
if((String)_hostname != ""){
|
||||
#ifdef ESP8266
|
||||
DEBUG_WM(DEBUG_DEV,"hostname: STA",WiFi.hostname());
|
||||
#elif defined(ESP32)
|
||||
DEBUG_WM(DEBUG_DEV,"hostname: STA",WiFi.getHostname());
|
||||
#endif
|
||||
setupHostname(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// possibly skip the config portal
|
||||
if (!_enableConfigPortal) {
|
||||
return false;
|
||||
}
|
||||
// if already connected, or try stored connect
|
||||
// @note @todo ESP32 has no autoconnect, so connectwifi will always be called unless user called begin etc before
|
||||
// @todo check if correct ssid == saved ssid when already connected
|
||||
bool connected = false;
|
||||
if (WiFi.status() == WL_CONNECTED){
|
||||
connected = true;
|
||||
DEBUG_WM(F("AutoConnect: ESP Already Connected"));
|
||||
setSTAConfig();
|
||||
// @todo not sure if this check makes sense, causes dup setSTAConfig in connectwifi,
|
||||
// and we have no idea WHAT we are connected to
|
||||
}
|
||||
|
||||
DEBUG_WM(F("AutoConnect: FAILED"));
|
||||
if(connected || connectWifi("", "") == WL_CONNECTED){
|
||||
//connected
|
||||
DEBUG_WM(F("AutoConnect: SUCCESS"));
|
||||
DEBUG_WM(F("STA IP Address:"),WiFi.localIP());
|
||||
_lastconxresult = WL_CONNECTED;
|
||||
|
||||
if((String)_hostname != ""){
|
||||
#ifdef ESP8266
|
||||
DEBUG_WM(DEBUG_DEV,"hostname: STA: ",WiFi.hostname());
|
||||
#elif defined(ESP32)
|
||||
DEBUG_WM(DEBUG_DEV,"hostname: STA: ",WiFi.getHostname());
|
||||
#endif
|
||||
}
|
||||
|
||||
return true; // connected success
|
||||
}
|
||||
|
||||
// possibly skip the config portal
|
||||
if (!_enableConfigPortal) {
|
||||
return false; // not connected and not cp
|
||||
}
|
||||
|
||||
DEBUG_WM(F("AutoConnect: FAILED"));
|
||||
}
|
||||
else DEBUG_WM(F("No Credentials are Saved, skipping connect"));
|
||||
|
||||
// not connected start configportal
|
||||
return startConfigPortal(apName, apPassword);
|
||||
bool res = startConfigPortal(apName, apPassword);
|
||||
return res;
|
||||
}
|
||||
|
||||
bool WiFiManager::setupHostname(bool restart){
|
||||
if((String)_hostname == "") {
|
||||
DEBUG_WM(DEBUG_DEV,"No Hostname to set");
|
||||
return false;
|
||||
} else DEBUG_WM(DEBUG_DEV,"setupHostname: ",_hostname);
|
||||
bool res = true;
|
||||
#ifdef ESP8266
|
||||
DEBUG_WM(DEBUG_VERBOSE,"Setting WiFi hostname");
|
||||
res = WiFi.hostname(_hostname);
|
||||
// #ifdef ESP8266MDNS_H
|
||||
#ifdef WM_MDNS
|
||||
DEBUG_WM(DEBUG_VERBOSE,"Setting MDNS hostname, tcp 80");
|
||||
if(MDNS.begin(_hostname)){
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
}
|
||||
#endif
|
||||
#elif defined(ESP32)
|
||||
// @note hostname must be set after STA_START
|
||||
delay(200); // do not remove, give time for STA_START
|
||||
res = WiFi.setHostname(_hostname);
|
||||
// #ifdef ESP32MDNS_H
|
||||
#ifdef WM_MDNS
|
||||
DEBUG_WM(DEBUG_VERBOSE,"Setting MDNS hostname, tcp 80");
|
||||
if(MDNS.begin(_hostname)){
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if(!res)DEBUG_WM(DEBUG_ERROR,F("[ERROR] hostname: set failed!"));
|
||||
|
||||
if(restart && (WiFi.status() == WL_CONNECTED)){
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("reconnecting to set new hostname"));
|
||||
// WiFi.reconnect(); // This does not reset dhcp
|
||||
WiFi_Disconnect();
|
||||
delay(200); // do not remove, need a delay for disconnect to change status()
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// CONFIG PORTAL
|
||||
@@ -404,7 +432,7 @@ bool WiFiManager::startAP(){
|
||||
DEBUG_WM(DEBUG_VERBOSE,"setting softAP Hostname:",_hostname);
|
||||
bool res = WiFi.softAPsetHostname(_hostname);
|
||||
if(!res)DEBUG_WM(DEBUG_ERROR,F("[ERROR] hostname: AP set failed!"));
|
||||
DEBUG_WM(DEBUG_DEV,F("hostname: AP"),WiFi.softAPgetHostname());
|
||||
DEBUG_WM(DEBUG_DEV,F("hostname: AP: "),WiFi.softAPgetHostname());
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -470,12 +498,14 @@ void WiFiManager::setupConfigPortal() {
|
||||
|
||||
// setup dns and web servers
|
||||
dnsServer.reset(new DNSServer());
|
||||
server.reset(new WM_WebServer(80));
|
||||
server.reset(new WM_WebServer(_httpPort));
|
||||
|
||||
if(_httpPort != 80) DEBUG_WM(DEBUG_VERBOSE,"http server started with custom port: ",_httpPort); // @todo not showing ip
|
||||
|
||||
/* Setup the DNS server redirecting all the domains to the apIP */
|
||||
dnsServer->setErrorReplyCode(DNSReplyCode::NoError);
|
||||
// DEBUG_WM("dns server started port: ",DNS_PORT);
|
||||
DEBUG_WM(DEBUG_DEV,"dns server started with ip: ",WiFi.softAPIP());
|
||||
DEBUG_WM(DEBUG_DEV,"dns server started with ip: ",WiFi.softAPIP()); // @todo not showing ip
|
||||
dnsServer->start(DNS_PORT, F("*"), WiFi.softAPIP());
|
||||
|
||||
// @todo new callback, webserver started, callback cannot override handlers, but can grab them first
|
||||
@@ -602,6 +632,11 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
boolean WiFiManager::process(){
|
||||
// process mdns, esp32 not required
|
||||
#if defined(WM_MDNS) && defined(ESP8266)
|
||||
MDNS.update();
|
||||
#endif
|
||||
|
||||
if(webPortalActive || (configPortalActive && !_configPortalIsBlocking)){
|
||||
uint8_t state = processConfigPortal();
|
||||
return state == WL_CONNECTED;
|
||||
@@ -619,7 +654,7 @@ uint8_t WiFiManager::processConfigPortal(){
|
||||
// Waiting for save...
|
||||
if(connect) {
|
||||
connect = false;
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("process connect"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("processing save"));
|
||||
if(_enableCaptivePortal) delay(_cpclosedelay); // keeps the captiveportal from closing to fast.
|
||||
|
||||
// skip wifi if no ssid
|
||||
@@ -644,10 +679,12 @@ uint8_t WiFiManager::processConfigPortal(){
|
||||
}
|
||||
|
||||
if (_shouldBreakAfterConfig) {
|
||||
|
||||
// do save callback
|
||||
// @todo this is more of an exiting callback than a save, clarify when this should actually occur
|
||||
// confirm or verify data was saved to make this more accurate callback
|
||||
if ( _savewificallback != NULL) {
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("WiFi/Param save callback"));
|
||||
_savewificallback();
|
||||
}
|
||||
shutdownConfigPortal();
|
||||
@@ -725,6 +762,7 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) {
|
||||
//@todo catch failures in set_config
|
||||
|
||||
// make sure sta is on before `begin` so it does not call enablesta->mode while persistent is ON ( which would save WM AP state to eeprom !)
|
||||
|
||||
if(_cleanConnect) WiFi_Disconnect(); // disconnect before begin, in case anything is hung, this causes a 2 seconds delay for connect
|
||||
// @todo find out what status is when this is needed, can we detect it and handle it, say in between states or idle_status
|
||||
|
||||
@@ -745,7 +783,7 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) {
|
||||
connRes = waitForConnectResult();
|
||||
}
|
||||
else {
|
||||
DEBUG_WM(F("No saved credentials, skipping wifi"));
|
||||
DEBUG_WM(F("No wifi save required, skipping"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -799,6 +837,8 @@ bool WiFiManager::wifiConnectDefault(){
|
||||
DEBUG_WM(F("Connecting to SAVED AP:"),WiFi_SSID(true));
|
||||
DEBUG_WM(DEBUG_DEV,F("Using Password:"),WiFi_psk(true));
|
||||
ret = WiFi_enableSTA(true,storeSTAmode);
|
||||
delay(500); // THIS DELAY ?
|
||||
DEBUG_WM(DEBUG_DEV,"Mode after delay: "+getModeString(WiFi.getMode()));
|
||||
if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] wifi enableSta failed");
|
||||
ret = WiFi.begin();
|
||||
if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] wifi begin failed");
|
||||
@@ -812,7 +852,7 @@ bool WiFiManager::wifiConnectDefault(){
|
||||
* @return bool success
|
||||
*/
|
||||
bool WiFiManager::setSTAConfig(){
|
||||
DEBUG_WM(F("STA static IP:"),_sta_static_ip);
|
||||
DEBUG_WM(DEBUG_DEV,F("STA static IP:"),_sta_static_ip);
|
||||
bool ret = true;
|
||||
if (_sta_static_ip) {
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Custom static IP/GW/Subnet/DNS"));
|
||||
@@ -828,7 +868,7 @@ bool WiFiManager::setSTAConfig(){
|
||||
if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] wifi config failed");
|
||||
else DEBUG_WM(F("STA IP set:"),WiFi.localIP());
|
||||
} else {
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("setSTAConfig static ip not set"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("setSTAConfig static ip not set, skipping"));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -936,7 +976,7 @@ void WiFiManager::handleRoot() {
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Root"));
|
||||
if (captivePortal()) return; // If captive portal redirect instead of displaying the page
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_options)); // @token options
|
||||
String page = getHTTPHead(FPSTR(S_options)); // @token options @todo replace options with title
|
||||
String str = FPSTR(HTTP_ROOT_MAIN);
|
||||
str.replace(FPSTR(T_v),configPortalActive ? _apName : WiFi.localIP().toString()); // use ip if ap is not active for heading
|
||||
page += str;
|
||||
@@ -991,6 +1031,7 @@ void WiFiManager::handleWifi(boolean scan) {
|
||||
}
|
||||
page += FPSTR(HTTP_FORM_END);
|
||||
page += FPSTR(HTTP_SCAN_LINK);
|
||||
if(_showBack) page += FPSTR(HTTP_BACKBTN);
|
||||
reportStatus(page);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
@@ -1017,6 +1058,7 @@ void WiFiManager::handleParam(){
|
||||
|
||||
page += getParamOut();
|
||||
page += FPSTR(HTTP_FORM_END);
|
||||
if(_showBack) page += FPSTR(HTTP_BACKBTN);
|
||||
reportStatus(page);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
@@ -1311,7 +1353,7 @@ void WiFiManager::handleWiFiStatus(){
|
||||
handleRequest();
|
||||
String page;
|
||||
// String page = "{\"result\":true,\"count\":1}";
|
||||
#ifdef JSTEST
|
||||
#ifdef WM_JSTEST
|
||||
page = FPSTR(HTTP_JS);
|
||||
#endif
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
@@ -1366,7 +1408,7 @@ void WiFiManager::handleWifiSave() {
|
||||
page += FPSTR(HTTP_PARAMSAVED);
|
||||
}
|
||||
else {
|
||||
String page = getHTTPHead(FPSTR(S_titlewifisaved)); // @token titlewifisaved
|
||||
page = getHTTPHead(FPSTR(S_titlewifisaved)); // @token titlewifisaved
|
||||
page += FPSTR(HTTP_SAVED);
|
||||
}
|
||||
page += FPSTR(HTTP_END);
|
||||
@@ -1408,8 +1450,10 @@ void WiFiManager::doParamSave(){
|
||||
if(_paramsCount > 0){
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Parameters"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,FPSTR(D_HR));
|
||||
|
||||
for (int i = 0; i < _paramsCount; i++) {
|
||||
if (_params[i] == NULL) {
|
||||
if (_params[i] == NULL || _params[i]->_length == 0) {
|
||||
DEBUG_WM(DEBUG_ERROR,"[ERROR] WiFiManagerParameter is out of scope");
|
||||
break; // @todo might not be needed anymore
|
||||
}
|
||||
//read parameter from server
|
||||
@@ -1446,6 +1490,7 @@ void WiFiManager::handleInfo() {
|
||||
uint16_t infos = 0;
|
||||
|
||||
//@todo convert to enum or refactor to strings
|
||||
//@todo wrap in build flag to remove all info code for memory saving
|
||||
#ifdef ESP8266
|
||||
infos = 27;
|
||||
String infoids[] = {
|
||||
@@ -1512,6 +1557,7 @@ void WiFiManager::handleInfo() {
|
||||
}
|
||||
page += F("</dl>");
|
||||
if(_showInfoErase) page += FPSTR(HTTP_ERASEBTN);
|
||||
if(_showBack) page += FPSTR(HTTP_BACKBTN);
|
||||
page += FPSTR(HTTP_HELP);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
@@ -1524,7 +1570,7 @@ void WiFiManager::handleInfo() {
|
||||
String WiFiManager::getInfoData(String id){
|
||||
|
||||
String p;
|
||||
// @todo add versioning
|
||||
// @todo add WM versioning
|
||||
if(id==F("esphead"))p = FPSTR(HTTP_INFO_esphead);
|
||||
else if(id==F("wifihead"))p = FPSTR(HTTP_INFO_wifihead);
|
||||
else if(id==F("uptime")){
|
||||
@@ -1806,11 +1852,16 @@ void WiFiManager::handleNotFound() {
|
||||
boolean WiFiManager::captivePortal() {
|
||||
DEBUG_WM(DEBUG_DEV,"-> " + server->hostHeader());
|
||||
|
||||
if(!_enableCaptivePortal) return false; // skip redirections
|
||||
|
||||
if (!isIp(server->hostHeader())) {
|
||||
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
|
||||
// doredirect = !isIp(server->hostHeader()) // old check
|
||||
|
||||
if (doredirect) {
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("<- Request redirected to captive portal"));
|
||||
server->sendHeader(F("Location"), (String)F("http://") + toStringIp(server->client().localIP()), true);
|
||||
server->sendHeader(F("Location"), (String)F("http://") + serverLoc, true);
|
||||
server->send ( 302, FPSTR(HTTP_HEAD_CT2), ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
|
||||
server->client().stop(); // Stop is needed because we sent no content length
|
||||
return true;
|
||||
@@ -1931,7 +1982,6 @@ bool WiFiManager::erase(bool opt){
|
||||
// if opt true, do nvs erase
|
||||
if(opt){
|
||||
DEBUG_WM("Erasing NVS");
|
||||
int err;
|
||||
esp_err_t err;
|
||||
err = nvs_flash_init();
|
||||
DEBUG_WM(DEBUG_VERBOSE,"nvs_flash_init: ",err!=ESP_OK ? (String)err : "Success");
|
||||
@@ -1963,7 +2013,7 @@ bool WiFiManager::erase(bool opt){
|
||||
* @access public
|
||||
*/
|
||||
void WiFiManager::resetSettings() {
|
||||
DEBUG_WM(F("SETTINGS ERASED"));
|
||||
DEBUG_WM(F("resetSettings"));
|
||||
WiFi_enableSTA(true,true); // must be sta to disconnect erase
|
||||
|
||||
if (_resetcallback != NULL)
|
||||
@@ -1975,7 +2025,8 @@ void WiFiManager::resetSettings() {
|
||||
WiFi.persistent(true);
|
||||
WiFi.disconnect(true);
|
||||
WiFi.persistent(false);
|
||||
#endif
|
||||
#endif
|
||||
DEBUG_WM(F("SETTINGS ERASED"));
|
||||
}
|
||||
|
||||
// SETTERS
|
||||
@@ -2006,6 +2057,13 @@ void WiFiManager::setConfigPortalTimeout(unsigned long seconds) {
|
||||
void WiFiManager::setConnectTimeout(unsigned long seconds) {
|
||||
_connectTimeout = seconds * 1000;
|
||||
}
|
||||
/**
|
||||
* toggle _cleanconnect, always disconnect before connecting
|
||||
* @param {[type]} bool enable [description]
|
||||
*/
|
||||
void WiFiManager::setCleanConnect(bool enable){
|
||||
_cleanConnect = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* [setConnectTimeout description
|
||||
@@ -2350,7 +2408,7 @@ void WiFiManager::setMenu(const char * menu[], uint8_t size){
|
||||
}
|
||||
}
|
||||
}
|
||||
DEBUG_WM(getMenuOut());
|
||||
// DEBUG_WM(getMenuOut());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2373,13 +2431,14 @@ void WiFiManager::setMenu(std::vector<const char *>& menu){
|
||||
}
|
||||
}
|
||||
}
|
||||
DEBUG_WM(getMenuOut());
|
||||
// DEBUG_WM(getMenuOut());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set params as sperate page not in wifi
|
||||
* NOT COMPATIBLE WITH setMenu! @todo scan menuids and insert param after wifi or something
|
||||
* NOT COMPATIBLE WITH setMenu!
|
||||
* @todo scan menuids and insert param after wifi or something, same for ota
|
||||
* @param bool enable
|
||||
* @since $dev
|
||||
*/
|
||||
@@ -2447,6 +2506,10 @@ void WiFiManager::setClass(String str){
|
||||
_bodyClass = str;
|
||||
}
|
||||
|
||||
void WiFiManager::setHttpPort(uint16_t port){
|
||||
_httpPort = port;
|
||||
}
|
||||
|
||||
// HELPERS
|
||||
|
||||
/**
|
||||
@@ -2495,8 +2558,8 @@ void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) {
|
||||
uint16_t max;
|
||||
uint8_t frag;
|
||||
#ifdef ESP8266
|
||||
ESP.getHeapStats(&free, &max, &frag);
|
||||
_debugPort.printf("[MEM] free: %5d | max: %5d | frag: %3d%% \n", free, max, frag);
|
||||
// ESP.getHeapStats(&free, &max, &frag);// @todo Does not exist in 2.3.0
|
||||
// _debugPort.printf("[MEM] free: %5d | max: %5d | frag: %3d%% \n", free, max, frag);
|
||||
#elif defined ESP32
|
||||
// total_free_bytes; ///< Total free bytes in the heap. Equivalent to multi_free_heap_size().
|
||||
// total_allocated_bytes; ///< Total bytes allocated to data in the heap.
|
||||
@@ -2529,13 +2592,16 @@ void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) {
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
void WiFiManager::debugSoftAPConfig(){
|
||||
wifi_country_t country;
|
||||
|
||||
#ifdef ESP8266
|
||||
softap_config config;
|
||||
wifi_softap_get_config(&config);
|
||||
wifi_get_country(&country);
|
||||
#if !defined(WM_NOCOUNTRY)
|
||||
wifi_country_t country;
|
||||
wifi_get_country(&country);
|
||||
#endif
|
||||
#elif defined(ESP32)
|
||||
wifi_country_t country;
|
||||
wifi_config_t conf_config;
|
||||
esp_wifi_get_config(WIFI_IF_AP, &conf_config); // == ESP_OK
|
||||
wifi_ap_config_t config = conf_config.ap;
|
||||
@@ -2551,7 +2617,9 @@ void WiFiManager::debugSoftAPConfig(){
|
||||
DEBUG_WM(F("authmode: "),config.authmode);
|
||||
DEBUG_WM(F("ssid_hidden: "),config.ssid_hidden);
|
||||
DEBUG_WM(F("max_connection: "),config.max_connection);
|
||||
DEBUG_WM(F("country: "),(String)country.cc);
|
||||
#if !defined(WM_NOCOUNTRY)
|
||||
DEBUG_WM(F("country: "),(String)country.cc);
|
||||
#endif
|
||||
DEBUG_WM(F("beacon_interval: "),(String)config.beacon_interval + "(ms)");
|
||||
DEBUG_WM(FPSTR(D_HR));
|
||||
}
|
||||
@@ -2569,9 +2637,16 @@ void WiFiManager::debugPlatformInfo(){
|
||||
DEBUG_WM(F("system_get_boot_version():"),system_get_boot_version());
|
||||
DEBUG_WM(F("getFreeHeap(): "),(String)ESP.getFreeHeap());
|
||||
#elif defined(ESP32)
|
||||
size_t freeHeap = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
||||
DEBUG_WM("Free heap: ", freeHeap);
|
||||
DEBUG_WM("ESP-IDF version: ", esp_get_idf_version());
|
||||
DEBUG_WM("Free heap: ", ESP.getFreeHeap());
|
||||
DEBUG_WM("ESP SDK version: ", ESP.getSdkVersion());
|
||||
// esp_chip_info_t chipInfo;
|
||||
// esp_chip_info(&chipInfo);
|
||||
// DEBUG_WM("Chip Info: Model: ",chipInfo.model);
|
||||
// DEBUG_WM("Chip Info: Cores: ",chipInfo.cores);
|
||||
// DEBUG_WM("Chip Info: Rev: ",chipInfo.revision);
|
||||
// DEBUG_WM(printf("Chip Info: Model: %d, cores: %d, revision: %d", chipInfo.model.c_str(), chipInfo.cores, chipInfo.revision));
|
||||
// DEBUG_WM("Chip Rev: ",(String)ESP.getChipRevision());
|
||||
// core version is not avail
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -2674,7 +2749,7 @@ bool WiFiManager::WiFiSetCountry(){
|
||||
else if(_wificountry == "CN") ret = esp_wifi_set_country(&WM_COUNTRY_CN) == ESP_OK;
|
||||
else DEBUG_WM(DEBUG_ERROR,"[ERROR] country code not found");
|
||||
|
||||
#elif defined(ESP8266)
|
||||
#elif defined(ESP8266) && !defined(WM_NOCOUNTRY)
|
||||
// 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);
|
||||
@@ -2715,14 +2790,14 @@ bool WiFiManager::WiFi_Disconnect() {
|
||||
#ifdef ESP8266
|
||||
if((WiFi.getMode() & WIFI_STA) != 0) {
|
||||
bool ret;
|
||||
DEBUG_WM(DEBUG_DEV,F("WIFI station disconnect"));
|
||||
DEBUG_WM(DEBUG_DEV,F("WiFi station disconnect"));
|
||||
ETS_UART_INTR_DISABLE(); // @todo probably not needed
|
||||
ret = wifi_station_disconnect();
|
||||
ETS_UART_INTR_ENABLE();
|
||||
return ret;
|
||||
}
|
||||
#elif defined(ESP32)
|
||||
DEBUG_WM(DEBUG_DEV,F("WIFI station disconnect"));
|
||||
DEBUG_WM(DEBUG_DEV,F("WiFi station disconnect"));
|
||||
return WiFi.disconnect(); // not persistent atm
|
||||
#endif
|
||||
return false;
|
||||
@@ -2730,7 +2805,7 @@ bool WiFiManager::WiFi_Disconnect() {
|
||||
|
||||
// toggle STA without persistent
|
||||
bool WiFiManager::WiFi_enableSTA(bool enable,bool persistent) {
|
||||
DEBUG_WM(DEBUG_DEV,F("WiFi station enable"));
|
||||
DEBUG_WM(DEBUG_DEV,F("WiFi_enableSTA"),(String) enable? "enable" : "disable");
|
||||
#ifdef ESP8266
|
||||
WiFiMode_t newMode;
|
||||
WiFiMode_t currentMode = WiFi.getMode();
|
||||
@@ -2858,8 +2933,9 @@ String WiFiManager::WiFi_psk(bool persistent) const {
|
||||
void WiFiManager::WiFiEvent(WiFiEvent_t event,system_event_info_t info){
|
||||
if(!_hasBegun){
|
||||
// DEBUG_WM(DEBUG_VERBOSE,"[ERROR] WiFiEvent, not ready");
|
||||
Serial.println("[ERROR] wm not ready");
|
||||
return;
|
||||
}
|
||||
}
|
||||
// DEBUG_WM(DEBUG_VERBOSE,"[EVENT]",event);
|
||||
if(event == SYSTEM_EVENT_STA_DISCONNECTED){
|
||||
DEBUG_WM(DEBUG_VERBOSE,"[EVENT] WIFI_REASON:",info.disconnected.reason);
|
||||
@@ -2887,7 +2963,7 @@ void WiFiManager::WiFi_autoReconnect(){
|
||||
// @todo move to seperate method, used for event listener now
|
||||
DEBUG_WM(DEBUG_VERBOSE,"ESP32 event handler enabled");
|
||||
using namespace std::placeholders;
|
||||
WiFi.onEvent(std::bind(&WiFiManager::WiFiEvent,this,_1,_2));
|
||||
wm_event_id = WiFi.onEvent(std::bind(&WiFiManager::WiFiEvent,this,_1,_2));
|
||||
// }
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user