Achieving acceptable functionality (wrt Cloud blocking / reconnection)

Particle.publish is likely the source of most of your blocking issues in SYSTEM_THREAD(ENABLED) mode.

There are a number of techniques in that post of things you can do to mitigate the blocking.

However, in order to make the most responsive UI, I'd handle that from a thread, with a few caveats:

  • If you use a shared resource like I2C or SPI, you can use it from a thread, but you need to either never use it from the main thread, or add guards to prevent both your thread and the loop thread from using it at the same time.
  • Serial is fine from a thread.
  • Do not make any Particle calls from your UI thread, otherwise you'll be back into the situation where blocking occurs,

This post explains some more of the caveats of using threads:

With system thread enabled your thread should run almost perfectly at 1000 times per second, even when connecting to the cloud at the same time.

There are a few situations in 0.7.0 where the networking code blocks. These should be fixed in 0.8.0 which should be released soon.

2 Likes