[SOLVED ]Doing useful work while connecting

Hi people,

my question is hopefully a simple one; with the cellular Electron board I am trying to figure out if / how it is possible to process things (or read sensor data) also when trying to connect to the cellular.

In my case it is not very important when exactly the data gets sent to the cloud. So I can try on best-effort basis, say, hourly. If connection succeeds then fine, lets send some data. If not, then lets try again later.

The issue I have is that I would need to be able to remain functional also during the connection attempt. At the moment all measurements and processing go to a halt for unknown amount of time (= the period of connecting which can be quite long especially if unsuccessful), and we lose data / processing from that period.

thoughts? Is this possible?

Have you seen the system threads feature yet :)?

Thanks Moors7. Yes I’ve noticed it. I tried enabling it (and semi-automatic mode). But even doing so calling Particle.connect() in loop() will block the loop() execution (maybe works differently for WiFi?). Or am I perhaps misunderstanding the meaning of the SYSTEM_THREAD and how it works?

How does your code look?
One common mistake is to retrigger Particle.connect() while a previous connection attempt is still running, tripping the previous attempt and stalling your own code frequently.
The actual connection process should not halt your code while it’s running in SEMI_AUTOMATIC and multi threaded mode, but the initiation of it might cause short “interruptions”.

What kind of data are you reading and how?
If you have time critical reads to do you could use interrupt driven timers, but you’d be limited to read actions that can be run from an ISR.

1 Like

ScruffR could be that you pointed me to the smoking gun, several connect() calls before completing previous ones. I’m away from code until tomorrow but I’ll check, experiment and get back with the results! (About the data reading details, its still in the works as I’m currently mapping out accelerometer options).

Yes indeed! Thank you very much. There was a flaw in logic that caused Particle.connect() to be called frequently, and the behaviour looked like blocking.


Thank you for helping them out @Moors7 and @ScruffR!