Arduino Cloud Scheduler responding to UTC time instead of Local Time

Hello,

I am using the scheduler feature on an Arduino Cloud dashboard.

Using modified example code...

if (schedule_variable.isActive()) {
// whenever the job is "active", turn on the LED
digitalWrite(LED, HIGH);
} else {
// whenever the job is "not active", turn off the LED
digitalWrite(LED, LOW);

However, I am in New Zealand and when I set the timezone of the thing to our local timezone this code still responds as if the timezone is UTC. (i.e. Exactly 12 hours out from local time)

Some assistance would be greatly appreciated.

M

Hello all,

I am experiencing an issue with Arduino Cloud scheduler widget where although I have my thing’s timezone set to Auckland/Pacific the script ‘is.active’ is responding to a time that is 12 hours wrong. I.e. UTC time.

Using MKR 1500 NB.

Any advice would be greatly appreciated.

M

you can do some calculations, and arriving at the right time is the fastest way!

Thank you for your reply.

The ‘is.active’ script doesn’t bring the time into the code though so how would you do calculations?

I am trying to reduce iot traffic as much as possible so don’t really want to be requesting the time every loop.

The example on the Arduino site says to change the timezone on your thing to use the widget so is this just broken?

Ty

M

int timetochange= TIME; //the hours you need to change

int realtime=timetochange+12;
if(realtime>23){
realtime=realtime-24;
}

I have merged your cross-posts @bigdingo.

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting can result in a suspension from the forum.

In the future, please take some time to pick the forum category that best suits the subject of your question and then only post once to that forum category. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

1 Like

Really? That simple? Tyvm

Hello Pert,

My apologies, I actually posted again because I couldn't find my original post.

Sorry for wasting your time.

M

1 Like

I think so, let me know :slight_smile:

Hi @bigdingo ,
setting setDebugMessageLevel(3); to 3 in your setup function will enable some additional prints in the serial monitor regarding the timezone. If i set my thing timezone to Auckland/pacific i'm receiving this values:

ArduinoIoTCloudTCP::setTimeZoneData tz_offset: [43200]
ArduinoIoTCloudTCP::setTimeZoneData tz_dst_unitl: [1664028000l]

Could you please post the values you are receiving?

Also adding this lines in your loop would help us to understand which values are not correct:

if(ArduinoCloud.connected()){
    Serial.print("UTC Time: ");
    Serial.println(ArduinoCloud.getInternalTime());
    Serial.print("Local Time: ");
    Serial.println(ArduinoCloud.getLocalTime());
    delay(1000);
  }

Remember to write also at what time you are doing the tests in order to check the values.

If you have another board, like a mkrwifi1010, it would be useful to know if you are experiencing the same issue.

Thanks

1 Like

Hello Pennam,

I have my thing set to Pacific/Auckland also...

I am getting these prints from the loop code you posted.

UTC Time: 1653969542
Local Time: 1654012742
UTC Time: 1653969543
Local Time: 1654012743
UTC Time: 1653969544
Local Time: 1654012744
UTC Time: 1653969545
Local Time: 1654012745
UTC Time: 1653969547
Local Time: 1654012747
UTC Time: 1653969548
Local Time: 1654012748
UTC Time: 1653969549
Local Time: 1654012749
UTC Time: 1653969550
Local Time: 1654012750
UTC Time: 1653969551
Local Time: 1654012751
UTC Time: 1653969553
Local Time: 1654012753
UTC Time: 1653969554
Local Time: 1654012754
UTC Time: 1653969555
Local Time: 1654012755
UTC Time: 1653969556
Local Time: 1654012756
UTC Time: 1653969558
Local Time: 1654012758
UTC Time: 1653969559
Local Time: 1654012759
UTC Time: 1653969560
Local Time: 1654012760

This was done at 15:59 Local time.

Best,
M

My Apologies,

This time I caught the other data you requested.

ArduinoIoTCloudTCP::setTimeZoneData tz_offset: [43200]
ArduinoIoTCloudTCP::setTimeZoneData tz_dst_unitl: [1664028000l]
UTC Time: 1653969855
Local Time: 1654013055
UTC Time: 1653969856
Local Time: 1654013056
UTC Time: 1653969857
Local Time: 1654013058
UTC Time: 1653969859
Local Time: 1654013059
UTC Time: 1653969860
Local Time: 1654013060
UTC Time: 1653969861
Local Time: 1654013061
UTC Time: 1653969862
Local Time: 1654013062
UTC Time: 1653969864
Local Time: 1654013064
UTC Time: 1653969865
Local Time: 1654013065
UTC Time: 1653969866
Local Time: 1654013066
UTC Time: 1653969867
Local Time: 1654013067

Hi @bigdingo,
sorry for the late reply. Your timezone data looks correct but UTC Time value is already shifted by +12 hours from GMT. The MKRNB has two ways to retrive the UTC Time value:

  1. From the connection handler -> MKRNB library
  2. From NTP server

I suspect the value retrieved from MKRNB library is wrong. I've created a custom ArduinoIoTCloud library with some additional debug print to try to track the timeshift origin.

You can find the library here. It would be very useful if you could load it as custom library from the web editor and send us the serial monitor log from startup to the loop().

Remember to set debug level to 3 and to write also at what time you are doing the tests in order to check the values.

Thanks

Hi @pennam Pennam,

Thank you very much for this, I have been struggling with another issue that has stopped me from getting a monitor log. (MKR GSM Issue - Keeps crashing - #7 by MartinL)

Anyhow, here you go, test undertaken at 10:45am Local time.

GPRS.attachGPRS(): 4
Connected to GPRS Network
ConnectionHandler::getRemoteTime time: [1654512304l]
ArduinoIoTCloudTCP::handle_SyncTime internal clock configured to posix timestamp 1654512304
UTC Time: 1654512309
Local Time: 0
UTC Time: 1654512310
Local Time: 0
UTC Time: 1654512312
Local Time: 0
UTC Time: 1654512313
Local Time: 0
UTC Time: 1654512314
Local Time: 0
UTC Time: 1654512315
Local Time: 0
UTC Time: 1654512317
Local Time: 0
Connected to Arduino IoT Cloud
Thing ID: fffd94ea-4475-4341-bb57-6c1483f5c63c
UTC Time: 1654512319
Local Time: 0
UTC Time: 1654512320
Local Time: 0
UTC Time: 1654512321
Local Time: 0
UTC Time: 1654512323
Local Time: 0
ArduinoIoTCloudTCP::setTimeZoneData tz_offset: [43200]
ArduinoIoTCloudTCP::setTimeZoneData tz_dst_unitl: [1664028000l]
UTC Time: 1654512324
Local Time: 1654555524
UTC Time: 1654512325
Local Time: 1654555525
UTC Time: 1654512326
Local Time: 1654555526
UTC Time: 1654512327
Local Time: 1654555527
UTC Time: 1654512329
Local Time: 1654555529
UTC Time: 1654512330
Local Time: 1654555530
UTC Time: 1654512331
Local Time: 1654555531
UTC Time: 1654512332
Local Time: 1654555532
UTC Time: 1654512333
Local Time: 1654555533
UTC Time: 1654512335
Local Time: 1654555535
UTC Time: 1654512336
Local Time: 1654555536
UTC Time: 1654512337
Local Time: 1654555537
UTC Time: 1654512338
Local Time: 1654555538
UTC Time: 1654512339
Local Time: 1654555539
UTC Time: 1654512341
Local Time: 1654555541
UTC Time: 1654512342
Local Time: 1654555542
UTC Time: 1654512343
Local Time: 1654555543
UTC Time: 1654512344
Local Time: 1654555544
UTC Time: 1654512345
Local Time: 1654555545
UTC Time: 1654512347
Local Time: 1654555547
UTC Time: 1654512348
Local Time: 1654555548
UTC Time: 1654512349
Local Time: 1654555549
UTC Time: 1654512350
Local Time: 1654555550
UTC Time: 1654512351
Local Time: 1654555551
UTC Time: 1654512353
Local Time: 1654555553
UTC Time: 1654512354
Local Time: 1654555554
UTC Time: 1654512355
Local Time: 1654555555
UTC Time: 1654512357
Local Time: 1654555557
UTC Time: 1654512358
Local Time: 1654555558
UTC Time: 1654512359
Local Time: 1654555559
UTC Time: 1654512360
Local Time: 1654555560
UTC Time: 1654512361
Local Time: 1654555561
UTC Time: 1654512362
Local Time: 1654555562
UTC Time: 1654512364
Local Time: 1654555564
UTC Time: 1654512365
Local Time: 1654555565
UTC Time: 1654512366
Local Time: 1654555566
UTC Time: 1654512367
Local Time: 1654555567
UTC Time: 1654512368
Local Time: 1654555568
UTC Time: 1654512370
Local Time: 1654555570
UTC Time: 1654512371
Local Time: 1654555571
UTC Time: 1654512372
Local Time: 1654555572
UTC Time: 1654512373
Local Time: 1654555573
UTC Time: 1654512374
Local Time: 1654555574
UTC Time: 1654512376
Local Time: 1654555576
UTC Time: 1654512377
Local Time: 1654555577
UTC Time: 1654512378
Local Time: 1654555578
UTC Time: 1654512379
Local Time: 1654555579
UTC Time: 1654512380
Local Time: 1654555580
UTC Time: 1654512382
Local Time: 1654555582

Hi @bigdingo,
thanks for the data. This line is confirming my suspect :

ConnectionHandler::getRemoteTime time: [1654512304l]

Time of the test: 6 june 2022 10:45am
Time from connection handler (should be GMT): 1654512324 -> 6 june 2022 10:45am
Localtime: 1654555524 -> 6 june 2022 22:45

i've also double checked the previous test data and however it looks correct...

Time of the test 31 may 2022 15:59
Time from unknown source: 1653969542 -> 31 may 2022 3:59am
Localtime: 1654012742 -> 31 May 2022 15:59

At the end i'm still thinking that the data coming from connection handler is wrong so i've made another change in the library that should either fix the issue using NTP time and also allows us to check the difference between connection handler time and NTP time.

Would you be so kind to download the library again, repeat the test, post the serial monitor log and check if with this change the scheduler works correctly?

You can find the library here

Thanks

Hi again @Pennam,

Here is the new test data... Time test taken 2:20pm 10th June.

I can not get the 'isActive' code to work at all any more.

SIM card ok
GPRS.attachGPRS(): 4
Connected to GPRS Network
NTPUtils::getRemoteTime time: [1654827436l]
ArduinoIoTCloudTCP::handle_SyncTime internal clock configured to posix timestamp 1654827436
UTC Time: 1654827447
Local Time: 0
UTC Time: 1654827451
Local Time: 0
UTC Time: 1654827456
Local Time: 0
UTC Time: 1654827460
Local Time: 0
ArduinoIoTCloudTCP::handle_WaitDeviceConfig device waiting for valid thing_id
UTC Time: 1654827464
Local Time: 0
UTC Time: 1654827469
Local Time: 0
UTC Time: 1654827473
Local Time: 0
UTC Time: 1654827477
Local Time: 0
Connected to Arduino IoT Cloud
Thing ID: fffd94ea-4475-4341-bb57-6c1483f5c63c
UTC Time: 1654827486
Local Time: 0
UTC Time: 1654827491
Local Time: 0
UTC Time: 1654827495
Local Time: 0
UTC Time: 1654827499
Local Time: 0
ArduinoIoTCloudTCP::setTimeZoneData tz_offset: [43200]
ArduinoIoTCloudTCP::setTimeZoneData tz_dst_unitl: [1664028000l]
UTC Time: 1654827503
Local Time: 1654870703
UTC Time: 1654827507
Local Time: 1654870707
UTC Time: 1654827511
Local Time: 1654870711
UTC Time: 1654827516
Local Time: 1654870716
UTC Time: 1654827520
Local Time: 1654870720
UTC Time: 1654827524
Local Time: 1654870724
UTC Time: 1654827528
Local Time: 1654870728
UTC Time: 1654827532
Local Time: 1654870732
UTC Time: 1654827536
Local Time: 1654870736
UTC Time: 1654827540
Local Time: 1654870740
UTC Time: 1654827545
Local Time: 1654870745
UTC Time: 1654827549
Local Time: 1654870749
UTC Time: 1654827553
Local Time: 1654870753
UTC Time: 1654827557
Local Time: 1654870757
UTC Time: 1654827561
Local Time: 1654870761
UTC Time: 1654827565
Local Time: 1654870765

Hi @pennam,

Do you happen to have any further advice on this?

Best,

M

Hi @bigdingo,
sorry for the delay, i'm on vacation this week, i'll take a look to the new data on monday. In the meanwhile can you share also your scheduler configuration.

Mattia

Hi @bigdingo,
the retrieved time is correct now. I've also made a quick test with my board and the scheduler widget and everything has worked. Would you share your scheduler configuration so i can try to help you?

Hi @pennam

This is working for me fully now, thank you so much for your support.

Best,

Matt