Chapter 4. API Guides
when the scan is completed. If the target AP is found, the Wi-Fi driver will start the Wi-Fi connection; otherwise,
WIFI_EVENT_STA_DISCONNECTED will be generated. Refer to Scan for Specific AP On All Channels.
Scan In Blocked Mode
If the block parameter of esp_wifi_scan_start() is true, then the scan is a blocked one, and the application
task will be blocked until the scan is done. The blocked scan is similar to an unblocked one, except that no scan-done
event will arise when the blocked scan is completed.
Parallel Scan
Two application tasks may call esp_wifi_scan_start() at the same time, or the same application task calls
esp_wifi_scan_start() before it gets a scan-done event. Both scenarios can happen. However, the Wi-
Fi driver does not support multiple concurrent scans adequately. As a result, concurrent scans should be
avoided. Support for concurrent scan will be enhanced in future releases, as the ESP32-S2’s Wi-Fi functionality
improves continuously.
Scan When Wi-Fi is Connecting
The esp_wifi_scan_start() fails immediately if the Wi-Fi is in connecting process because the connecting
has higher priority than the scan. If scan fails because of connecting, the recommended strategy is to delay sometime
and retry scan again, the scan will succeed once the connecting is completed.
However, the retry/delay strategy may not work all the time. Considering following scenario:
• The station is connecting a non-existed AP or if the station connects the existed AP with a wrong password, it
always raises the event WIFI_EVENT_STA_DISCONNECTED.
• The application call esp_wifi_connect() to do reconnection on receiving the disconnect event.
• Another application task, e.g. the console task, call esp_wifi_scan_start() to do scan, the scan always
fails immediately because the station is keeping connecting.
• When scan fails, the application simply delay sometime and retry the scan.
In above scenario the scan will never succeed because the connecting is in process. So if the application supports
similar scenario, it needs to implement a better reconnect strategy. E.g.
• The application can choose to define a maximum continuous reconnect counter, stop reconnect once the re-
connect reaches the max counter.
• The application can choose to do reconnect immediately in the first N continous reconnect, then give a delay
sometime and reconnect again.
The application can define its own reconnect strategy to avoid the scan starve to death. Refer to <Wi-Fi Reconnect>.
4.33.10 ESP32-S2 Wi-Fi Station Connecting Scenario
This scenario only depicts the case when there is only one target AP are found in scan phase, for the scenario that
more than one AP with the same SSID are found, refer to ESP32-S2 Wi-Fi Station Connecting When Multiple APs
Are Found.
Generally, the application does not need to care about the connecting process. Below is a brief introduction to the
process for those who are really interested.
Scenario:
Scan Phase
• s1.1, The Wi-Fi driver begins scanning in“Wi-Fi Connect”. Refer to Scan in Wi-Fi Connect for more details.
• s1.2, If the scan fails to find the target AP, WIFI_EVENT_STA_DISCONNECTED will arise and the reason-code
will be WIFI_REASON_NO_AP_FOUND. Refer to Wi-Fi Reason Code.
Espressif Systems 1528
Submit Document Feedback
Release v4.4