Our team is developing a product built around the Photon that should function just as well offline as online. Furthermore, when a network connection is available, it’s important that our application code is never blocked for too long (> a few ms) lest that delay create a visible stutter that would detract from an end user’s experience. Thus, we’re wholly dependent on (and thankful for) the SYSTEM_THREAD feature that was rolled out in 0.4.6 and further stabilized in 0.4.7.
In MANUAL mode with SYSTEM_THREAD enabled, the application code is completely responsible for bringing up and maintaining a Wifi connection. I’ve brought up the question of how best to do this in the past for discussion, so I’m officially beginning one now.
At least for our devices, what we really want is the convenience of automatic mode with the controlled, nonblocking behavior of manual mode with threading enabled. A single call to
Particle.connect() gets us almost everything we need:
- Enter listening mode, if no credentials are present (this can be bypassed by checking credentials manually)
- Connect to network, if credentials are present and router is available
- Connect to cloud, if outside access available
What we don’t have is:
- Some method of detecting connection status and failures for user feedback / debugging - There’s no Particle.connecting(), and cloud-related system events have not been fleshed out yet.
- Full manual control of cloud connectivity - Issue #748 Once a connection is attempted, the system firmware takes over the reins and reconnects and resets as it sees fit.
If these issues get fixed, anyone should be able to attain AUTOMATIC behavior in MANUAL+THREADING mode with simple code like this:
This may not be of much interest to non-organizational users, but it is definitely critical to any application that wants connectivity as a background feature without core functionality being blocked.
I was originally planning to post this state machine flowchart for attaining and maintaining connectivity, but I now think it is completely unnecessary given that
Particle.connect probably has to determine all the same things and conditionally branch in all the same ways to function as advertised. Provided, of course, that it functions as advertised.
Thanks for reading!