Controlling electron

I am controlling an engine that turns on only if a sensor measures a range below the allowed. But when the electron is disconnected by problems 3G signal, control is affected. As I can separate the process of sending data to the cloud without affecting the control, if not find 3G signal or delay in connecting?

Yes, this is possible. The easiest way to do this is to enable system threading mode by adding this line of code near the top of your program:

SYSTEM_THREAD(ENABLED);

It is also possible to the SEMI_AUTOMATIC system mode for this purpose.

The reason is that by default (threading off, automatic mode) user code does not run when there is no cloud connection. This makes thing easier because you don’t have to make sure the cloud is connected before doing certain things.

You do not have to worry about Particle.function or Particle.variable; these are designed to work with the cloud not connected yet.

You do have to worry about Particle.publish or Particle.subscribe. You may want to use Particle.connected() to check to see the cloud is up at the time you make the call.

3 Likes