WiFi.scan() only returns result when connected to a network

This is to toggle the set up done flag so that I automatically do not go into listening mode. This is because I did not set up my Argon using the mobile app, just by USB. Sources:

This only really needs to be done once but I left it there. It does not impact the functionality once the flag is toggled.

I guess this is my problem. I assume scanning would be working when flashing green. I had assume similar characteristics like a mobile phone (bad comparison I know) where you can still scan and see availble networks even though you have credentials saved and trying to connect to known wifi networks (or that they just made it seemless to the end user and automatically toggled scan and connecting states). Maybe this is a typical characteristic when dealing with WiFi at this level? If there are doc's describing this I would appreciate it, so far I'm running off just https://docs.particle.io/reference/device-os/firmware/argon/#scan-

Anyway, thanks to @ScruffR 's code above, it seems that this characteristic apparently widely known since he intentionally does a waitUntil(WiFi.ready); before scanning again. To resolve this issue, I did something similar to his code where I do a if (!WiFi.ready()) { WiFi.disconnect() }before a WiFi.scan(). After the WiFi.scan() I go back to WiFi.connect() again. The scan does have a delay but for my scenario I think its acceptable.

This is helpful, thanks for the information on WICED. I will definately look this up. Its good to always know more about why you are not connecting and probably feed this back to the end user.

1 Like