From 1152ced7eac99ce9313cd165bb6db412dd9ba644 Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Fri, 20 Mar 2020 16:20:31 +0900 Subject: [PATCH] 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);