scanning after AP disappears -- errors: Now is connecting, user scan invalid now!

jimbob
Posts: 29
Joined: Fri Aug 05, 2016 10:47 pm

scanning after AP disappears -- errors: Now is connecting, user scan invalid now!

Postby jimbob » Tue Oct 09, 2018 2:42 pm

I'm trying to write some robust code that looks for another access point when the current one disappears.

So far (in pseudocode) I do

Code: Select all

esp_wifi_set_config(...)
esp_wifi_connect()
//AP I'm trying to connect to isn't available...
//I wait until I see the callback for a SYSTEM_EVENT_STA_DISCONNECTED event, then I call 
esp_wifi_scan_start(&scanConf, 0)
However, I get the following message:
wifi: Now is connecting, user scan invalid now!
and the scan never completes (nor do I see another event)

I check the error state of esp_wifi_scan_start(&scanConf, 0) and it returns ESP_OK, even when it fails with the "Now is connecting, user scan invalid now" message.

Looking at the docs I think it describes this in some form:

https://docs.espressif.com/projects/esp ... n-examples
3. The scanning triggered by esp_wifi_start_scan() will not be effective until connection between ESP32 and the AP is established. If ESP32 is scanning and connecting at the same time, ESP32 will abort scanning and return a warning message and error number ESP_ERR_WIFI_STATE. If you want to do reconnection after ESP32 received disconnect event, remember to add the maximum retry time, otherwise the called scan will not work. This is especially true when the AP doesn’t exist, and you still try reconnection after ESP32 received disconnect event with the reason code WIFI_REASON_NO_AP_FOUND.
Could someone clarify what it's saying -- I don't intend to scan while still connecting; I'm assuming I can't rely on the Disconnect event to wait for this to complete?
If I can't rely on the Disconnect event, is there a way to detect that the scan will fail before requesting it? And if not, what is the maximum retry time I need to wait -- and do I always have to wait that long after receiving a Disconnect event before scanning.

Additionally, is there an event I can watch for when a scan fails?

Basically I'm doing this as the customer wants the device to be online as much as fast as possible, and so I'm keen to try and find an alternate AP and reconnect as soon as possible when one goes down.
Thanks

chrismerck
Posts: 73
Joined: Tue May 29, 2018 8:00 pm

Re: scanning after AP disappears -- errors: Now is connecting, user scan invalid now!

Postby chrismerck » Tue Nov 20, 2018 12:37 pm

Hi Jimbob,

For what it's worth, I've run into the same issue.

Our solution was to set a timeout, after which we will cancel the connecting state by reconfiguring WiFi in (AP)STA mode with blank ssid. Then a scan can succeed again. It's a sloppy and somewhat slow state-machine based on timeouts, but it works.

frazan-un
Posts: 2
Joined: Wed Apr 03, 2019 10:07 am

Re: scanning after AP disappears -- errors: Now is connecting, user scan invalid now!

Postby frazan-un » Wed May 08, 2019 9:02 am

Hi,
I resolved calling an esp_wifi_disconnect() before the scan in order to terminate completely the previous connection.
Bye

Who is online

Users browsing this forum: No registered users and 126 guests