I think that there is a bug with the Arduino IOT Cloud Scheduler widget not syncing after board restart. When the board and dashboard scheduler widget are both true, disconnect power to the board, reconnect board power. Now the board variable is false. The board and cloud are out of sync.
Here is a simple sketch connected to a dashboard with a switch widget and a scheduler widget.
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/09de5b68-998a-4200-a40a-ba7d32a2026e
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
CloudSchedule mySchedule;
bool mySwitch;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
}
void onMySwitchChange() {
if (mySwitch) {
Serial.print("MySwitch state is ");
Serial.println("true");
} else {
Serial.print("MySwitch state is ");
Serial.println("false");
}
}
void onMyScheduleChange() {
if (mySchedule.isActive()) {
Serial.print("MySchedule state is ");
Serial.println("true");
} else {
Serial.print("MySchedule state is ");
Serial.println("false");
}
}
- I set the dashboard widgets to false (switch off and no active schedule), then boot to nano. In the serial monitor (below I get the boot messages and widgets showing as false (correctly). Then you can see that I have tried changing the widgets a couple of times and left them BOTH as true. I disconnected power to the nano, then plugged it in again. (Without changing anything on the dashboard). You can see the boot messages followed by widget states which are switch true (correct) and scheduler false (incorrect).
- In this (related) post A variable that updates on change and periodically? - #6 by ubidefeo , ubidefeo from the Arduino team states that "despite the property update being "on change", at every successful connection between IoT Cloud and your board there is a "Sync" event which syncs your board's variable with the Cloud property".
So restart sync works for the switch widget but not for scheduler.
Board is Arduino nano 33 IOT
***** Arduino IoT Cloud - configuration info *****
Device ID: 30786b15-d67f-49ad-9769-8a84c518096d
MQTT Broker: mqtts-sa.iot.arduino.cc:8883
WiFi.status(): 0
Current WiFi Firmware: 1.4.4
Connected to "WiFi_OliveNet-429C9D"
Connected to Arduino IoT Cloud
Thing ID: 09de5b68-998a-4200-a40a-ba7d32a2026e
MySchedule state is false
MySwitch state is false
MySwitch state is true
MySchedule state is false
MySchedule state is true
***** Arduino IoT Cloud - configuration info *****
Device ID: 30786b15-d67f-49ad-9769-8a84c518096d
MQTT Broker: mqtts-sa.iot.arduino.cc:8883
WiFi.status(): 0
Current WiFi Firmware: 1.4.4
Connected to "WiFi_OliveNet-429C9D"
ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect to mqtts-sa.iot.arduino.cc:8883
ArduinoIoTCloudTCP::handle_ConnectMqttBroker 1 connection attempt at tick time 14668
Connected to Arduino IoT Cloud
Thing ID: 09de5b68-998a-4200-a40a-ba7d32a2026e
MySchedule state is false
MySwitch state is true