Hello. I am working at setting up a basic relay control that leverages a Scheduler, consumed on the hardware side by a Arduino Nano ESP32. I am having an issue with an incorrect offset being applied to the set time, and I am not sure where I am going wrong.
My understanding is that the board will sync with IoT Cloud on start, and set the internal RTC with relevant time information configured on my associated Thing
- so no need to manually set time, offset, daylight changes etc.
Somehow the board is starting up with an initial setting of NZST (UTC +12), then applying a further +12 offset pushing its local time forward again. The end result seems to be that the Scheduler value is being set incorrectly.
Details:
- Scheduler configured for my local timezone
Pacific/Auckland
, currently +12 - Start time set for 2100 local
Expected that this would set the underlying CloudSchedule variable latest value to the same, given that other time values are displayed in local in the UI, however it is shown in UTC:
Having looked at some very similar posts, (in particular: Arduino Cloud Scheduler responding to UTC time instead of Local Time) it makes this seem like an issue with the time and offset configured on device start and sync with IoT Cloud. That issue solution resulted in the patch being merged and the board is different, so I have not tried to use the custom lib that was used there when debugging.
Looking at my Nano ESP32 and logging the times that were at issue in the linked thread, it looks as though the RTC is initially being set with NZST and not UTC, and then once connected and synced with IoT Cloud the (correct) received offset is applied again taking the local time forward to NZST +12 / UTC +24
setup and loop:
void setup() {
Serial.begin(9600);
delay(1500);
// thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(3);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
if(ArduinoCloud.connected()){
Serial.print("Cloud Internal Time: ");
Serial.println(ArduinoCloud.getInternalTime());
Serial.print("Cloud Local Time: ");
Serial.println(ArduinoCloud.getLocalTime());
}
delay(10000);
}
Output - run started 10 Sept, 2248 NZST
Connection to "IOT" failed
Retrying in "4000" milliseconds
Connected to "IOT"
TimeServiceClass::sync Drift: 0 RTC value: 1694342886
Cloud Internal Time: 1694342937
Cloud Local Time: 0
Cloud Internal Time: 1694342947
Cloud Local Time: 0
Cloud Internal Time: 1694342958
Cloud Local Time: 0
ArduinoIoTCloudTCP::handle_WaitDeviceConfig device waiting for valid thing_id
Cloud Internal Time: 1694342968
Cloud Local Time: 0
Cloud Internal Time: 1694342979
Cloud Local Time: 0
Cloud Internal Time: 1694342989
Cloud Local Time: 0
Cloud Internal Time: 1694342999
Cloud Local Time: 0
Connected to Arduino IoT Cloud
Thing ID: QWERTY
Cloud Internal Time: 1694343010
Cloud Local Time: 0
Cloud Internal Time: 1694343020
Cloud Local Time: 0
TimeServiceClass::setTimeZoneData offset: 43200 dst_unitl 1695477600
Cloud Internal Time: 1694343030
Cloud Local Time: 1694386230
If anyone can offer advice, that would be appreciated.