System semi_automatic mode question

argon
xenon
boron
Tags: #<Tag:0x00007f1ca1565058> #<Tag:0x00007f1ca1564ef0> #<Tag:0x00007f1ca1564d10>

#1

Consider me a newbie. I want my application code to begin to run as soon as power is applied to my device (…either a xenon, boron, or an argon). I do not want the application code to wait until it has communications established with the cloud or network before it begins to execute. I plan to implement the connection to the cloud in automatic mode later on. A few questions regarding the semi_automatic mode:

  1. Do I need the following code for the device to connect to the cloud (or network) when I bring D1 to ground through a momentary button or will the device automatically begin to connect to the cloud (or network) as soon as the button is pressed without the code below?

    if(connectToCloud && Particle.connected() == false) {
    Particle.connect();
    connectToCloud = false;
    }
    void connect() {
    connectToCloud = true;
    }

  2. I have pin D1 connected to a sensor for i2c communications. Will the use of a momentary (normally open) push button to ground potentially cause any hardware issues? The reason I ask is that the device may be communicating (i2c) with the sensor when I press the button. Of course it would stop the scl signal momentarily, but that would be ok with me as long as it would not hurt the device.

  3. If in semi_automatic mode and if I want to update my application code, I assume I would have to press the D1 button to get the device connected to the cloud (or network) or else load new code through the dfu mode. Will both of these methods work for updating code in semi_automatic mode?

  4. Are there any other issues I need to be warned about before I try to use the semi_automatic mode?


#2

As a newbie I can see that to understand exactly how the cloud comms works with the application is a bit daunting.

SYSTEM_MODE(SEMI_AUTOMATIC);
Allows you to have control over switching on and off cloud/mesh comms.
Good practice is to do the connection from setup() i.e. once but if you intend to switch off and then on the connection to not call Particle.connect(); more than once. It is a good idea to wait for the connection to happen or not using waitFor(Particle.connected, timeout); Thereafter, it is automatic, unless you want to disconnect.

I would suggest you also want to include SYSTEM_THREAD(ENABLED);

When using SYSTEM_THREAD(ENABLED) you must be careful of when you register your variables. At the beginning of setup(), before you do any lengthy operations, delays, or things like waiting for a key press, is best. The reason is that variable and function registrations are only sent up once, about 30 seconds after connecting to the cloud. Calling Particle.variable after the registration information has been sent does not re-send the request and the variable will not work.

The cloud comms works on the system thread but without SYSTEM_THREAD(ENABLED) would block the application thread. With multi-threading the communication on I2C would not get interrupted mid-send - is this your concern?

D0/D1 are the I2C bus pins - I am unclear what you mean by using the D1 button. If you want a user button then I would use and define with pinMode() another pin.