System Threading and Particle.connect()

Hello everyone!

I’m making an intrusion alarm system on my Particle Photon. My problem is that the Photon won’t be able to read sensors while it is connecting and I’m trying to avoid that.

Now, I initially though about using a hardware interrupt that checks the sensors and sends a disconnect() in case the state of a pin the sensor is connected to changes (because, according to the reference, “This connection will block execution of loop() or setup() until either the device connects to the Cloud or an interrupt is fired that calls Particle.disconnect().”, at least when in semi-auto mode).

A couple of days ago I found out about System Threading and the SYSTEM_THREAD(ENABLED); function.
Reference does mention SOME functions are executed on other thread but does not mention anything about the connection process.

What I’m wondering is: will connection still block code in the loop() function? Do I just stick to hardware interrupts and the disconnect() method?

Thank you!

The connection process and most system agenda will be running on the independent thread.

You will see some latency in your own code while the system is connecting but your loop() won’t be blocked.


That sounds great, thanks for the answer.

One thing I do not understand is why it is not like that by default, unless there are some disadvantages to this I’m not noticing (could very well be).

I’m not sure if there are other reasons too, but multi threading was only intruduced a considerable while after the first devices went on the shelves and hence the previous “lack” of the feature had set the defacto standard.

Also since this calls for slightly different setup of your program, all the docs, samples and tutorials published before the arrival of multi threading would have needed to be revisited to cater for this change.

1 Like

That makes sense, thanks for explaining! :slight_smile:

1 Like