Arduino IoT Cloud Scheduler sample - set time zone and getLocalTime() not in sync

Question on the Cloud Scheduler and Time widget behavior:

I have an Opla IoT Kit (w/ MKR Wifi 1010) trying out the Cloud Scheduler example in this article on Arduino IoT Cloud environment. My location is Japan (UTC +9) and set time zone at bottom right in the Thing page to "Asia/Tokyo".

After uploading the sample sketch and looking in the Dashboard, the Time widget shows "Asia/Tokyo" but the value of getLocalTime() seems to be off by 9 hours more from my location time which is UTC +9.

  if(ArduinoCloud.connected()){
     time_read = ArduinoCloud.getLocalTime();
  }

i tried adding two more variables - one to hold getLocalTime() - 32400 seconds, another using getInternalTime() - to compare with this code and the resulting screenshot:

    if(ArduinoCloud.connected()){
       time_read = ArduinoCloud.getLocalTime();
       Serial.print("time_read =");
       Serial.println(time_read);
       
       time_read_offset = ArduinoCloud.getLocalTime() - 32400; // -9 hrs in secs
       Serial.print("time_read_offset =");
       Serial.println(time_read_offset);
       
       sys_time = ArduinoCloud.getInternalTime();
       Serial.print("sys_time =");
       Serial.println(sys_time);
    }

Counter variable is working, meaning the scheduler runs at the set time, but the Time widget (getLocalTime) is displaying the wrong time.

I tried to set Thing time zone to UTC +0 (London) but then the counter variable wasn't working right anymore, maybe because the time variable (in UTC +9) and scheduler (in UTC +0) were off by 9 hours, as in the screenshot here.

My question is: is the article's sample sketch and explanation working correctly as-is and I missed a step, or is the workaround (offset by -9 hrs or use getSystemTime()) correct? Thanks for reading this and appreciate your tip(s)!

Hi @ebto,
from your description it looks like the board InternalTime is not the UTC time, but your actual LocalTime and this is not correct. Your workaround, despite the fact it makes things working , should not be necessary.

I've tried to setup the same example, but i cannot replicate your condition and things seems to work correctly for me.

Could you provide us more details, maybe share the complete sketch, and the logs with active debug options. To enable full debug logs you need the following changes:

Thanks

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