ESP32: rescanning wifi after reconfigure

#1

My goal is to scan the wifi, present the list of ssids discovered to user, let them select one, and configure the wifi to communicate with that wireless network. My apps is ESP32 based.

Right now, mgos_scan_wifi() is working. To reconfigure the wifi, I disable it with mgos_wifi_disconnect, then call mgos_wifi_setup with a filled in mgos_config_wifi structure. This works fine; I can see the disconnect happen, along with the reconnect to the new AP.

But after I do this once, mgos_scan_wifi() appears to stop working; the callback never gets called again.

mgos_scan_wifi() works fine if called multiple times if I do NOT do the mgos_wifi_disconnect()/mgos_wifi_setup() between.

How can I reconfigure wifi and keep mgos_scan_wifi() working without an intervening reboot (which would be an ugly experience for my users)?

#2

Also, I see this the first time I try to rescan after a reconfigure.

[Apr 22 16:09:34.300] W (205246) wifi: Now is connecting, user scan invalid now!

…but the connection to the new AP is connected and working, not in the progress of conning…