Powerloss/reboot change cloud variable state

Hi, I'm trying to understand the behavior when the hardware is reset by a power loss/reboot and last state of cloud variables.

Does the cloud variables sync and basically leaves off where it was before reset?

Is there a way to change a cloud boolean to true or false before the loop runs?

Hi!

By default the behaviour is the following. When the device connects to the Cloud, it receives the latest variable value stored in the Cloud of the RW variables. So, any local changes applied to a Cloud variable locally in your sketch will be overridden as soon as the device connects to the Cloud.

If you want to change this behaviour, you can leverage event callbacks. You can register a function that it is called when the SYNC event is triggered. In that function you can set the value of the variables. This would effectively mean that you are setting the default value in your sketch and not in the Cloud.

A snippet of code:

void setup() {
   ...
   ArduinoCloud.addCallback(ArduinoIoTCloudEvent::SYNC, onSync);
   ...
}

void onSync() {
  // Set the new (default) values of your Cloud variables
   myInt = 0;
   myBool = false;
}

You can find a very good full example here:

I hope this helps!

Awesome - thank you. I looked all over for behavior and could not find anything like this answer.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.