Read Variables Before Reset

When the board connects to the cloud it always gets the latest cloud value automatically! So you don't generally need to store it locally. This is very convenient.

However, you should know a few things:

  • There's a delay between the time your board starts running and the cloud connection is established. This means that before reading/using the variable you need to make sure it was synced from the cloud. You can do it like this:
void setup() {
   ...
   ArduinoCloud.addCallback(ArduinoIoTCloudEvent::SYNC, onSync);
   ...
}

void onSync() {
   // Connection to the cloud was established and variables were synced!
   // Now you can read and use them.
}
  • This of course relies on Internet connectivity. If your board reboots and there's no connection to the cloud, your program will need to wait until connection comes back again. In that case, you might want to store your data locally in flash memory or an SD card.
1 Like