@@ -83,7 +83,7 @@ static bool sta_config_equal(const wifi_config_t& lhs, const wifi_config_t& rhs)
8383 return  true ;
8484}
8585
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 ){
8787 wifi_config->sta .channel  = channel;
8888 wifi_config->sta .listen_interval  = listen_interval;
8989 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,
9999 if (ssid != NULL  && ssid[0 ] != 0 ){
100100 _wifi_strncpy ((char *)wifi_config->sta .ssid , ssid, 32 );
101101 if (password != NULL  && password[0 ] != 0 ){
102- 	wifi_config->sta .threshold .authmode  = WIFI_AUTH_WPA2_PSK ;
102+ 	wifi_config->sta .threshold .authmode  = min_security ;
103103 _wifi_strncpy ((char *)wifi_config->sta .password , password, 64 );
104104	}
105105 if (bssid != NULL ){
@@ -115,6 +115,9 @@ static void wifi_sta_config(wifi_config_t * wifi_config, const char * ssid=NULL,
115115
116116bool  WiFiSTAClass::_autoReconnect = true ;
117117bool  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;
118121
119122static  wl_status_t  _sta_status = WL_NO_SHIELD;
120123static  EventGroupHandle_t _sta_status_group = NULL ;
@@ -243,12 +246,7 @@ wl_status_t WiFiSTAClass::begin(const char* ssid, const char *passphrase, int32_
243246 _wifi_strncpy (reinterpret_cast <char *>(conf.sta .password ), passphrase, 64 );
244247 }
245248
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);
252250
253251 wifi_config_t  current_conf;
254252 if (esp_wifi_get_config ((wifi_interface_t )ESP_IF_WIFI_STA, ¤t_conf) != ESP_OK){
@@ -404,6 +402,37 @@ bool WiFiSTAClass::isConnected()
404402 return  (status () == WL_CONNECTED);
405403}
406404
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+ }
407436
408437/* *
409438 * Setting the ESP32 station to connect to the AP (which is recorded) 
0 commit comments