@@ -83,7 +83,7 @@ static bool sta_config_equal(const wifi_config_t& lhs, const wifi_config_t& rhs)
83
83
return true ;
84
84
}
85
85
86
- static void wifi_sta_config (wifi_config_t * wifi_config, const char * ssid=NULL , const char * password=NULL , const uint8_t * bssid=NULL , uint8_t channel=0 , wifi_scan_method_t scan_method=WIFI_ALL_CHANNEL_SCAN, wifi_sort_method_t sort_method=WIFI_CONNECT_AP_BY_SIGNAL, uint16_t listen_interval=0 , bool pmf_required=false ){
86
+ static void wifi_sta_config (wifi_config_t * wifi_config, const char * ssid=NULL , const char * password=NULL , const uint8_t * bssid=NULL , uint8_t channel=0 , wifi_auth_mode_t min_security=WIFI_AUTH_WPA2_PSK, wifi_scan_method_t scan_method=WIFI_ALL_CHANNEL_SCAN, wifi_sort_method_t sort_method=WIFI_CONNECT_AP_BY_SIGNAL, uint16_t listen_interval=0 , bool pmf_required=false ){
87
87
wifi_config->sta .channel = channel;
88
88
wifi_config->sta .listen_interval = listen_interval;
89
89
wifi_config->sta .scan_method = scan_method;// WIFI_ALL_CHANNEL_SCAN or WIFI_FAST_SCAN
@@ -99,7 +99,7 @@ static void wifi_sta_config(wifi_config_t * wifi_config, const char * ssid=NULL,
99
99
if (ssid != NULL && ssid[0 ] != 0 ){
100
100
_wifi_strncpy ((char *)wifi_config->sta .ssid , ssid, 32 );
101
101
if (password != NULL && password[0 ] != 0 ){
102
- wifi_config->sta .threshold .authmode = WIFI_AUTH_WPA2_PSK ;
102
+ wifi_config->sta .threshold .authmode = min_security ;
103
103
_wifi_strncpy ((char *)wifi_config->sta .password , password, 64 );
104
104
}
105
105
if (bssid != NULL ){
@@ -115,6 +115,9 @@ static void wifi_sta_config(wifi_config_t * wifi_config, const char * ssid=NULL,
115
115
116
116
bool WiFiSTAClass::_autoReconnect = true ;
117
117
bool WiFiSTAClass::_useStaticIp = false ;
118
+ wifi_auth_mode_t WiFiSTAClass::_minSecurity = WIFI_AUTH_WPA2_PSK;
119
+ wifi_scan_method_t WiFiSTAClass::_scanMethod = WIFI_FAST_SCAN;
120
+ wifi_sort_method_t WiFiSTAClass::_sortMethod = WIFI_CONNECT_AP_BY_SIGNAL;
118
121
119
122
static wl_status_t _sta_status = WL_NO_SHIELD;
120
123
static EventGroupHandle_t _sta_status_group = NULL ;
@@ -243,12 +246,7 @@ wl_status_t WiFiSTAClass::begin(const char* ssid, const char *passphrase, int32_
243
246
_wifi_strncpy (reinterpret_cast <char *>(conf.sta .password ), passphrase, 64 );
244
247
}
245
248
246
- if (channel == 0 ) {
247
- // If no specific channel specified, then do an slower WIFI_ALL_CHANNEL_SCAN
248
- wifi_sta_config (&conf, ssid, passphrase, bssid, channel, WIFI_ALL_CHANNEL_SCAN);
249
- }
250
- else
251
- wifi_sta_config (&conf, ssid, passphrase, bssid, channel, WIFI_FAST_SCAN);
249
+ wifi_sta_config (&conf, ssid, passphrase, bssid, channel, _minSecurity, _scanMethod, _sortMethod);
252
250
253
251
wifi_config_t current_conf;
254
252
if (esp_wifi_get_config ((wifi_interface_t )ESP_IF_WIFI_STA, ¤t_conf) != ESP_OK){
@@ -404,6 +402,37 @@ bool WiFiSTAClass::isConnected()
404
402
return (status () == WL_CONNECTED);
405
403
}
406
404
405
+ /* *
406
+ * Set the minimum security for AP to be considered connectable
407
+ * Must be called before WiFi.begin()
408
+ * @param minSecurity wifi_auth_mode_t
409
+ */
410
+ void WiFiSTAClass::setMinSecurity (wifi_auth_mode_t minSecurity)
411
+ {
412
+ _minSecurity = minSecurity;
413
+ }
414
+
415
+ /* *
416
+ * Set the way that AP is chosen.
417
+ * First SSID match[WIFI_FAST_SCAN] or Sorted[WIFI_ALL_CHANNEL_SCAN] (RSSI or Security)
418
+ * Must be called before WiFi.begin()
419
+ * @param scanMethod wifi_scan_method_t
420
+ */
421
+ void WiFiSTAClass::setScanMethod (wifi_scan_method_t scanMethod)
422
+ {
423
+ _scanMethod = scanMethod;
424
+ }
425
+
426
+ /* *
427
+ * Set the way that AP is sorted. (requires scanMethod WIFI_ALL_CHANNEL_SCAN)
428
+ * By SSID[WIFI_CONNECT_AP_BY_SIGNAL] or Security[WIFI_CONNECT_AP_BY_SECURITY]
429
+ * Must be called before WiFi.begin()
430
+ * @param sortMethod wifi_sort_method_t
431
+ */
432
+ void WiFiSTAClass::setSortMethod (wifi_sort_method_t sortMethod)
433
+ {
434
+ _sortMethod = sortMethod;
435
+ }
407
436
408
437
/* *
409
438
* Setting the ESP32 station to connect to the AP (which is recorded)
0 commit comments