Great stuff. If you compile my code you’ll observe that the last publish statements in the setup block don’t actually publish. I did the hacky subscribe / publish in the loop because it seems cloud registration timing and reliability has changed. Our beta code using 1.4.x firmware stopped reliably connecting / publish / subscribe.
While other more rounded examples will certainly help the community, selfishly I’d really love honing in on the core process of wifi connection / cloud connection / subscribe / publish. That behaviour has changed dramatically since 1.1.x with how Particle.connect now needs wifi.connect, and I presume the recent cloud registration issues are due to timing and changes to the backend.
The code I provided is quite stripped down, it has some necessary weight due to test functions but aside from that is quite minimal.
Juggling the sections around to your recommendations or adding recommended recovery / watchdog / waitfor logic should be pretty easy I hope!
For customer context, I’m currently held up by 3 weeks, waiting to release firmware features to my customers after observing the subscribe / publish cloud issues. If they don’t reliably work then we’ll have devices that don’t retrieve their configuration or listen to configurations actively sent to them.