From b0d7d5de6c9eea42cde168afcf82dd1356b9cd2d Mon Sep 17 00:00:00 2001 From: gw8484 <62185620+gw8484@users.noreply.github.com> Date: Sat, 14 Mar 2020 11:38:47 -0700 Subject: [PATCH 01/11] Add files via upload Added options to: * Set minimum RSSI for connection * Connect to stored AP with strongest RSSI --- src/AutoConnect.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ src/AutoConnect.h | 17 +++++++++++++++++ src/AutoConnectDefs.h | 14 ++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/src/AutoConnect.cpp b/src/AutoConnect.cpp index 669f727..07016a2 100644 --- a/src/AutoConnect.cpp +++ b/src/AutoConnect.cpp @@ -121,6 +121,14 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long } AC_DBG("WiFi.begin(%s%s%s)\n", ssid == nullptr ? "" : ssid, passphrase == nullptr ? "" : ",", passphrase == nullptr ? "" : passphrase); cs = _waitForConnect(_connectTimeout) == WL_CONNECTED; +#ifdef INC_RSSI_USE_SUP //!!! + if(cs==true) { + if(WiFi.RSSI()<_apConfig.conMinRSSI || _apConfig.conFindMaxRSSI==true) { + _disconnectWiFi(false); + cs=false; + } + } +#endif } // Reconnect with a valid credential as the autoReconnect option is enabled. @@ -625,13 +633,46 @@ bool AutoConnect::_loadAvailCredential(const char* ssid) { AC_DBG("%d network(s) found\n", (int)nn); if (nn > 0) { // Determine valid credentials by BSSID. +#ifdef INC_RSSI_USE_SUP //!!! + int maxRSSIWifiIndex=-1; + int maxRSSICredIndex=-1; +#endif for (uint8_t i = 0; i < credential.entries(); i++) { credential.load(i, &_credential); for (uint8_t n = 0; n < nn; n++) { +#ifdef INC_RSSI_USE_SUP //!!! + if (!memcmp(_credential.bssid, WiFi.BSSID(n), sizeof(station_config_t::bssid))) { + + if(WiFi.RSSI(n)>=_apConfig.conMinRSSI) { + if(_apConfig.conFindMaxRSSI!=true) { + return true; + } + + if(maxRSSIWifiIndex<0) { + maxRSSIWifiIndex=n; + maxRSSICredIndex=i; + } else { + if(WiFi.RSSI(n)>WiFi.RSSI(maxRSSIWifiIndex)) { + maxRSSIWifiIndex=n; + maxRSSICredIndex=i; + } + } + + } + + } +#else if (!memcmp(_credential.bssid, WiFi.BSSID(n), sizeof(station_config_t::bssid))) return true; +#endif } } +#ifdef INC_RSSI_USE_SUP //!!! + if(maxRSSIWifiIndex>=0) { + credential.load(maxRSSICredIndex, &_credential); + return true; + } +#endif } } else if (strlen(ssid)) diff --git a/src/AutoConnect.h b/src/AutoConnect.h index 1f34f02..60beba6 100644 --- a/src/AutoConnect.h +++ b/src/AutoConnect.h @@ -58,6 +58,10 @@ class AutoConnectConfig { * assigned from macro. Password is same as above too. */ AutoConnectConfig() : +#ifdef INC_RSSI_USE_SUP //!!! + conMinRSSI(AUTOCONNECT_CON_MIN_RSSI), + conFindMaxRSSI(AUTOCONNECT_CON_FIND_MAX_RSSI), +#endif apip(AUTOCONNECT_AP_IP), gateway(AUTOCONNECT_AP_GW), netmask(AUTOCONNECT_AP_NM), @@ -90,6 +94,10 @@ class AutoConnectConfig { * Configure by SSID for the captive portal access point and password. */ AutoConnectConfig(const char* ap, const char* password, const unsigned long portalTimeout = 0, const uint8_t channel = AUTOCONNECT_AP_CH) : +#ifdef INC_RSSI_USE_SUP //!!! + conMinRSSI(AUTOCONNECT_CON_MIN_RSSI), + conFindMaxRSSI(AUTOCONNECT_CON_FIND_MAX_RSSI), +#endif apip(AUTOCONNECT_AP_IP), gateway(AUTOCONNECT_AP_GW), netmask(AUTOCONNECT_AP_NM), @@ -122,6 +130,10 @@ class AutoConnectConfig { ~AutoConnectConfig() {} AutoConnectConfig& operator=(const AutoConnectConfig& o) { +#ifdef INC_RSSI_USE_SUP //!!! + conMinRSSI=o.conMinRSSI; + conFindMaxRSSI=o.conFindMaxRSSI; +#endif apip = o.apip; gateway = o.gateway; netmask = o.netmask; @@ -153,6 +165,11 @@ class AutoConnectConfig { return *this; } + +#ifdef INC_RSSI_USE_SUP //!!! + int conMinRSSI; /**< Minimum AP signal strength accepted for connection */ + bool conFindMaxRSSI; /**< Find stored AP with highest signal strength for connection */ +#endif IPAddress apip; /**< SoftAP IP address */ IPAddress gateway; /**< SoftAP gateway address */ IPAddress netmask; /**< SoftAP subnet mask */ diff --git a/src/AutoConnectDefs.h b/src/AutoConnectDefs.h index 3c407eb..1d10455 100644 --- a/src/AutoConnectDefs.h +++ b/src/AutoConnectDefs.h @@ -10,6 +10,19 @@ #ifndef _AUTOCONNECTDEFS_H_ #define _AUTOCONNECTDEFS_H_ +//!!! +#define INC_RSSI_USE_SUP 1 + +#ifdef INC_RSSI_USE_SUP //!!! +#ifndef AUTOCONNECT_CON_MIN_RSSI +#define AUTOCONNECT_CON_MIN_RSSI -100 // no limit +#endif + +#ifndef AUTOCONNECT_CON_FIND_MAX_RSSI +#define AUTOCONNECT_CON_FIND_MAX_RSSI false // use first available +#endif +#endif + // Uncomment the following AC_DEBUG to enable debug output. //#define AC_DEBUG @@ -25,6 +38,7 @@ #define AC_DBG_DUMB(...) #endif // !AC_DEBUG + // Indicator to specify that AutoConnectAux handles elements with JSON. // Comment out the AUTOCONNECT_USE_JSON macro to detach the ArduinoJson. #ifndef AUTOCONNECT_NOUSE_JSON From 13bd4c7ac5eda945a9d643a16fac35298382ad7d Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Wed, 18 Mar 2020 13:35:42 +0900 Subject: [PATCH 02/11] Typo fixed --- examples/Elements/Elements.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Elements/Elements.ino b/examples/Elements/Elements.ino index f8f6cfb..45e3d9f 100644 --- a/examples/Elements/Elements.ino +++ b/examples/Elements/Elements.ino @@ -58,7 +58,7 @@ static const char PAGE_ELEMENTS[] PROGMEM = R"( "value": [ "Button-1", "Button-2", - "Butotn-3" + "Button-3" ], "label": "Radio buttons", "arrange": "vertical", From 5fd6240af3b095d2d46294dcf18c16127e66c17e Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Wed, 18 Mar 2020 13:41:16 +0900 Subject: [PATCH 03/11] Supports lower RSSI limit. --- src/AutoConnect.cpp | 143 +++++++++++++++++++++++------------------- src/AutoConnect.h | 36 +++++------ src/AutoConnectDefs.h | 13 ++-- 3 files changed, 104 insertions(+), 88 deletions(-) diff --git a/src/AutoConnect.cpp b/src/AutoConnect.cpp index 07016a2..05c1dcf 100644 --- a/src/AutoConnect.cpp +++ b/src/AutoConnect.cpp @@ -2,8 +2,8 @@ * AutoConnect class implementation. * @file AutoConnect.cpp * @author hieromon@gmail.com - * @version 1.1.1 - * @date 2019-10-17 + * @version 1.1.5 + * @date 2019-03-17 * @copyright MIT license. */ @@ -95,15 +95,6 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long _ticker->start(AUTOCONNECT_FLICKER_PERIODDC, (uint8_t)AUTOCONNECT_FLICKER_WIDTHDC); } - // Advance configuration for STA mode. Restore previous configuration of STA. - station_config_t current; - if (_getConfigSTA(¤t)) { - AC_DBG("Current:%.32s\n", current.ssid); - _loadAvailCredential(reinterpret_cast(current.ssid)); - } - if (!_configSTA(_apConfig.staip, _apConfig.staGateway, _apConfig.staNetmask, _apConfig.dns1, _apConfig.dns2)) - return false; - // If the portal is requested promptly skip the first WiFi.begin and // immediately start the portal. if (_apConfig.immediateStart) { @@ -112,29 +103,47 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long AC_DBG("Start the portal immediately\n"); } else { - // Try to connect by STA immediately. - if (ssid == nullptr && passphrase == nullptr) - WiFi.begin(); - else { - _disconnectWiFi(false); - WiFi.begin(ssid, passphrase); + cs = true; + // Prepare valid configuration according to the WiFi connection right order. + const char* c_ssid = ssid; + const char* c_password = passphrase; + station_config_t current; + if (_getConfigSTA(¤t)) + AC_DBG("Current:%.32s\n", current.ssid); + if (_apConfig.wifiDisp == AC_WIFIDISP_RSSI && (ssid == nullptr && passphrase == nullptr)) { + // AC_WIFIDISP_RSSI is available when SSID and password are not provided. + // Find the strongest signal from the broadcast among the saved credentials. + if ((cs = _loadAvailCredential(nullptr, AC_WIFIDISP_RSSI, false))) { + memcpy(current.ssid, _credential.ssid, sizeof(station_config_t::ssid)); + memcpy(current.password, _credential.password, sizeof(station_config_t::password)); + c_ssid = reinterpret_cast(current.ssid); + c_password = reinterpret_cast(current.password); + AC_DBG("Adopted:%.32s\n", c_ssid); + } } - AC_DBG("WiFi.begin(%s%s%s)\n", ssid == nullptr ? "" : ssid, passphrase == nullptr ? "" : ",", passphrase == nullptr ? "" : passphrase); - cs = _waitForConnect(_connectTimeout) == WL_CONNECTED; -#ifdef INC_RSSI_USE_SUP //!!! - if(cs==true) { - if(WiFi.RSSI()<_apConfig.conMinRSSI || _apConfig.conFindMaxRSSI==true) { - _disconnectWiFi(false); - cs=false; + + if (cs) { + // Advance configuration for STA mode. Restore previous configuration of STA. + _loadAvailCredential(reinterpret_cast(current.ssid)); + if (!_configSTA(_apConfig.staip, _apConfig.staGateway, _apConfig.staNetmask, _apConfig.dns1, _apConfig.dns2)) + return false; + + // Try to connect by STA immediately. + if (c_ssid == nullptr && c_password == nullptr) + WiFi.begin(); + else { + _disconnectWiFi(false); + WiFi.begin(c_ssid, c_password); } + AC_DBG("WiFi.begin(%s%s%s)\n", c_ssid == nullptr ? "" : c_ssid, c_password == nullptr ? "" : ",", c_password == nullptr ? "" : c_password); + cs = _waitForConnect(_connectTimeout) == WL_CONNECTED; } -#endif } // Reconnect with a valid credential as the autoReconnect option is enabled. if (!cs && _apConfig.autoReconnect && (ssid == nullptr && passphrase == nullptr)) { // Load a valid credential. - if (_loadAvailCredential(nullptr)) { + if (_loadAvailCredential(nullptr, _apConfig.wifiDisp, true)) { // Try to reconnect with a stored credential. char ssid_c[sizeof(station_config_t::ssid) + sizeof('\0')]; char password_c[sizeof(station_config_t::password) + sizeof('\0')]; @@ -142,7 +151,7 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long strncat(ssid_c, reinterpret_cast(_credential.ssid), sizeof(ssid_c) - sizeof('\0')); *password_c = '\0'; strncat(password_c, reinterpret_cast(_credential.password), sizeof(password_c) - sizeof('\0')); - AC_DBG("autoReconnect loaded SSID:%s\n", ssid_c); + AC_DBG("autoReconnect loaded:%s(%s)\n", ssid_c, _apConfig.wifiDisp == AC_WIFIDISP_RECENT ? "RECENT" : "RSSI"); const char* psk = strlen(password_c) ? password_c : nullptr; _configSTA(IPAddress(_credential.config.sta.ip), IPAddress(_credential.config.sta.gateway), IPAddress(_credential.config.sta.netmask), IPAddress(_credential.config.sta.dns1), IPAddress(_credential.config.sta.dns2)); WiFi.begin(ssid_c, psk); @@ -620,9 +629,11 @@ void AutoConnect::onNotFound(WebServerClass::THandlerFunction fn) { /** * Load stored credentials that match nearby WLANs. * @param ssid SSID which should be loaded. If nullptr is assigned, search SSID with WiFi.scan. + * @param wifiDisp WiFi connection disposition. + * @param excludeCurrent Skip loading the current SSID. * @return true A matched credential of BSSID was loaded. */ -bool AutoConnect::_loadAvailCredential(const char* ssid) { +bool AutoConnect::_loadAvailCredential(const char* ssid, const AC_WIFIDISP_t wifiDisp, const bool excludeCurrent) { AutoConnectCredential credential(_apConfig.boundaryOffset); if (credential.entries() > 0) { @@ -632,49 +643,55 @@ bool AutoConnect::_loadAvailCredential(const char* ssid) { int8_t nn = WiFi.scanNetworks(false, true); AC_DBG("%d network(s) found\n", (int)nn); if (nn > 0) { - // Determine valid credentials by BSSID. -#ifdef INC_RSSI_USE_SUP //!!! - int maxRSSIWifiIndex=-1; - int maxRSSICredIndex=-1; -#endif + station_config_t validConfig; // Temporary to find the strongest RSSI. + int32_t minRSSI = -120; // Min value to find the strongest RSSI. + + // Seek SSID + const char* currentSSID = WiFi.SSID().c_str(); + const bool skipCurrent = excludeCurrent & (strlen(currentSSID) > 0); for (uint8_t i = 0; i < credential.entries(); i++) { credential.load(i, &_credential); + // Seek valid configuration according to the WiFi connection disposition. + // Verify that an available SSIDs meet AC_WIFIDISP_t requirements. for (uint8_t n = 0; n < nn; n++) { -#ifdef INC_RSSI_USE_SUP //!!! + if (skipCurrent && !strcmp(currentSSID, WiFi.SSID(n).c_str())) + continue; if (!memcmp(_credential.bssid, WiFi.BSSID(n), sizeof(station_config_t::bssid))) { - - if(WiFi.RSSI(n)>=_apConfig.conMinRSSI) { - if(_apConfig.conFindMaxRSSI!=true) { - return true; - } - - if(maxRSSIWifiIndex<0) { - maxRSSIWifiIndex=n; - maxRSSICredIndex=i; - } else { - if(WiFi.RSSI(n)>WiFi.RSSI(maxRSSIWifiIndex)) { - maxRSSIWifiIndex=n; - maxRSSICredIndex=i; - } - } - - } - - } -#else - if (!memcmp(_credential.bssid, WiFi.BSSID(n), sizeof(station_config_t::bssid))) - return true; -#endif + // Excepts SSID that has weak RSSI under the lower limit. + if (WiFi.RSSI(n) < _apConfig.minRSSI) { + AC_DBG("%s:%" PRId32 "dBm, rejected\n", reinterpret_cast(_credential.ssid), WiFi.RSSI(n)); + continue; + } + // Determine valid credential + switch (wifiDisp) { + case AC_WIFIDISP_RECENT: + // By BSSID, exit to keep the credential just loaded. + return true; + + case AC_WIFIDISP_RSSI: + // Verify that most strong radio signal. + // Continue seeking to find the strongest WIFI signal SSID. + if (WiFi.RSSI(n) > minRSSI) { + minRSSI = WiFi.RSSI(n); + memcpy(&validConfig, &_credential, sizeof(station_config_t)); + } + break; + } + break; + } } } -#ifdef INC_RSSI_USE_SUP //!!! - if(maxRSSIWifiIndex>=0) { - credential.load(maxRSSICredIndex, &_credential); - return true; - } -#endif + // Increasing the minSSI will indicate the successfully sought for AC_WIFIDISP_RSSI. + // Restore the credential that has maximum RSSI. + if (minRSSI > -120) { + memcpy(&_credential, &validConfig, sizeof(station_config_t)); + return true; + } } } + + // The SSID to load was specified. + // Set the IP configuration globally from the saved credential. else if (strlen(ssid)) if (credential.load(ssid, &_credential) >= 0) { if (_credential.dhcp == STA_STATIC) { diff --git a/src/AutoConnect.h b/src/AutoConnect.h index 60beba6..bfed533 100644 --- a/src/AutoConnect.h +++ b/src/AutoConnect.h @@ -2,8 +2,8 @@ * Declaration of AutoConnect class and accompanying AutoConnectConfig class. * @file AutoConnect.h * @author hieromon@gmail.com - * @version 1.1.1 - * @date 2019-10-17 + * @version 1.1.5 + * @date 2020-03-16 * @copyright MIT license. */ @@ -50,6 +50,12 @@ typedef enum AC_ONBOOTURI { AC_ONBOOTURI_HOME } AC_ONBOOTURI_t; +/** WiFi connection disposition, it specifies the order of WiFI connecting with saved credentials. */ +typedef enum AC_WIFIDISP { + AC_WIFIDISP_RECENT, + AC_WIFIDISP_RSSI +} AC_WIFIDISP_t; + class AutoConnectConfig { public: /** @@ -58,10 +64,6 @@ class AutoConnectConfig { * assigned from macro. Password is same as above too. */ AutoConnectConfig() : -#ifdef INC_RSSI_USE_SUP //!!! - conMinRSSI(AUTOCONNECT_CON_MIN_RSSI), - conFindMaxRSSI(AUTOCONNECT_CON_FIND_MAX_RSSI), -#endif apip(AUTOCONNECT_AP_IP), gateway(AUTOCONNECT_AP_GW), netmask(AUTOCONNECT_AP_NM), @@ -69,8 +71,10 @@ class AutoConnectConfig { psk(String(AUTOCONNECT_PSK)), channel(AUTOCONNECT_AP_CH), hidden(0), + minRSSI(AUTOCONNECT_MIN_RSSI), autoSave(AC_SAVECREDENTIAL_AUTO), bootUri(AC_ONBOOTURI_ROOT), + wifiDisp(AC_WIFIDISP_RECENT), boundaryOffset(AC_IDENTIFIER_OFFSET), uptime(AUTOCONNECT_STARTUPTIME), autoRise(true), @@ -94,10 +98,6 @@ class AutoConnectConfig { * Configure by SSID for the captive portal access point and password. */ AutoConnectConfig(const char* ap, const char* password, const unsigned long portalTimeout = 0, const uint8_t channel = AUTOCONNECT_AP_CH) : -#ifdef INC_RSSI_USE_SUP //!!! - conMinRSSI(AUTOCONNECT_CON_MIN_RSSI), - conFindMaxRSSI(AUTOCONNECT_CON_FIND_MAX_RSSI), -#endif apip(AUTOCONNECT_AP_IP), gateway(AUTOCONNECT_AP_GW), netmask(AUTOCONNECT_AP_NM), @@ -105,8 +105,10 @@ class AutoConnectConfig { psk(String(password)), channel(channel), hidden(0), + minRSSI(AUTOCONNECT_MIN_RSSI), autoSave(AC_SAVECREDENTIAL_AUTO), bootUri(AC_ONBOOTURI_ROOT), + wifiDisp(AC_WIFIDISP_RECENT), boundaryOffset(AC_IDENTIFIER_OFFSET), uptime(AUTOCONNECT_STARTUPTIME), autoRise(true), @@ -130,10 +132,6 @@ class AutoConnectConfig { ~AutoConnectConfig() {} AutoConnectConfig& operator=(const AutoConnectConfig& o) { -#ifdef INC_RSSI_USE_SUP //!!! - conMinRSSI=o.conMinRSSI; - conFindMaxRSSI=o.conFindMaxRSSI; -#endif apip = o.apip; gateway = o.gateway; netmask = o.netmask; @@ -141,8 +139,10 @@ class AutoConnectConfig { psk = o.psk; channel = o.channel; hidden = o.hidden; + minRSSI=o.minRSSI; autoSave = o.autoSave; bootUri = o.bootUri; + wifiDisp = o.wifiDisp; boundaryOffset = o.boundaryOffset; uptime = o.uptime; autoRise = o.autoRise; @@ -166,10 +166,6 @@ class AutoConnectConfig { } -#ifdef INC_RSSI_USE_SUP //!!! - int conMinRSSI; /**< Minimum AP signal strength accepted for connection */ - bool conFindMaxRSSI; /**< Find stored AP with highest signal strength for connection */ -#endif IPAddress apip; /**< SoftAP IP address */ IPAddress gateway; /**< SoftAP gateway address */ IPAddress netmask; /**< SoftAP subnet mask */ @@ -177,8 +173,10 @@ class AutoConnectConfig { String psk; /**< SoftAP password */ uint8_t channel; /**< SoftAP used wifi channel */ uint8_t hidden; /**< SoftAP SSID hidden */ + int16_t minRSSI; /**< Lowest WiFi signal strength (RSSI) that can be connected. */ AC_SAVECREDENTIAL_t autoSave; /**< Auto save credential */ AC_ONBOOTURI_t bootUri; /**< An uri invoking after reset */ + AC_WIFIDISP_t wifiDisp; /**< WiFI connection disposition */ uint16_t boundaryOffset; /**< The save storage offset of EEPROM */ int uptime; /**< Length of start up time */ bool autoRise; /**< Automatic starting the captive portal */ @@ -245,7 +243,7 @@ class AutoConnect { void _startWebServer(void); void _startDNSServer(void); void _handleNotFound(void); - bool _loadAvailCredential(const char* ssid); + bool _loadAvailCredential(const char* ssid, const AC_WIFIDISP_t wifiDisp = AC_WIFIDISP_RECENT, const bool excludeCurrent = false); void _stopPortal(void); bool _classifyHandle(HTTPMethod mothod, String uri); void _handleUpload(const String& requestUri, const HTTPUpload& upload); diff --git a/src/AutoConnectDefs.h b/src/AutoConnectDefs.h index 1d10455..3cde0fd 100644 --- a/src/AutoConnectDefs.h +++ b/src/AutoConnectDefs.h @@ -2,8 +2,8 @@ * Predefined AutoConnect configuration parameters. * @file AutoConnectDefs.h * @author hieromon@gmail.com - * @version 1.1.0 - * @date 2019-10-11 + * @version 1.1.5 + * @date 2020-03-16 * @copyright MIT license. */ @@ -14,10 +14,6 @@ #define INC_RSSI_USE_SUP 1 #ifdef INC_RSSI_USE_SUP //!!! -#ifndef AUTOCONNECT_CON_MIN_RSSI -#define AUTOCONNECT_CON_MIN_RSSI -100 // no limit -#endif - #ifndef AUTOCONNECT_CON_FIND_MAX_RSSI #define AUTOCONNECT_CON_FIND_MAX_RSSI false // use first available #endif @@ -188,6 +184,11 @@ #endif #endif +// Lowest WiFi signal strength (RSSI) that can be connected. +#ifndef AUTOCONNECT_MIN_RSSI +#define AUTOCONNECT_MIN_RSSI -120 // No limit +#endif // !AUTOCONNECT_MIN_RSSI + // ArduinoJson buffer size #ifndef AUTOCONNECT_JSONBUFFER_SIZE #define AUTOCONNECT_JSONBUFFER_SIZE 256 From f0d6d3cb78bfc539a286378447e57e82d036fad1 Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Thu, 19 Mar 2020 13:29:28 +0900 Subject: [PATCH 04/11] Bump version --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index 90b150c..281a516 100644 --- a/library.json +++ b/library.json @@ -25,6 +25,6 @@ "espressif8266", "espressif32" ], - "version": "1.1.4", + "version": "1.1.5", "license": "MIT" } diff --git a/library.properties b/library.properties index 2ac38c4..0403fc1 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=AutoConnect -version=1.1.4 +version=1.1.5 author=Hieromon Ikasamo maintainer=Hieromon Ikasamo sentence=ESP8266/ESP32 WLAN configuration at runtime with web interface. From b685f30af2ac7c3feacf7d71ef70aa6278b8b5c3 Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Thu, 19 Mar 2020 13:32:27 +0900 Subject: [PATCH 05/11] Updated a changelog for v1.1.5 --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 4c006bf..133b573 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,9 @@ Full documentation is available on https://Hieromon.github.io/AutoConnect, some ## Change log +### [1.1.5] Mar. 19, 2020 +- Supports an attempt order when available APs would be found multiple, and RSSI lower bound on AP signal strength. This option can specify the order of connection attempting according to the WiFi signal strength indicated with RSSI. (PR #187) + ### [1.1.4] Feb. 14, 2020 - Supports for overriding text of the menu items with user-defined labels. - Fixed the compiler warning with experimental WiFi mode of ESP8266. From 1152ced7eac99ce9313cd165bb6db412dd9ba644 Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Fri, 20 Mar 2020 16:20:31 +0900 Subject: [PATCH 06/11] Change AC_WIFIDISP_t --- src/AutoConnect.cpp | 26 +++++++++++++------------- src/AutoConnect.h | 20 ++++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/AutoConnect.cpp b/src/AutoConnect.cpp index 05c1dcf..fea5fd0 100644 --- a/src/AutoConnect.cpp +++ b/src/AutoConnect.cpp @@ -110,10 +110,10 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long station_config_t current; if (_getConfigSTA(¤t)) AC_DBG("Current:%.32s\n", current.ssid); - if (_apConfig.wifiDisp == AC_WIFIDISP_RSSI && (ssid == nullptr && passphrase == nullptr)) { - // AC_WIFIDISP_RSSI is available when SSID and password are not provided. + if (_apConfig.principle == AC_PRINCIPLE_RSSI && (ssid == nullptr && passphrase == nullptr)) { + // AC_PRINCIPLE_RSSI is available when SSID and password are not provided. // Find the strongest signal from the broadcast among the saved credentials. - if ((cs = _loadAvailCredential(nullptr, AC_WIFIDISP_RSSI, false))) { + if ((cs = _loadAvailCredential(nullptr, AC_PRINCIPLE_RSSI, false))) { memcpy(current.ssid, _credential.ssid, sizeof(station_config_t::ssid)); memcpy(current.password, _credential.password, sizeof(station_config_t::password)); c_ssid = reinterpret_cast(current.ssid); @@ -143,7 +143,7 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long // Reconnect with a valid credential as the autoReconnect option is enabled. if (!cs && _apConfig.autoReconnect && (ssid == nullptr && passphrase == nullptr)) { // Load a valid credential. - if (_loadAvailCredential(nullptr, _apConfig.wifiDisp, true)) { + if (_loadAvailCredential(nullptr, _apConfig.principle, true)) { // Try to reconnect with a stored credential. char ssid_c[sizeof(station_config_t::ssid) + sizeof('\0')]; char password_c[sizeof(station_config_t::password) + sizeof('\0')]; @@ -151,7 +151,7 @@ bool AutoConnect::begin(const char* ssid, const char* passphrase, unsigned long strncat(ssid_c, reinterpret_cast(_credential.ssid), sizeof(ssid_c) - sizeof('\0')); *password_c = '\0'; strncat(password_c, reinterpret_cast(_credential.password), sizeof(password_c) - sizeof('\0')); - AC_DBG("autoReconnect loaded:%s(%s)\n", ssid_c, _apConfig.wifiDisp == AC_WIFIDISP_RECENT ? "RECENT" : "RSSI"); + AC_DBG("autoReconnect loaded:%s(%s)\n", ssid_c, _apConfig.principle == AC_PRINCIPLE_RECENT ? "RECENT" : "RSSI"); const char* psk = strlen(password_c) ? password_c : nullptr; _configSTA(IPAddress(_credential.config.sta.ip), IPAddress(_credential.config.sta.gateway), IPAddress(_credential.config.sta.netmask), IPAddress(_credential.config.sta.dns1), IPAddress(_credential.config.sta.dns2)); WiFi.begin(ssid_c, psk); @@ -629,11 +629,11 @@ void AutoConnect::onNotFound(WebServerClass::THandlerFunction fn) { /** * Load stored credentials that match nearby WLANs. * @param ssid SSID which should be loaded. If nullptr is assigned, search SSID with WiFi.scan. - * @param wifiDisp WiFi connection disposition. + * @param principle WiFi connection principle. * @param excludeCurrent Skip loading the current SSID. * @return true A matched credential of BSSID was loaded. */ -bool AutoConnect::_loadAvailCredential(const char* ssid, const AC_WIFIDISP_t wifiDisp, const bool excludeCurrent) { +bool AutoConnect::_loadAvailCredential(const char* ssid, const AC_PRINCIPLE_t principle, const bool excludeCurrent) { AutoConnectCredential credential(_apConfig.boundaryOffset); if (credential.entries() > 0) { @@ -651,8 +651,8 @@ bool AutoConnect::_loadAvailCredential(const char* ssid, const AC_WIFIDISP_t wif const bool skipCurrent = excludeCurrent & (strlen(currentSSID) > 0); for (uint8_t i = 0; i < credential.entries(); i++) { credential.load(i, &_credential); - // Seek valid configuration according to the WiFi connection disposition. - // Verify that an available SSIDs meet AC_WIFIDISP_t requirements. + // Seek valid configuration according to the WiFi connection principle. + // Verify that an available SSIDs meet AC_PRINCIPLE_t requirements. for (uint8_t n = 0; n < nn; n++) { if (skipCurrent && !strcmp(currentSSID, WiFi.SSID(n).c_str())) continue; @@ -663,12 +663,12 @@ bool AutoConnect::_loadAvailCredential(const char* ssid, const AC_WIFIDISP_t wif continue; } // Determine valid credential - switch (wifiDisp) { - case AC_WIFIDISP_RECENT: + switch (principle) { + case AC_PRINCIPLE_RECENT: // By BSSID, exit to keep the credential just loaded. return true; - case AC_WIFIDISP_RSSI: + case AC_PRINCIPLE_RSSI: // Verify that most strong radio signal. // Continue seeking to find the strongest WIFI signal SSID. if (WiFi.RSSI(n) > minRSSI) { @@ -681,7 +681,7 @@ bool AutoConnect::_loadAvailCredential(const char* ssid, const AC_WIFIDISP_t wif } } } - // Increasing the minSSI will indicate the successfully sought for AC_WIFIDISP_RSSI. + // Increasing the minSSI will indicate the successfully sought for AC_PRINCIPLE_RSSI. // Restore the credential that has maximum RSSI. if (minRSSI > -120) { memcpy(&_credential, &validConfig, sizeof(station_config_t)); diff --git a/src/AutoConnect.h b/src/AutoConnect.h index bfed533..78ed388 100644 --- a/src/AutoConnect.h +++ b/src/AutoConnect.h @@ -50,11 +50,11 @@ typedef enum AC_ONBOOTURI { AC_ONBOOTURI_HOME } AC_ONBOOTURI_t; -/** WiFi connection disposition, it specifies the order of WiFI connecting with saved credentials. */ -typedef enum AC_WIFIDISP { - AC_WIFIDISP_RECENT, - AC_WIFIDISP_RSSI -} AC_WIFIDISP_t; +/** WiFi connection principle, it specifies the order of WiFi connecting with saved credentials. */ +typedef enum AC_PRINCIPLE { + AC_PRINCIPLE_RECENT, + AC_PRINCIPLE_RSSI +} AC_PRINCIPLE_t; class AutoConnectConfig { public: @@ -74,7 +74,7 @@ class AutoConnectConfig { minRSSI(AUTOCONNECT_MIN_RSSI), autoSave(AC_SAVECREDENTIAL_AUTO), bootUri(AC_ONBOOTURI_ROOT), - wifiDisp(AC_WIFIDISP_RECENT), + principle(AC_PRINCIPLE_RECENT), boundaryOffset(AC_IDENTIFIER_OFFSET), uptime(AUTOCONNECT_STARTUPTIME), autoRise(true), @@ -108,7 +108,7 @@ class AutoConnectConfig { minRSSI(AUTOCONNECT_MIN_RSSI), autoSave(AC_SAVECREDENTIAL_AUTO), bootUri(AC_ONBOOTURI_ROOT), - wifiDisp(AC_WIFIDISP_RECENT), + principle(AC_PRINCIPLE_RECENT), boundaryOffset(AC_IDENTIFIER_OFFSET), uptime(AUTOCONNECT_STARTUPTIME), autoRise(true), @@ -142,7 +142,7 @@ class AutoConnectConfig { minRSSI=o.minRSSI; autoSave = o.autoSave; bootUri = o.bootUri; - wifiDisp = o.wifiDisp; + principle = o.principle; boundaryOffset = o.boundaryOffset; uptime = o.uptime; autoRise = o.autoRise; @@ -176,7 +176,7 @@ class AutoConnectConfig { int16_t minRSSI; /**< Lowest WiFi signal strength (RSSI) that can be connected. */ AC_SAVECREDENTIAL_t autoSave; /**< Auto save credential */ AC_ONBOOTURI_t bootUri; /**< An uri invoking after reset */ - AC_WIFIDISP_t wifiDisp; /**< WiFI connection disposition */ + AC_PRINCIPLE_t principle; /**< WiFi connection principle */ uint16_t boundaryOffset; /**< The save storage offset of EEPROM */ int uptime; /**< Length of start up time */ bool autoRise; /**< Automatic starting the captive portal */ @@ -243,7 +243,7 @@ class AutoConnect { void _startWebServer(void); void _startDNSServer(void); void _handleNotFound(void); - bool _loadAvailCredential(const char* ssid, const AC_WIFIDISP_t wifiDisp = AC_WIFIDISP_RECENT, const bool excludeCurrent = false); + bool _loadAvailCredential(const char* ssid, const AC_PRINCIPLE_t principle = AC_PRINCIPLE_RECENT, const bool excludeCurrent = false); void _stopPortal(void); bool _classifyHandle(HTTPMethod mothod, String uri); void _handleUpload(const String& requestUri, const HTTPUpload& upload); From a42c375c36d953b1c24e2b22b834bc9e2fc5a606 Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Fri, 20 Mar 2020 16:28:01 +0900 Subject: [PATCH 07/11] Supports lower RSSI limit. --- src/AutoConnectDefs.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/AutoConnectDefs.h b/src/AutoConnectDefs.h index 3cde0fd..884ecf7 100644 --- a/src/AutoConnectDefs.h +++ b/src/AutoConnectDefs.h @@ -10,15 +10,6 @@ #ifndef _AUTOCONNECTDEFS_H_ #define _AUTOCONNECTDEFS_H_ -//!!! -#define INC_RSSI_USE_SUP 1 - -#ifdef INC_RSSI_USE_SUP //!!! -#ifndef AUTOCONNECT_CON_FIND_MAX_RSSI -#define AUTOCONNECT_CON_FIND_MAX_RSSI false // use first available -#endif -#endif - // Uncomment the following AC_DEBUG to enable debug output. //#define AC_DEBUG @@ -34,7 +25,6 @@ #define AC_DBG_DUMB(...) #endif // !AC_DEBUG - // Indicator to specify that AutoConnectAux handles elements with JSON. // Comment out the AUTOCONNECT_USE_JSON macro to detach the ArduinoJson. #ifndef AUTOCONNECT_NOUSE_JSON From 0f81aab9db5251e65d06dd86479f7cdedaba598d Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Fri, 20 Mar 2020 18:11:43 +0900 Subject: [PATCH 08/11] Supports lower RSSI limit. --- mkdocs/advancedusage.md | 325 +++++++++++++++++++++++++++++----------- mkdocs/apiconfig.md | 19 +++ mkdocs/changelog.md | 3 + mkdocs/faq.md | 2 +- 4 files changed, 258 insertions(+), 91 deletions(-) diff --git a/mkdocs/advancedusage.md b/mkdocs/advancedusage.md index efd9561..eaf802a 100644 --- a/mkdocs/advancedusage.md +++ b/mkdocs/advancedusage.md @@ -33,7 +33,7 @@ An autoReconnect option is available to *AutoConnect::begin* without SSID and pa !!! caution "An autoReconnect will work if SSID detection succeeded" An autoReconnect will not effect if the SSID which stored credential to be connected is a hidden access point. -### Auto save Credential +### Autosave Credential By default, AutoConnect saves the credentials of the established connection to the flash. You can disable it with the [**autoSave**](apiconfig.md#autosave) parameter specified by [AutoConnectConfig](apiconfig.md). See the [Saved credentials access](credit.md) chapter for details on accessing stored credentials. @@ -201,39 +201,31 @@ To implement embedding your legacy web pages to the AutoConnect menu, you can us For details, see section [Constructing the menu](menuize.md) of Examples page. -### Change menu title - -Although the default menu title is **AutoConnect**, you can change the title by setting [*AutoConnectConfig::title*](apiconfig.md#title). To set the menu title properly, you must set before calling [*AutoConnect::begin*](api.md#begin). - -```cpp hl_lines="6 7" -AutoConnect Portal; -AutoConnectConfig Config; - -void setup() { - // Set menu title - Config.title = "FSBrowser"; - Portal.config(Config); - Portal.begin(); -} -``` +### Change the menu labels -Executing the above sketch will rewrite the menu title for the **FSBrowser** as the below. +You can change the label text for each menu item but cannot change them at run time. There are two ways to change the label text, both of which require coding the label literal. -
- +1. Overwrite the label literal of library source code directly. + + You can change the label of the AutoConnect menu item by rewriting the default label literal in [AutoConnectLabels.h](https://github.com/Hieromon/AutoConnect/blob/master/src/AutoConnectLabels.h) macros. However, changing menu items literal influences all the sketch's build scenes. + + ```cpp + #define AUTOCONNECT_MENULABEL_CONFIGNEW "Configure new AP" + #define AUTOCONNECT_MENULABEL_OPENSSIDS "Open SSIDs" + #define AUTOCONNECT_MENULABEL_DISCONNECT "Disconnect" + #define AUTOCONNECT_MENULABEL_RESET "Reset..." + #define AUTOCONNECT_MENULABEL_HOME "HOME" + #define AUTOCONNECT_BUTTONLABEL_RESET "RESET" + ``` -### Change the menu labels + !!! note "**buld_flags** with PlatformIO will no effect" + The mistake that many people make is to use PlatformIO's build_flags to try to redefine any literal at compile time.
+ The AutoConnect library statically contains the label literals which are embedded as binary data when compiling the library code. The label literals will not change without compiling the library source.
+ And PlatformIO is a build system. Library sources will not be compiled unless AutoConnectLabels.h is updated. -You can change the label of the AutoConnect menu item by rewriting the default label letter in [AutoConnectLabels.h](https://github.com/Hieromon/AutoConnect/blob/master/src/AutoConnectLabels.h) macros. However, changing menu items letter influences all the sketch's build scenes. +2. Change the label literals for each Arduino project -```cpp -#define AUTOCONNECT_MENULABEL_CONFIGNEW "Configure new AP" -#define AUTOCONNECT_MENULABEL_OPENSSIDS "Open SSIDs" -#define AUTOCONNECT_MENULABEL_DISCONNECT "Disconnect" -#define AUTOCONNECT_MENULABEL_RESET "Reset..." -#define AUTOCONNECT_MENULABEL_HOME "HOME" -#define AUTOCONNECT_BUTTONLABEL_RESET "RESET" -``` + Another way to change the label literal is to provide a header file that defines the label literals, as mentioned in [Appendix](changelabel.md#change-the-items-label-text). You can also use this method to display label text and fixed text in the local language on the AutoConnect page. See [**Appendix:Change the item's label text**](changelabel.md#change-the-items-label-text) for details. ### Combination with mDNS @@ -258,6 +250,56 @@ void loop() { } ``` +### Connects depending on the WiFi signal strength + +When the ESP module found the multiple available access points (ie. AutoConnect has connected in the past), the default behavior AutoConnect will attempt to connect to the least recent one. However, If the ESP module can operate properly with any access point, it is advantageous to establish a connection with the best one of the reception sensitivity. + +The [*AutoConnectConfig::principle*](apiconfig.md#principle) parameter has the connection disposition, and specifying **AC_PRINCIPLE_RSSI** will attempt to connect to one of the highest RSSI value among multiple available access points. Also You can expect stable WiFi connection by specifying the lower limit of signal strength using [*AutoConnectConfig::minRSSI*](apiconfig.md#minrssi). +Combining these two parameters allows you to filter the destination AP when multiple available access points are found. + +[*AutoConnectConfig::principle*](apiconfig.md#principle) affects the behavior of both 1st-WiFi.begin and [**autoReconnect**](advancedusage.md#automatic-reconnect). If you specify **AC_PRINCIPLE_RECENT** for the [**principle**](apiconfig.md#principle), it will try according to the conventional connection rules, but if you specify **AC_PRINCIPLE_RSSI**, it will try to connect to the access point that is sending the strongest WiFi signal at that time instead of the last accessed AP. Also, the static IPs will be restored from a saved credential instead of AutoConnectConfig. (The values specified by AutoConnectConfig is ignored) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SSID &
Password
AutoConnectConfig
::principle
Which credentials would be selectedStatic IPs
AutoConnect
::begin
NULL specifiedAC_PRINCIPLE_RECENTNothing, depends on SDK savesUse the specified value of AutoConnectConfig
AC_PRINCIPLE_RSSIAuto-selected credentials with max RSSIRestoring static IPs suitable for the SSID from saved credentials
Specified with the sketchNot efectiveBy AutoConnect::begin parametersUse the specified value of AutoConnectConfig
AutoReconnectLoad from
saved credential
AC_PRINCIPLE_RECENTRecently saved SSID would be chosenRestoring static IPs suitable for the SSID from saved credentials
AC_PRINCIPLE_RSSIAuto-selected credentials with max RSSI
+ ### Debug print You can output AutoConnect monitor messages to the **Serial**. A monitor message activation switch is in an include header file [AutoConnectDefs.h](https://github.com/Hieromon/AutoConnect/blob/master/src/AutoConnectDefs.h) of library source. Define [**AC_DEBUG**](https://github.com/Hieromon/AutoConnect/blob/master/src/AutoConnectDefs.h#L14) macro to output the monitor messages.[^1] @@ -300,54 +342,112 @@ portal.begin(); !!! hint "Obtaining chip ID for ESP32" `acConfig.apid = "ESP-" + String((uint32_t)(ESP.getEfuseMac() >> 32), HEX);` -### Move the saving area of EEPROM for the credentials +### On-demand start the captive portal -By default, the credentials saving area is occupied from the beginning of EEPROM area. [ESP8266 Arduino core document](http://arduino-esp8266.readthedocs.io/en/latest/filesystem.html?highlight=eeprom#flash-layout) says that: +The [default behavior of AutoConnect::begin](lsbegin.md) gives priority to connect to the least recently established access point. In general, We expect this behavior in most situations, but will intentionally launch the captive portal on some occasion. +Here section describes how to launch on demand the captive portal, and suggests two templates that you can use to implement it. -> The following diagram illustrates flash layout used in Arduino environment: +1. Offline for usual operation, connect to WiFi with an external switch -> ``` -> |--------------|-------|---------------|--|--|--|--|--| -> ^ ^ ^ ^ ^ -> Sketch OTA update File system EEPROM WiFi config (SDK) -> ``` + You can use this template if the ESP module does not connect to WiFi at an ordinal situation and need to establish by a manual trigger. In this case, it is desirable that AutoConnect not start until an external switch fires. This behavior is similar to the [WiFiManager's startConfigPortal](https://github.com/tzapu/WiFiManager#on-demand-configuration-portal) function. + [*AutoConnectConfig::immediateStart*](apiconfig.md#immediatestart) is an option to launch the portal by the SoftAP immediately without attempting 1st-WiFi.begin. Also, by setting the [*AutoConnectConfig::autoRise*](apiconfig.md#autorise) option to false, it is possible to suppress unintended automatic pop-ups of the portal screen when connecting to an ESP module SSID. + To implement this, execute AutoConnect::config within the **setup()** function as usual, and handle AutoConnect::begin inside the **loop()** function. -and + ```cpp hl_lines="9" + #define TRIGGER_PIN 5 // Trigger switch should be LOW active. + #define HOLD_TIMER 3000 -> EEPROM library uses one sector of flash located [just after the SPIFFS](http://arduino-esp8266.readthedocs.io/en/latest/libraries.html?highlight=SPIFFS#eeprom). + AutoConnect Portal; + AutoConnectConfig Config; -Also, in ESP32 arduino core 1.0.2 earlier, the placement of the EEPROM area of ESP32 is described in the [partition table](https://github.com/espressif/arduino-esp32/blob/master/tools/partitions/default.csv). So in the default state, the credential storage area used by AutoConnect conflicts with data owned by the user sketch. It will be destroyed together saved data in EEPROM by user sketch and AutoConnect each other. But you can move the storage area to avoid this. + void setup() { + pinMode(5, INPUT_PULLUP); + Config.immediateStart = true; + // Config.autoRise = false; // If you don't need to automatically pop-up the portal when connected to the ESP module's SSID. + Portal.config(Config); + } -The [**boundaryOffset**](apiconfig.md#boundaryoffset) in [AutoConnectConfig](apiconfig.md) specifies the start offset of the credentials storage area. The default value is 0. + void loop() { + if (digitalRead(TRIGGER_PIN) == LOW) { + unsigned long tm = millis(); + while (digitalRead(TRIGGER_PIN) == LOW) { + yield(); + } + // Hold the switch while HOLD_TIMER time to start connect. + if (millis() - tm > HOLD_TIMER) + Portal.begin(); + } -!!! info "The boundaryOffset ignored with AutoConnect v1.0.0 later on ESP32 arduino core 1.0.3 later" - For ESP32 arduino core 1.0.3 and later, AutoConnect will store credentials to Preferences in the nvs. Since it is defined as the namespace dedicated to AutoConnect and separated from the area used for user sketches. Therefore, the [boundaryOffset](apiconfig.md#boundaryoffset) is ignored with the combination of AutoConnect v1.0.0 or later and the arduino-esp32 1.0.3 or later. + if (WiFi.status() == WL_CONNECTED) { + // Here, what to do if the module has connected to a WiFi access point + } -### On-demand start the captive portal + // Main process of your sketch -If you do not usually connect to WiFi and need to establish a WiFi connection if necessary, you can combine the [**autoRise**](apiconfig.md#autorise) option with the [**immediateStart**](apiconfig.md#immediatestart) option to achieve on-demand connection. This behavior is similar to the [WiFiManager's startConfigPortal](https://github.com/tzapu/WiFiManager#on-demand-configuration-portal) function. In order to do this, you usually configure only with AutoConnectConfig in *setup()* and [*AutoConnect::begin*](api.md#begin) handles in *loop()*. + Portal.handleClient(); // If WiFi is not connected, handleClient will do nothing. + } + ``` -```cpp hl_lines="5 6" -AutoConnect Portal; -AutoConnectConfig Config; + !!! note "It will not be automatic reconnect" + The above example does not connect to WiFi until TRIGGER\_PIN goes LOW. When TRIGGER\_PIN goes LOW, the captive portal starts and you can connect to WiFi. Even if you reset the module, it will not automatically reconnect. -void setup() { - Config.autoRise = false; - Config.immediateStart = true; - Portal.config(Config); -} +2. Register new access points on demand -void loop() { - if (digitalRead(TRIGGER_PIN) == LOW) { - while (digitalRead(TRIGGER_PIN) == LOW) - yield(); - Portal.begin(); - } - Portal.handleClient(); -} -``` -The above example does not connect to WiFi until TRIGGER\_PIN goes LOW. When TRIGGER\_PIN goes LOW, the captive portal starts and you can connect to WiFi. Even if you reset the module, it will not automatically reconnect. + The following template is useful for controlling the registration of unknown access points. In this case, the ESP module establishes a WiFi connection using WiFi.begin natively without relying on AutoConnect. + Known access point credentials are saved by AutoConnect, to the ESP module can use the saved credentials to handle WiFi.begin natively. This means that you can explicitly register available access points when needed, and the ESP module will not use unknown access points under normal situations. + + ```cpp + AutoConnect* portal = nullptr; + + bool detectSwitch() { + /* + Returns true if an external switch to configure is active. + */ + } + + bool connectWiFi(const char* ssid, const char* password, unsigned long timeout) { + WiFi.mode(WIFI_STA); + delay(100); + WiFi.begin(ssid, password); + unsigned long tm = millis(); + while (WiFi.status() != WL_CONNECTED) { + if (millis() - tm > timeout) + return false; + } + return true; + } + + void setup() { + AutoConnectCredential credt; + station_config_t config; + for (int8_t e = 0; e < credt.entries(); e++) { + credt.load(e, &config); + if (connectWiFi(config.ssid, config.password, 30000)) + break; + } + if (WiFi.status() != WL_CONNECTED) { + // Here, do something when WiFi cannot reach. + } + } + + void loop() { + if (detectSwitch()) { + AutoConnectConfig config; + config.immediateStart= true; + if (!portal) { + portal = new AutoConnect; + } + portal->config(config); + if (portal->begin()) { + portal->end(); + delete portal; + portal = nullptr; + } + } + // Here, ordinally sketch logic. + } + ``` ### Refers the hosted ESP8266WebServer/WebServer @@ -419,30 +519,20 @@ An example sketch used with the PageBuilder as follows and it explains how it ai ## Configuration functions -### Configuration for Soft AP and captive portal +You can adjust the AutoConnect behave at run-time using [AutoConnectConfig](apiconfig.md). AutoConnectConfig is a class that has only AutoConnect configuration data. You define the behavior of AutoConnect using AutoConnectConfig member variables and give it to AutoConnect via the [AutoConnect::config](api.md#config) function. -AutoConnect will activate SoftAP at failed the first *WiFi.begin*. It SoftAP settings are stored in [**AutoConnectConfig**](apiconfig.md#autoconnectconfig) as the following parameters. The sketch could be configured SoftAP using these parameters, refer the [AutoConnectConfig API](apiconfig.md#public-member-variables) for details. +AutoConnectConfig can specify the following runtime behavior: -- IP address of SoftAP activated. -- Gateway IP address. -- Subnet mask. -- SSID for SoftAP. -- Password for SoftAP. -- Channel. -- SoftAP name. -- Hidden attribute. -- Station hostname. -- Auto save credential. -- Offset address of the credentials storage area in EEPROM. -- Captive portal time out limit. -- Maintain portal function even after a timeout. -- Length of start up time after reset. -- Automatic starting the captive portal. -- Start the captive portal forcefully. -- Auto reset after connection establishment. -- Home URL of the user sketch application. -- Menu title. -- Ticker signal output. +- [Assign user sketch's home path](advancedusage.md#assign-user-sketchs-home-path) +- [Change menu title](advancedusage.md#change-menu-title) +- [Change SSID and Password for SoftAP](advancedusage.md#change-ssid-and-password-for-softap) +- [Configuration for Soft AP and captive portal](advancedusage.md#configuration-for-soft-ap-and-captive-portal) +- [Configure WiFi channel](advancedusage.md#configure-wifi-channel) +- [Move the saving area of EEPROM for the credentials](advancedusage.md#move-the-saving-area-of-eeprom-for-the-credentials) +- [Relocate the AutoConnect home path](advancedusage.md#relocate-the-autoconnect-home-path) +- [Static IP assignment](advancedusage.md#static-ip-assignment-2) +- [Station host name](advancedusage.md#station-host-name) +- [Ticker for WiFi status](advancedusage.md#ticker-for-wifi-status) !!! note "AutoConnect::config before AutoConnect::begin" *AutoConnect::config* must be executed before *AutoConnect::begin*. @@ -453,6 +543,27 @@ AutoConnect will activate SoftAP at failed the first *WiFi.begin*. It SoftAP set +### Change menu title + +Although the default menu title is **AutoConnect**, you can change the title by setting [*AutoConnectConfig::title*](apiconfig.md#title). To set the menu title properly, you must set before calling [*AutoConnect::begin*](api.md#begin). + +```cpp hl_lines="6 7" +AutoConnect Portal; +AutoConnectConfig Config; + +void setup() { + // Set menu title + Config.title = "FSBrowser"; + Portal.config(Config); + Portal.begin(); +} +``` + +Executing the above sketch will rewrite the menu title for the **FSBrowser** as the below. + +
+ + ### Change SSID and Password for SoftAP An **esp8266ap** is default SSID name for SoftAP of captive portal and password is **12345678** for ESP8266. Similarly, **esp32ap** and **12345678** for ESP32. You can change both by setting [apid](apiconfig.md#apid) and [psk](apiconfig.md#psk). @@ -481,9 +592,43 @@ void setup() { } ``` -You can also assign no password to SoftAP launched as a captive portal. Assigning a null string as `String("")` to [AutoConnectConfig::psk](apiconfig.md#psk) does not require a password when connecting to SoftAP. +You can also assign no password to SoftAP launched as a captive portal. Assigning a null string as `String("")` to [*AutoConnectConfig::psk*](apiconfig.md#psk) does not require a password when connecting to SoftAP. But this method is not recommended. The broadcast radio of SSID emitted from SoftAP will leak and reach several tens of meters. +### Configuration for Soft AP and captive portal + +AutoConnect will activate SoftAP at failed the first *WiFi.begin*. It SoftAP settings are stored in [**AutoConnectConfig**](apiconfig.md#autoconnectconfig) as the following parameters. The sketch could be configured SoftAP using these parameters, refer the [AutoConnectConfig API](apiconfig.md#public-member-variables) for details. + +### Configure WiFi channel + +Appropriately specifying the WiFi channel to use for ESP8266 and ESP32 is essential for a stable connection with the access point. AutoConnect remembers the WiFi channel with a credential of the access point once connected and reuses it. + +The default channel when a captive portal starts and AutoConnect itself becomes an access point is the [*AutoConnectConfig::channel*](apiconfig.md#channel) member. If this channel is different from the channel of the access point you will attempt to connect, WiFi.begin may fail. The cause is that the ESP module shares the same channel in AP mode and STA mode. If the connection attempt is not stable, specifying a proper channel using AutoConnectConfig::channel may result in a stable connection. + +### Move the saving area of EEPROM for the credentials + +By default, the credentials saving area is occupied from the beginning of EEPROM area. [ESP8266 Arduino core document](http://arduino-esp8266.readthedocs.io/en/latest/filesystem.html?highlight=eeprom#flash-layout) says that: + + +> The following diagram illustrates flash layout used in Arduino environment: + +> ``` +> |--------------|-------|---------------|--|--|--|--|--| +> ^ ^ ^ ^ ^ +> Sketch OTA update File system EEPROM WiFi config (SDK) +> ``` + +and + +> EEPROM library uses one sector of flash located [just after the SPIFFS](http://arduino-esp8266.readthedocs.io/en/latest/libraries.html?highlight=SPIFFS#eeprom). + +Also, in ESP32 arduino core 1.0.2 earlier, the placement of the EEPROM area of ESP32 is described in the [partition table](https://github.com/espressif/arduino-esp32/blob/master/tools/partitions/default.csv). So in the default state, the credential storage area used by AutoConnect conflicts with data owned by the user sketch. It will be destroyed together saved data in EEPROM by user sketch and AutoConnect each other. But you can move the storage area to avoid this. + +The [**boundaryOffset**](apiconfig.md#boundaryoffset) in [AutoConnectConfig](apiconfig.md) specifies the start offset of the credentials storage area. The default value is 0. + +!!! info "The boundaryOffset ignored with AutoConnect v1.0.0 later on ESP32 arduino core 1.0.3 later" + For ESP32 arduino core 1.0.3 and later, AutoConnect will store credentials to Preferences in the nvs. Since it is defined as the namespace dedicated to AutoConnect and separated from the area used for user sketches. Therefore, the [boundaryOffset](apiconfig.md#boundaryoffset) is ignored with the combination of AutoConnect v1.0.0 or later and the arduino-esp32 1.0.3 or later. + ### Relocate the AutoConnect home path A home path of AutoConnect is **/\_ac** by default. You can access from the browser with http://IPADDRESS/\_ac. You can change the home path by revising [**AUTOCONNECT_URI**](https://github.com/Hieromon/AutoConnect/blob/master/src/AutoConnectDefs.h#L62) macro in the include header file as [AutoConnectDef.h](https://github.com/Hieromon/AutoConnect/blob/master/src/AutoConnectDef.h). @@ -521,7 +666,7 @@ portal.begin(); ### Station host name -[AutoConnectConfig::hostName](apiconfig.md#hostname) assigns the station DHCP hostname which complies with [RFC952](https://tools.ietf.org/html/rfc952). It must satisfy the following constraints. +[*AutoConnectConfig::hostName*](apiconfig.md#hostname) assigns the station DHCP hostname which complies with [RFC952](https://tools.ietf.org/html/rfc952). It must satisfy the following constraints. - Up to 24 characters - Only the alphabet (a-z, A-Z), digits (0-9), minus sign (-) @@ -531,7 +676,7 @@ portal.begin(); Flicker signal can be output from the ESP8266/ESP32 module according to WiFi connection status. If you connect the LED to the signal output pin, you can know the WiFi connection status during behavior inside AutoConnect::begin through the LED blink. -[AutoConnectConfig::ticker](apiconfig.md#ticker) option specifies flicker signal output. The following sketch is an example of flashing the active-high LED connected to pin #16 according to WiFi connection during the AutoConnect::begin. +[*AutoConnectConfig::ticker*](apiconfig.md#ticker) option specifies flicker signal output. The following sketch is an example of flashing the active-high LED connected to pin #16 according to WiFi connection during the AutoConnect::begin. ```cpp AutoConnect portal; @@ -565,11 +710,11 @@ The flicker cycle length is defined by some macros in `AutoConnectDefs.h` header - `AUTOCONNECT_FLICKER_WIDTHAP` and `AUTOCONNECT_FLICKER_WIDTHDC`: Specify the duty rate for each period[ms] in 8-bit resolution. -[AutoConnectConfig::tickerPort](apiconfig.md#tickerport) specifies a port that outputs the flicker signal. If you are using an LED-equipped ESP module board, you can assign a LED pin to the tick-port for the WiFi connection monitoring without the external LED. The default pin is arduino valiant's **LED\_BUILTIN**. You can refer to the Arduino IDE's variant information to find out which pin actually on the module assign to **LED\_BUILTIN**.[^3] +[*AutoConnectConfig::tickerPort*](apiconfig.md#tickerport) specifies a port that outputs the flicker signal. If you are using an LED-equipped ESP module board, you can assign a LED pin to the tick-port for the WiFi connection monitoring without the external LED. The default pin is arduino valiant's **LED\_BUILTIN**. You can refer to the Arduino IDE's variant information to find out which pin actually on the module assign to **LED\_BUILTIN**.[^3] [^3]: It's defined in the `pins_arduino.h` file, located in the sub-folder named **variants** wherein Arduino IDE installed folder. -[AutoConnectConfig::tickerOn](apiconfig.md#tickeron) specifies the active logic level of the flicker signal. This value indicates the active signal level when driving the ticker. For example, if the LED connected to tickPort lights by LOW, the tickerOn is **LOW**. The logic level of LED_BUILTIN for popular modules are as follows: +[*AutoConnectConfig::tickerOn*](apiconfig.md#tickeron) specifies the active logic level of the flicker signal. This value indicates the active signal level when driving the ticker. For example, if the LED connected to tickPort lights by LOW, the tickerOn is **LOW**. The logic level of LED_BUILTIN for popular modules are as follows: module | Logic level | LED_BUILTIN Pin | Arduino alias ----|----|:---:|---- diff --git a/mkdocs/apiconfig.md b/mkdocs/apiconfig.md index 83f314a..04f531e 100644 --- a/mkdocs/apiconfig.md +++ b/mkdocs/apiconfig.md @@ -189,6 +189,14 @@ Disable the first WiFi.begin() and start the captive portal. If this option is e
falseEnable the first WiFi.begin() and it will start captive portal when connection failed. This is default.
+### minRSSI + +Specify the lower limit of the WiFi signal strength allowed to use as an access point. This value should be greater than -120 as RSSI. Generally, a data link will not be established unless it exceeds -90 dBm. Also, packet transmission is not reliable below -70 dBm to -80 dBm. +
+
**Type**
+
int16_tThe default value is -120
+
+ ### netmask Sets subnet mask for Soft AP in captive portal. When AutoConnect fails the initial WiFi.begin, it starts the captive portal with the IP address specified this. @@ -205,6 +213,17 @@ Specify the timeout value of the captive portal in [ms] units. It is valid when
unsigned longCaptive portal timeout value. The default value is 0.
+### principle + +Specify the connection order will attempt to connect to one of the highest RSSI values among multiple available access points. It is given as an enumeration value of **AC_PRINCIPLE_t** indicating. +
+
**Type**
+
AC_PRINCIPLE_t
+
**Value**
+
AC_PRINCIPLE_RECENT Attempts to connect in the order of the saved credentials entries. The entry order is generally a time series connected in the past.
+
AC_PRINCIPLE_RSSI Attempts to connect to one of the highest RSSI values among multiple available access points.
+
+ ### psk Sets password for SoftAP. The length should be from 8 to up to 63. The default value is **12345678**. diff --git a/mkdocs/changelog.md b/mkdocs/changelog.md index 856e22c..e5676b1 100644 --- a/mkdocs/changelog.md +++ b/mkdocs/changelog.md @@ -1,3 +1,6 @@ +### [1.1.5] Mar. 19, 2020 +- Supports an attempt order when available APs would be found multiple, and RSSI lower bound on AP signal strength. This option can specify the order of connection attempting according to the WiFi signal strength indicated with RSSI. + #### [1.1.4] Feb. 14, 2020 - Supports for overriding text of the menu items with user-defined labels. - Fixed the compiler warning with experimental WiFi mode of ESP8266. diff --git a/mkdocs/faq.md b/mkdocs/faq.md index ed0daa6..26ae605 100644 --- a/mkdocs/faq.md +++ b/mkdocs/faq.md @@ -67,7 +67,7 @@ You have the following two options to avoid this conflict: - Suppresses the automatic save operation of credentials by AutoConnect. You can completely stop saving the credentials by AutoConnect. However, if you select this option, you lose the past credentials which were able to connect to the AP. Therefore, the effect of the [automatic reconnection feature](advancedusage.md#automatic-reconnect) will be lost. - If you want to stop the automatic saving of the credentials, uses [AutoConnectConfig::autoSave](apiconfig.md#autosave) option specifying **AC_SAVECREDENTIAL_NEVER**. Refer to the chapter on [Advanced usage](advancedusage.md#auto-save-credential) for details. + If you want to stop the automatic saving of the credentials, uses [AutoConnectConfig::autoSave](apiconfig.md#autosave) option specifying **AC_SAVECREDENTIAL_NEVER**. Refer to the chapter on [Advanced usage](advancedusage.md#autosave-credential) for details. ## Does not appear esp8266ap in smartphone. From 8eda9af6989c3986989c6fcddf78a6deb8966a1c Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Mon, 23 Mar 2020 01:58:02 +0900 Subject: [PATCH 09/11] Supports lower RSSI limit. --- mkdocs/advancedusage.md | 13 +-- mkdocs/images/process_begin.svg | 142 ++++++++++++++++---------------- mkdocs/lsbegin.md | 8 +- 3 files changed, 83 insertions(+), 80 deletions(-) diff --git a/mkdocs/advancedusage.md b/mkdocs/advancedusage.md index eaf802a..0426239 100644 --- a/mkdocs/advancedusage.md +++ b/mkdocs/advancedusage.md @@ -14,11 +14,11 @@ AutoConnect stores the established WiFi connection in the flash of the ESP8266/E ### Automatic reconnect -When the captive portal is started, SoftAP starts and the STA is disconnected. The current SSID setting memorized in ESP8266 will be lost but then the reconnect behavior of ESP32 is somewhat different from this. +AutoConnect changes WIFI mode depending on the situation. The [AutoConnect::begin](lsbegin.md) function starts WIFI in STA mode and starts the webserver if the connection is successful by the 1st-WiFi.begin. But if the connection fails with the least recently established access point, AutoConnect will switch the WIFI mode to AP_STA and starts the DNS server to be able to launch a captive portal. -The [*WiFiSTAClass::disconnect*](https://github.com/espressif/arduino-esp32/blob/a0f0bd930cfd2d607bf3d3288f46e2d265dd2e11/libraries/WiFi/src/WiFiSTA.h#L46) function implemented in the arduino-esp32 has extended parameters than the ESP8266's arduino-core. The second parameter of WiFi.disconnect on the arduino-esp32 core that does not exist in the [ESP8266WiFiSTAClass](https://github.com/esp8266/Arduino/blob/7e1bdb225da8ab337373517e6a86a99432921a86/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp#L296) has the effect of deleting the currently connected WiFi configuration and its default value is "false". On the ESP32 platform, even if WiFi.disconnect is executed, WiFi.begin() without the parameters in the next turn will try to connect to that AP. That is, automatic reconnection is implemented in arduino-esp32 already. Although this behavior appears seemingly competent, it is rather a disadvantage in scenes where you want to change the access point each time. When explicitly disconnecting WiFi from the Disconnect menu, AutoConnect will erase the AP connection settings saved by arduino-esp32 core. AutoConnect's automatic reconnection is a mechanism independent from the automatic reconnection of the arduino-esp32 core. +When the captive portal is started, SoftAP starts and the STA is disconnected. At this point, the station configuration information that the ESP module has stored on its own (it is known as the SDK's [station_config](https://github.com/esp8266/Arduino/blob/db75d2c448bfccc6dc308bdeb9fbd3efca7927ff/tools/sdk/include/user_interface.h#L249) structure) is discarded. -If the [**autoReconnect**](apiconfig.md#autoreconnect) option of the [AutoConnectConfig](apiconfig.md) class is enabled, it automatically attempts to reconnect to the disconnected past access point. When the autoReconnect option is specified, AutoConnect will not start SoftAP immediately if the first WiFi.begin fails. It will scan WiFi signal and the same connection information as the detected BSSID is stored in the flash as AutoConnect's credentials, explicitly apply it with WiFi.begin and rerun. +AutoConnect can connect to an access point again using saved credential that has disconnected once, and its control is allowed by [**autoReconnect**](apiconfig.md#autoreconnect). [*AutoConnectConfig::autoReconnect*](apiconfig.md#autoreconnect) option specifies to attempt to reconnect to the past established access point that stored in saved credentials. AutoConnect does not start SoftAP immediately even if 1st-WiFi.begin fails when the [**autoReconnct**](apiconfig.md#autoreconnect) is enabled. It will scan the WiFi signal, and if the same BSSID as the detected BSSID is stored in flash as AutoConnect credentials, explicitly apply it and reruns WiFi.begin still WIFI_STA mode. (The autoReconnect works effectively even if the SSID is a hidden access point) ```cpp hl_lines="3" AutoConnect Portal; @@ -28,10 +28,11 @@ Portal.config(Config); Portal.begin(); ``` -An autoReconnect option is available to *AutoConnect::begin* without SSID and pass Passphrase. +An [**autoRecconect**](apiconfig.md#autoreconnect) option is only available for [*AutoConnect::begin*](api.md#begin) without SSID and PASSWORD parameter. -!!! caution "An autoReconnect will work if SSID detection succeeded" - An autoReconnect will not effect if the SSID which stored credential to be connected is a hidden access point. +!!! note "An autoReconnect is not autoreconnect" + The [*WiFiSTAClass::disconnect*](https://github.com/espressif/arduino-esp32/blob/a0f0bd930cfd2d607bf3d3288f46e2d265dd2e11/libraries/WiFi/src/WiFiSTA.h#L46) function implemented in the arduino-esp32 has extended parameters than the ESP8266's arduino-core. The second parameter of WiFi.disconnect on the arduino-esp32 core that does not exist in the [ESP8266WiFiSTAClass](https://github.com/esp8266/Arduino/blob/7e1bdb225da8ab337373517e6a86a99432921a86/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp#L296) has the effect of deleting the currently connected WiFi configuration and its default value is "false". On the ESP32 platform, even if WiFi.disconnect is executed, WiFi.begin() without the parameters in the next turn will try to connect to that AP. That is, automatic reconnection is implemented in arduino-esp32 already. Although this behavior appears seemingly competent, it is rather a disadvantage in scenes where you want to change the access point each time. When explicitly disconnecting WiFi from the Disconnect menu, AutoConnect will erase the AP connection settings saved by the arduino-esp32 core. AutoConnect's automatic reconnection is a mechanism independent from the automatic reconnection of the arduino-esp32 core. + ### Autosave Credential diff --git a/mkdocs/images/process_begin.svg b/mkdocs/images/process_begin.svg index b9224a9..acef36c 100644 --- a/mkdocs/images/process_begin.svg +++ b/mkdocs/images/process_begin.svg @@ -9,12 +9,12 @@ xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="109mm" + width="104.57415mm" height="371.83472mm" - viewBox="0 0 108.99999 371.83472" + viewBox="0 0 104.57414 371.83472" version="1.1" id="svg8776" - inkscape:version="0.92.2 (5c3e80d, 2017-08-06)" + inkscape:version="0.92.4 (5da689c313, 2019-01-14)" sodipodi:docname="process_begin.svg"> @@ -248,8 +248,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="1.4142136" - inkscape:cx="259.43725" - inkscape:cy="1200.0696" + inkscape:cx="305.90966" + inkscape:cy="637.13379" inkscape:document-units="mm" inkscape:current-layer="layer1" showgrid="false" @@ -261,23 +261,24 @@ inkscape:snap-smooth-nodes="true" inkscape:snap-midpoints="false" inkscape:bbox-paths="true" - inkscape:bbox-nodes="true" + inkscape:bbox-nodes="false" inkscape:snap-bbox-edge-midpoints="true" inkscape:snap-bbox-midpoints="true" - inkscape:window-width="1571" + inkscape:window-width="1920" inkscape:window-height="1013" - inkscape:window-x="1376" - inkscape:window-y="0" - inkscape:window-maximized="0" + inkscape:window-x="2551" + inkscape:window-y="-9" + inkscape:window-maximized="1" fit-margin-top="0" fit-margin-left="0" fit-margin-right="0" - fit-margin-bottom="0"> + fit-margin-bottom="0" + showguides="true"> + originx="-23.664533" + originy="15.544253" /> @@ -295,10 +296,10 @@ inkscape:label="レイヤー 1" inkscape:groupmode="layer" id="layer1" - transform="translate(-23.664512,59.290411)"> + transform="translate(-23.664535,59.290408)"> @@ -939,24 +940,24 @@ YES NO + transform="translate(-25.135403,-186.53117)"> + transform="translate(-0.22278483,28.641187)"> WiFi.config (STA) + id="g1141" + transform="translate(0,15.879204)"> + transform="translate(-30.682548,2.7829924)"> + transform="translate(-37.753577,18.181876)"> @@ -1374,55 +1376,55 @@ xml:space="preserve" style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.17499995px;line-height:1.25;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332" x="35.828152" - y="-18.166817" + y="-2.2876122" id="text10760-5-3">NO YES Loads saved credentials from the flashLoads saved credentials from the flashthat matches the last SSID stored inthat matches the last SSID stored inthe ESP module. + x="79.343994" + y="-10.161308">the ESP module. If that credential has a static IP,If that credential has a static IP,restore it. + x="79.354843" + y="2.408726">restore it. diff --git a/mkdocs/lsbegin.md b/mkdocs/lsbegin.md index 0c63726..5c70dec 100644 --- a/mkdocs/lsbegin.md +++ b/mkdocs/lsbegin.md @@ -1,17 +1,17 @@ ## AutoConnect::begin logic sequence -Several parameters as follows of [AutoConnectConfig](apiconfig.md) affect the behavior of [AutoConnect::begin](api.md#begin) function. Each parameter affects the behaves in interacted order with the priority and apply to the logic sequence of [AutoConnect::begin](api.md#begin). +The following parameters of [AutoConnectConfig](apiconfig.md) affect the behavior of [AutoConnect::begin](api.md#begin) function and control a logic sequence. They are also evaluated on a case-by-case basis and may not be valid in all situations. The sketch must consider the role of these parameters and the conditions under which they will work as intended. You need to understand what happens when using these parameters in combination. -- [immediateStart](apiconfig.md#immediatestart) : The captive portal start immediately, without first WiFi.begin. +- [immediateStart](apiconfig.md#immediatestart) : The captive portal start immediately, without the 1st-WiFi.begin. - [autoReconenct](apiconfig.md#autoreconnect) : Attempt re-connect with past SSID by saved credential. - [portalTimeout](apiconfig.md#portaltimeout) : Time out limit for the portal. - [retainPortal](apiconfig.md#retainportal) : Keep DNS server functioning for the captive portal. -You can use these parameters in combination with sketch requirements and need to understand correctly the behavior caused by the parameters. The following chart shows the AutoConnect::begin logic sequence including the effect of these parameters. +The following chart shows the AutoConnect::begin logic sequence that contains the control flow with each parameter takes effect. -For example, [AutoConnect::begin](api.md#begin) will not exits without the [**portalTimeout**](apiconfig.md#portaltimeout) while the connection not establishes, but WebServer will start to work. A DNS server that detects the probe of the captive portal is also effective. So, your sketch may work seemingly, but it will close with inside a loop of the [AutoConnect::begin](api.md#begin) function. Especially when invoking [AutoConnect::begin](api.md#begin) in the **setup()**, execution control does not pass to the **loop()**. +For example, [AutoConnect::begin](api.md#begin) will not end without the [**portalTimeout**](apiconfig.md#portaltimeout) while the connection not establishes, but WebServer will start to work. And the DNS server also will start to make the captive portal detection to the client. The custom web page now responds correctly with the behavior of the two internally launched servers, and the sketch looks like working. But AutoConnect::begin does not end yet. Especially when invoking AutoConnect::begin in the **setup()**, control flow does not pass to the **loop()**. As different scenes, you may use the [**immediateStart**](apiconfig.md#immediatestart) effectively. Equipped the external switch to activate the captive portal with the ESP module, combined with the [**portalTime**](apiconfig.md#portaltimeout) and the [**retainPortal**](apiconfig.md#retainportal) it will become WiFi active connection feature. You can start [AutoConnect::begin](api.md#begin) at any point in the **loop()**, which allows your sketch can behave both the offline mode and the online mode. From 3d2321156d57f4618aeb9460c1ecbfff6504a1cb Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Tue, 24 Mar 2020 15:54:29 +0900 Subject: [PATCH 10/11] Description revised --- mkdocs/lsbegin.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/mkdocs/lsbegin.md b/mkdocs/lsbegin.md index 5c70dec..6bc553d 100644 --- a/mkdocs/lsbegin.md +++ b/mkdocs/lsbegin.md @@ -1,6 +1,6 @@ ## AutoConnect::begin logic sequence -The following parameters of [AutoConnectConfig](apiconfig.md) affect the behavior of [AutoConnect::begin](api.md#begin) function and control a logic sequence. They are also evaluated on a case-by-case basis and may not be valid in all situations. The sketch must consider the role of these parameters and the conditions under which they will work as intended. You need to understand what happens when using these parameters in combination. +The following parameters of [AutoConnectConfig](apiconfig.md) affect the behavior and control a logic sequence of [AutoConnect::begin](api.md#begin) function. These parameters are evaluated on a case-by-case basis and may not be valid in all situations. The Sketch must consider the role of these parameters and the conditions under which they will work as intended. You need to understand what happens when using these parameters in combination. - [immediateStart](apiconfig.md#immediatestart) : The captive portal start immediately, without the 1st-WiFi.begin. - [autoReconenct](apiconfig.md#autoreconnect) : Attempt re-connect with past SSID by saved credential. @@ -11,13 +11,12 @@ The following chart shows the AutoConnect::begin logic sequence that contains th -For example, [AutoConnect::begin](api.md#begin) will not end without the [**portalTimeout**](apiconfig.md#portaltimeout) while the connection not establishes, but WebServer will start to work. And the DNS server also will start to make the captive portal detection to the client. The custom web page now responds correctly with the behavior of the two internally launched servers, and the sketch looks like working. But AutoConnect::begin does not end yet. Especially when invoking AutoConnect::begin in the **setup()**, control flow does not pass to the **loop()**. +For example, [AutoConnect::begin](api.md#begin) will not end without the [**portalTimeout**](apiconfig.md#portaltimeout) while the connection not establishes, but WebServer will start to work. Also, the DNS server will start to make a series of the captive portal operation on the client device. The custom web pages now respond correctly by the two internally launched servers, and the Sketch looks like working. But AutoConnect::begin does not end yet. Especially when invoking AutoConnect::begin in the **setup()**, control flow does not pass to the **loop()**. -As different scenes, you may use the [**immediateStart**](apiconfig.md#immediatestart) effectively. Equipped the external switch to activate the captive portal with the ESP module, combined with the [**portalTime**](apiconfig.md#portaltimeout) and the [**retainPortal**](apiconfig.md#retainportal) it will become WiFi active connection feature. You can start [AutoConnect::begin](api.md#begin) at any point in the **loop()**, which allows your sketch can behave both the offline mode and the online mode. +However, [**portalTimeout**](apiconfig.md#portaltimeout) can be used effectively in various scenes in combination with [**immediateStart**](apiconfig.md#immediatestart). Its combination is useful for implementing Sketches that can work in situations where WiFi is not always available. Namely, Sketch will support a running mode with both offline and online. +If AutoConnect staying in the captive portal exceeds the time limit, Sketch can switch a process-mode to offline according to WiFi signal detection. Conversely, it can start a captive portal immediately with intentional control to shift the process-mode to online from offline. Especially, You can activate the process-mode shift manually by trigger via external switches. -The [**retainPortal**](apiconfig.md#retainportal) option allows the DNS server to continue operation after exiting from [AutoConnect::begin](api.md#begin). AutoConnect traps captive portal detection from the client and redirects it to the AutoConnect menu. That trap will answer all unresolved addresses with SoftAP's IP address. If the URI handler for the source request is undefined, it returns a 302 response with `SoftAPIP/_ac` to the client. This is the mechanism of AutoConnect's captive portal. Captive portal probes will frequently occur while you are attempting on the client device's WiFi connection Apps and these implementations are varied each OS, so it not realistic to identify all probing URIs. Therefore, while retainPortal is enabled, it is not preferable to executing the sketch under the WiFi connection Apps on the client device. (Probably not work correctly) You need to exit from the WiFi connection Apps once. - -Please consider these kinds of influence when you make sketches. +The [**retainPortal**](apiconfig.md#retainportal) option allows continuing the captive portal operation even after exiting from AutoConnect::begin. This option allows the use of the automatic portal pop-ups on the smartphone devices etc. even after the ESP module has established a connection with some access point in STA mode. (Excepts blocking a series of portal processes via intentionally accessing a URL outside the scope of **/_ac**. eg., if you try to communicate with the mqtt server without connecting to the access point, its access will be redirected to **/_ac** caused by the trap of the captive portal detection) !!! info "The AutoConnect::begin 3rd parameter" Another parameter as the [3rd parameter](api.md#begin) of AutoConnect::begin related to timeout constrains the connection wait time after WiFi.begin. It is the **CONNECTED** judgment of the above chart that it has an effect. From ba944b2c2a51f72f346985b7b46e390ac789b52c Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Wed, 25 Mar 2020 04:26:13 +0900 Subject: [PATCH 11/11] Improved RESET countdown display --- src/AutoConnectPage.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/AutoConnectPage.cpp b/src/AutoConnectPage.cpp index f69b99a..c637a78 100644 --- a/src/AutoConnectPage.cpp +++ b/src/AutoConnectPage.cpp @@ -591,7 +591,12 @@ const char AutoConnect::_PAGE_RESETTING[] PROGMEM = { "" AUTOCONNECT_PAGETITLE_RESETTING "" "" "" - "

{{RESET}}

" + "

{{RESET}}

" + "" "" "" };