Correct way to call Cloud Fucntions when using MANUAL mode with SYSTEM_THREAD(ENABLED) (DeviceOS 1.4.0)

After Particle.connect() it's usually advisable to wait a bit longer that merely five seconds and instead of using delay() a better approach would look like this

  Particle.connect();
  if (waitFor(Particle.connected, 60000)) {
    // connection established within 60 seconds
    // procede
  }
  else {
    // no connection 
    // act appropriatly depending on your use case
  } 

Also Particle.function(), Particle.variable() and Particle.subscribe() can and should be registered as soon as possible - in MANUAL mode that can even be before connecting.

I'd advise agains using that.
PUBLIC is the default when scope is omitted and that may cause unexpected behaviour effects if someone should happen to send an event of the same name. Even chosing an "obscure" event name won't help since anybody could subscribe to the public event stream and catch your chosen name in order to generate bogus events.

An explicit Particle.syncTime() should not be required since a fresh connection implicitly triggers a resync anyhow.
Also there is Time.isValid() which can/should be used instead of an arbitrary date check.

2 Likes