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
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?