Chapter 4. API Guides
• s1.2: Call esp_wifi_scan_start() to configure the scan. To do so, you can refer to Scan Configuration.
Since this is an all-channel scan, just set the SSID/BSSID/channel to 0.
Wi-Fi Driver’s Internal Scan Phase
• s2.1: The Wi-Fi driver switches to channel 1, in case the scan type is WIFI_SCAN_TYPE_ACTIVE, and
broadcasts a probe request. Otherwise, the Wi-Fi will wait for a beacon from the APs. The Wi-Fi driver will
stay in channel 1 for some time. The dwell time is configured in min/max time, with default value being 120
ms.
• s2.2: The Wi-Fi driver switches to channel 2 and performs the same operation as in step 2.1.
• s2.3: The Wi-Fi driver scans the last channel N, where N is determined by the country code which is configured
in step 1.1.
Scan-Done Event Handling Phase
• s3.1: When all channels are scanned, WIFI_EVENT_SCAN_DONE will arise.
• s3.2: The application’s event callback function notifies the application task that
WIFI_EVENT_SCAN_DONE is received. esp_wifi_scan_get_ap_num() is called to get
the number of APs that have been found in this scan. Then, it allocates enough entries and
calls esp_wifi_scan_get_ap_records() to get the AP records. Please note that the
AP records in the Wi-Fi driver will be freed, once esp_wifi_scan_get_ap_records()
is called. Do not call esp_wifi_scan_get_ap_records() twice for a single scan-done
event. If esp_wifi_scan_get_ap_records() is not called when the scan-done event oc-
curs, the AP records allocated by the Wi-Fi driver will not be freed. So, make sure you call
esp_wifi_scan_get_ap_records(), yet only once.
Scan All APs on All Channels (Background)
Scenario:
The scenario above is an all-channel background scan. Compared to Scan All APs on All Channels (Foreground) , the
difference in the all-channel background scan is that the Wi-Fi driver will scan the back-to-home channel for 30 ms
before it switches to the next channel to give the Wi-Fi connection a chance to transmit/receive data.
Scan for Specific AP on All Channels
Scenario:
This scan is similar to Scan All APs on All Channels (Foreground). The differences are:
• s1.1: In step 1.2, the target AP will be configured to SSID/BSSID.
• s2.1~s2.N: Each time the Wi-Fi driver scans an AP, it will check whether it is a target AP or not. If the scan
is WIFI_FAST_SCAN scan and the target AP is found, then the scan-done event will arise and scanning will
end; otherwise, the scan will continue. Please note that the first scanned channel may not be channel 1, because
the Wi-Fi driver optimizes the scanning sequence.
If there are multiple APs which match the target AP info, for example, if we happen to scan two APs whose
SSID is “ap”. If the scan is WIFI_FAST_SCAN, then only the first scanned “ap”will be found, if the scan
is WIFI_ALL_CHANNEL_SCAN, both “ap”will be found and the station will connect the “ap”according to
the configured strategy, refer to Station Basic Configuration.
You can scan a specific AP, or all of them, in any given channel. These two scenarios are very similar.
Scan in Wi-Fi Connect
When esp_wifi_connect() is called, the Wi-Fi driver will try to scan the configured AP first. The scan in
“Wi-Fi Connect”is the same as Scan for Specific AP On All Channels, except that no scan-done event will be generated
Espressif Systems 1525
Submit Document Feedback
Release v4.4