Quick wifi scan

I have the need to check if a specific AP (SSID) on a specific channel is available. I don’t need to connect to it, just scan. But I need to do this as fast as possible.
I managed to limit the scan to a single channel:

	u8 channel = WLAN_CHANNEL;
	u8 config = PSCAN_ENABLE;

	wifi_on(RTW_MODE_STA);

	wifi_set_pscan_chan(&channel, &config, 1);
	if (wifi_scan_networks_with_ssid(single_scan_result_cb, NULL, 500, WLAN_SSID, strlen(WLAN_SSID)) == RTW_SUCCESS) {
		printf("Network found");
	};

	wifi_off();

I put the MCU in sleep between checks.
If I use deep sleep, checking for the channel takes more than 500ms, with sleep I can do that in ~400, but this is still quite expensive from a power usage point of view. I need to do this every 30’’ while running from a battery.
I tried to call wifi_on only once (at boot time) and use wifi_rf_on/wifi_rf_off. This saves some time but, unfortunately, fails to detect the network, even when it’s available :frowning:
I see that initialization/deinitialization of wifi takes quite some time (even after I disabled networking).
I also see that the time required for the scan is the same, regardless of wether the AP is available or not.
On a different (and slower) chip I can do the same in ~200ms when the AP is available because the scan is terminated as soon as the required SSID is detected. This helps a lot with power consumption because having the AP in range is the most typical scenario.
Is there a way to speed-up wifi initialization on RTL8720 or RTL8722?
Is there a way to terminate scan as soon as the required SSID is detected?

1 Like

With partial channel scanning set, wifi_scan_networks_with_ssid should already be returning after finding the AP, since it is sending a directed probe packet only on a single channel and listening for the response.

Alternatively, you may want to try setting your own scan event callback, like in wifi_scan(), then shutting off WiFi when the SSID is found, but I am not sure if this will be faster.

wifi_reg_event_handler(WIFI_EVENT_SCAN_RESULT_REPORT, wifi_scan_each_report_hdl, NULL);

Ultimately, this forum is more catered to the general/open source side of the code, and I am unable to see exact details of how lower level code operates. I would suggest you consider an NDA, which would get you in contact with a specialized FAE from whom you can get more detailed information on WiFi / BLE operation.

Thank you for your reply.
I can’t sign an NDA on behalf of my employer, but if you can provide me with some contacts I can then involve my management.

you can refer to this post and send a PM with some company information to get started. After that, an FAE will contact you for further discussion.