Trying to figure out what the best practice is for calling Wifi.scan in order to a) have it return as quickly as possible b) deal with it in case it doesn’t return quickly (in terms of not crashing). It seems to me when I run “particle setup” from the CLI that scanning takes about 3-4 seconds, however depending on what state the WiFi is actively in, it could take anywhere from 1/2 a second to 20 seconds to return when I call it for my application code. A couple notes and observations:
Notes:
- I’m in SYSTEM_MODE(MANUAL) and SYSTEM_THREAD(ENABLED)
Observations:
- If I call WiFi.scan() when WiFI is on but before it connects to Particle then it returns quickly (< 1 second?)
- If I call WiFi.scan() when Particle is connected to the cloud it can take me 20+ seconds to return an my app crashes
- If I call WiFi.scan() when Particle was connected and I call Particle.disconnect() right before scanning it behaves the same as if connected, long return time, crashes my app (error code Hard fault)
I understand I may be doing somethings wrong here but that’s why I’m asking
Questions:
- Is there a state I should make sure that my system is in before I call WiFi.scan in order to get it to return the quickest?
- Is there any particular reason that if it doesn’t return after 10-20 seconds my app would crash?
- What can I do to improve my situation here?