Scheduler isn't valid when using Time zone
BlastCom opened this issue · comments
Here's a normal usage, but the LED was expected to turn ON and the value to increase.
Checked variable info. It states that the task should have started 4 hours later than expected.
So I removed 4 hours from my starting time and it worked
I did some output manipulation to understand what's happening (Starting time was set at 15:37 (GMT-4) and current time was 9:26 (GMT-4)) :
void loop() {
ArduinoCloud.update();
// Your code here
if (schedule_test.isActive()) {
light = true;
digitalWrite(LED, HIGH);
if (toggle) {
counter = ++counter;
toggle = false;
}
} else {
light = false;
digitalWrite(LED, LOW);
toggle = true;
}
if(ArduinoCloud.connected()){
time_read = ArduinoCloud.getLocalTime();
}
gettimeofday(¤t_time, NULL);
Serial.print("RTC seconds : ");
Serial.println(current_time.tv_sec, DEC);
Serial.print("TimeService.getRTC : ");
Serial.println(time(NULL), DEC);
Serial.print("TimeService.getTime (UTC) value : ");
Serial.println((unsigned int)TimeService.getTime(), DEC);
Serial.print("TimeService.getLocalTime value : ");
Serial.println((unsigned int)TimeService.getLocalTime(), DEC);
Serial.print("frm value : ");
Serial.println((unsigned int)schedule_test.getCloudValue().frm, DEC);
delay(1000);
}
RTC seconds : 1696425985
TimeService.getRTC : 1696425985
TimeService.getTime (UTC) value : 1696425985
TimeService.getLocalTime value : 1696411585
frm value : 1696361220
TimeService.getTime (UTC) value : 1696425985 (October 4, 2023 1:26:25 PM)
TimeService.getLocalTime value : 1696411585 (October 4, 2023 9:26:25 AM)
frm value -> That means FRM is set as GMT or UTC TIME.
GMT: Tuesday, October 3, 2023 7:27:00 PM
Your time zone: Tuesday, October 3, 2023 3:27:00 PM GMT-04:00 DST
But in ArduinoIoTCloud\src\property\types\CloudSchedule.h line 118, it compare the time with LOCAL time.
That means either isActive()
should compare in UTC time instead of local or the ArduinoCloud Schedule initialization should be initialized with local time instead UTC.
[Edit] What appears in the variable info, seems to get the local time then converting it to GMT. It uses that GMT time to compare with the local time. It looks like some Cloud integration problem.
Related
https://forum.arduino.cc/t/cloud-scheduler-using-utc-even-though-timezone-set/1170088
I'm using an ESP32 Dev Module with a mounted ESP32-WROOM-32
Hi @BlastCom,
the ArduinoCloud Schedule initialization should be initialized with local time instead UTC
This is how it should work, the library expect a localtime value and the fix has to be released cloud side. This forum thread is also related https://forum.arduino.cc/t/scheduler-nano-esp32-time-and-zone-settings/1167084/11
Hi @pennam,
It's great that you succeed to replicate the issue as I saw in the thread.
I'll keep myself updated on this issue.
@pennam I temporally modified the library to use getTime() instead of getLocalTime() and it works.
I know it's a bandage more than a fix but I can now tackle another task in the meantime.
Closing as off topic since the bug is not in the codebase hosted in this repository.