WiFi connection flow with SoftAP

I’m thinking on a WiFi connection flow. I would like my product (led installation that has an animation running, that shouldn’t stop) to work independent of what the state of the WiFi connection is. Right now I use a timer to run a fixedLoop (outside the main loop().

The idea is that if there are no credentials or that if the wifi dissappeared for a while, I switch to the SoftAP (listen mode). Nonetheless, I want to retry every x seconds to connect (maybe the WiFi network with credentials will show up again). Based on some EEPROM flags I might be able to override some things (for example always chose SoftAP or just turn WiFi Off).

Below a flow I have in mind.

Let’s assume I don’t want only WiFi direct so I go to the connecting to wifi state.

Is it possible to switch to SoftAP mode (with HTTP interface) after a let say 30 seconds (when ready() is still false)? Because in the current example (https://docs.particle.io/reference/firmware/photon/#softap-http-pages) it seems to run in the startup.

Is it possible that while in SoftAP mode, I sometimes reconnect to see if I can find the WiFi? Is that done with WiFi.listen(false);?

What about this listening() it mentions that is only useful when system code runs as a separate RTOS task from application code. We estimate that firmware feature will be released for the Photon in September 2015. Is this already implemented? (https://docs.particle.io/reference/firmware/photon/#listening-)

Is this flow doable, or is there an easier way to do it?

This is implemented already and activated via SYSTEM_THREAD(ENABLED)

WiFi.listen(false) should stop SoftAP too.

And in order to check if you’ve got a WiFi with known credentials in reach you won’t need to attempt a connection and maybe “stall” your animation, but you could use WiFi.scan() and check against the stored networks retrieved via WiFi.getCredentials(). Since I think scanning is less intrusive than a connection attempt.

You can call WiFi.listen() anytime, not only in setup(), just hooking up the “callback” needs to be done beforehand.

Thanks for the clear advice. I’ll try to code and test it the upcoming days. I’ll post the code here as an example.

1 Like

I’m testing what happens if a WiFi network is not found while I’ve put in the correct creditials, but the network is offline (use case: router temporary unplugged).

Why does WiFi.hasCredentials pause for about 21 seconds? What is going on
in the background? Not calling hasCredentials doesn’t stop the loop.

This only happens when WiFi.connect() is called before (which doesn’t influence the WiFi.connecting() flag directly it seems).

These would be questions I’d rather leave for @mdma to answer :wink:

@mdma: Is this expected behavior, our should I file an issue in Github?

WiFi.hasCredentials() is a synchronous function - please see https://docs.particle.io/reference/firmware/photon/#system-thread. So, if the system is busy attempting to connect to WiFi (which can take 21 seconds before timing out) then the call will block waiting for the system to respond.

1 Like

I’m wondering some things right now reading all the documentation, forum posts and thinking in a correct flow.

I know that when I enter a wrong password it will keep trying to connect (green blink). Is there an explicit way to find that this is caused by a wrong password? My current method to find this out is to do a scan to check if the AP is available (with sufficient strength) and to conclude that if it stays connecting for a certain time, the password probably is wrong.

Would it be possible to see in listen mode if someone is currently on a page. I know I can check if the page is opened. But can I see if the connecting is active? I might be able to play around with a meta-refresh every n seconds, to find this out otherwise.

Would it be possible that when I enter any url in the browser, it will always reconnect to my softap page. Right now you have to enter the ip address at least. However there are systems (I know it from the WiFi onboard on a train) that redirect any url to a fixed destination.

When can I expect WiFi.rssi to give a 1 (wifi chip error) and a 2 time-out error?

Hereby the implementation of my WiFi Manager. I don’t implemented it exactly like the given flowchart above. I’ve decided to not implement the WiFi off or only WiFi direct flag (actually when you remove all credentials, you stay in the listen mode).


I’m still working on a “button-less” WiFi setup. So in my Wifimanager code (used in Manual mode), the Particle Photon will go to direct-mode when it can’t connect to any of the stored WiFi networks.

I’ve programmed a time-out, so after a certain time-out it will try to reconnect to the network.

However the problem is that the time-out happens also when I’m connected with the Photon in Direct Mode to set credentials in the SoftAP.

Is there a way to detect that an device is connected with the SoftAP? So if that’s the case I can reset the reconnect timer.

@avtolstoy @BDub Any idea’s? Or could this feature be implemented?