Add files via upload

Added options to:
* Set minimum RSSI for connection
* Connect to stored AP with strongest RSSI
pull/187/head
gw8484 5 years ago committed by GitHub
parent ebb95cd8e5
commit b0d7d5de6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 41
      src/AutoConnect.cpp
  2. 17
      src/AutoConnect.h
  3. 14
      src/AutoConnectDefs.h

@ -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); AC_DBG("WiFi.begin(%s%s%s)\n", ssid == nullptr ? "" : ssid, passphrase == nullptr ? "" : ",", passphrase == nullptr ? "" : passphrase);
cs = _waitForConnect(_connectTimeout) == WL_CONNECTED; 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. // 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); AC_DBG("%d network(s) found\n", (int)nn);
if (nn > 0) { if (nn > 0) {
// Determine valid credentials by BSSID. // 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++) { for (uint8_t i = 0; i < credential.entries(); i++) {
credential.load(i, &_credential); credential.load(i, &_credential);
for (uint8_t n = 0; n < nn; n++) { 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))) if (!memcmp(_credential.bssid, WiFi.BSSID(n), sizeof(station_config_t::bssid)))
return true; return true;
#endif
} }
} }
#ifdef INC_RSSI_USE_SUP //!!!
if(maxRSSIWifiIndex>=0) {
credential.load(maxRSSICredIndex, &_credential);
return true;
}
#endif
} }
} }
else if (strlen(ssid)) else if (strlen(ssid))

@ -58,6 +58,10 @@ class AutoConnectConfig {
* assigned from macro. Password is same as above too. * assigned from macro. Password is same as above too.
*/ */
AutoConnectConfig() : AutoConnectConfig() :
#ifdef INC_RSSI_USE_SUP //!!!
conMinRSSI(AUTOCONNECT_CON_MIN_RSSI),
conFindMaxRSSI(AUTOCONNECT_CON_FIND_MAX_RSSI),
#endif
apip(AUTOCONNECT_AP_IP), apip(AUTOCONNECT_AP_IP),
gateway(AUTOCONNECT_AP_GW), gateway(AUTOCONNECT_AP_GW),
netmask(AUTOCONNECT_AP_NM), netmask(AUTOCONNECT_AP_NM),
@ -90,6 +94,10 @@ class AutoConnectConfig {
* Configure by SSID for the captive portal access point and password. * 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) : 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), apip(AUTOCONNECT_AP_IP),
gateway(AUTOCONNECT_AP_GW), gateway(AUTOCONNECT_AP_GW),
netmask(AUTOCONNECT_AP_NM), netmask(AUTOCONNECT_AP_NM),
@ -122,6 +130,10 @@ class AutoConnectConfig {
~AutoConnectConfig() {} ~AutoConnectConfig() {}
AutoConnectConfig& operator=(const AutoConnectConfig& o) { AutoConnectConfig& operator=(const AutoConnectConfig& o) {
#ifdef INC_RSSI_USE_SUP //!!!
conMinRSSI=o.conMinRSSI;
conFindMaxRSSI=o.conFindMaxRSSI;
#endif
apip = o.apip; apip = o.apip;
gateway = o.gateway; gateway = o.gateway;
netmask = o.netmask; netmask = o.netmask;
@ -153,6 +165,11 @@ class AutoConnectConfig {
return *this; 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 apip; /**< SoftAP IP address */
IPAddress gateway; /**< SoftAP gateway address */ IPAddress gateway; /**< SoftAP gateway address */
IPAddress netmask; /**< SoftAP subnet mask */ IPAddress netmask; /**< SoftAP subnet mask */

@ -10,6 +10,19 @@
#ifndef _AUTOCONNECTDEFS_H_ #ifndef _AUTOCONNECTDEFS_H_
#define _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. // Uncomment the following AC_DEBUG to enable debug output.
//#define AC_DEBUG //#define AC_DEBUG
@ -25,6 +38,7 @@
#define AC_DBG_DUMB(...) #define AC_DBG_DUMB(...)
#endif // !AC_DEBUG #endif // !AC_DEBUG
// Indicator to specify that AutoConnectAux handles elements with JSON. // Indicator to specify that AutoConnectAux handles elements with JSON.
// Comment out the AUTOCONNECT_USE_JSON macro to detach the ArduinoJson. // Comment out the AUTOCONNECT_USE_JSON macro to detach the ArduinoJson.
#ifndef AUTOCONNECT_NOUSE_JSON #ifndef AUTOCONNECT_NOUSE_JSON

Loading…
Cancel
Save