Boron when does user program start

With the Boron in Automatic connection mode, does the user program's setup and loop functions start running immediately, or only after connecting to the cloud? I have a system that needs to perform some work when the cloud is not available, and opportunistically send data to the cloud when available. What is the right way to do this?

Hi,
The right way to do this is by adding this in the global space - outside of setup() and outside of loop():

SYSTEM_THREAD(ENABLED);

Of interest:

System threading behavior

When the system thread is enabled, application execution changes compared to non-threaded execution:

  • setup() is executed immediately regardless of the system mode, which means setup typically executes before the Network or Cloud is connected. Particle.function(), Particle.variable() and Particle.subscribe() will function as intended whether the cloud is connected or not.
  • After setup() is called, loop() is called repeatedly, independent from the current state of the network or cloud connection. The system does not block loop() waiting for the network or cloud to be available, nor while connecting to Wi-Fi.

Cheers,

3 Likes

Just be sure you do this outside of setup() and outside of loop() as instructed above. If you do this inside setup() you will temporarily brick the device and require re-flashing via CLI. Don't ask me how I know.

1 Like