Skip to content

Commit f5b04b9

Browse files
authored
Use WIFI_FAST_SCAN if a specific channel was used (#5975)
1.0.6 changed scanning method to always scan all available channels during connect. This results in results in connect taking about ~3 seconds instead of ~1. This patch changes the behavior to use WIFI_FAST_SCAN if client used a specific channel.
1 parent 8c5d18d commit f5b04b9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Diff for: libraries/WiFi/src/WiFiSTA.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,19 @@ wl_status_t WiFiSTAClass::begin(const char* ssid, const char *passphrase, int32_
176176
wifi_config_t conf;
177177
memset(&conf, 0, sizeof(wifi_config_t));
178178
_wifi_strncpy(reinterpret_cast<char*>(conf.sta.ssid), ssid, 32);
179-
conf.sta.scan_method = WIFI_ALL_CHANNEL_SCAN; //force full scan to be able to choose the nearest / strongest AP
180179

181180
if(passphrase) {
182181
_wifi_strncpy(reinterpret_cast<char*>(conf.sta.password), passphrase, 64);
183182
}
184183

185-
wifi_config_t current_conf;
186-
wifi_sta_config(&conf, ssid, passphrase, bssid, channel);
184+
if(channel == 0) {
185+
// If no specific channel specified, then do an slower WIFI_ALL_CHANNEL_SCAN
186+
wifi_sta_config(&conf, ssid, passphrase, bssid, channel, WIFI_ALL_CHANNEL_SCAN);
187+
}
188+
else
189+
wifi_sta_config(&conf, ssid, passphrase, bssid, channel, WIFI_FAST_SCAN);
187190

191+
wifi_config_t current_conf;
188192
if(esp_wifi_get_config((wifi_interface_t)ESP_IF_WIFI_STA, &current_conf) != ESP_OK){
189193
log_e("get current config failed!");
190194
return WL_CONNECT_FAILED;

0 commit comments

Comments
 (0)