ArduinoCloud.getLocalTime() returning wrong value?

I can't believe my eyes, but by calling ArduinoCloud.getLocalTime() repeatedly every second or two, I sporadically (say, every 30-60 seconds) receive the wrong value 1663466400 corresponding to "2am this morning".

Here's a trace of the readings I am obtaining (returned value first, and the decoded time):
1663525694 18:28:14 in ciclo
1663525698 18:28:18 in ciclo
1663466400 02:00:00 fuori ciclo
1663525705 18:28:25 in ciclo
1663525706 18:28:26 in ciclo
1663525708 18:28:28 in ciclo
1663525709 18:28:29 in ciclo
1663525711 18:28:31 in ciclo
1663525714 18:28:34 in ciclo
1663525715 18:28:35 in ciclo
1663525717 18:28:37 in ciclo
1663525719 18:28:39 in ciclo
1663525722 18:28:42 in ciclo
1663525723 18:28:43 in ciclo
1663525725 18:28:45 in ciclo
1663525726 18:28:46 in ciclo
1663525730 18:28:50 in ciclo
1663466400 02:00:00 fuori ciclo
1663525737 18:28:57 in ciclo
1663525740 18:29:00 in ciclo
1663525742 18:29:02 in ciclo
1663525746 18:29:06 in ciclo
1663525748 18:29:08 in ciclo
1663525749 18:29:09 in ciclo
1663525751 18:29:11 in ciclo
1663525755 18:29:15 in ciclo
1663525760 18:29:20 in ciclo
1663525763 18:29:23 in ciclo
1663525767 18:29:27 in ciclo
1663525768 18:29:28 in ciclo
1663525771 18:29:31 in ciclo
1663525773 18:29:33 in ciclo
1663466400 02:00:00 fuori ciclo
1663525783 18:29:43 in ciclo
1663525789 18:29:49 in ciclo
1663525795 18:29:55 in ciclo
1663466400 02:00:00 fuori ciclo
1663525807 18:30:07 in ciclo
1663525813 18:30:13 in ciclo

Did anyone experienced such behaviour? I am sure there's something wrong (maybe in using it so frequently?) but can't spot it. Thanks
Michele

Many of the time servers have a poling limit. You may be exceeding that. Try waiting maybe 15 minutes between calls and see if that resolves it. If not it is probably your code but before you post it asking for help check the porum guidelines on how to do it.

@mantonucci which board are you using?

All Arduino boards are using internal RTC to store the time after the first request to the NTP server so it is really strange... ESP boards do not use internal RTC so each time request is an actual NTP request and in this case i would follow @gilshultz suggestion.

I am indeed using ESP8266 and ESP32 boards. I moved to Arduino IoT Cloud recently, and am porting the code of several Blynk (legacy) applications I have in operation since years, which routinely poll the NTP server every second. I never had any failure whatsoever with NTP, which leads me to believe there's something wrong in the ArduinoCloud.getLocalTime() code - especially because the wrong value returned is constant and corresponds exactly to 2 hours past midnight, which accidentally happens to be my timezone time offset.

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