Jussi Posted November 21 Posted November 21 Hi! I started to receive messages about strange issues in my script. After some hard debugging, I found out that the Shelly reports incorrect timestamp just after start, before receiving time from NTP. I am 90% sure that the timestamp was previously in year 1970 (as usually in epoch based systems), before acquiring time from NTP. However, now I can see that Shelly saves the time to retain memory (once a day?) and then uses that time until NTP syncs. Previously it was easy to check if the Shelly had received the time from NTP: const timeOK = new Date().getFullYear() > 2000; //Year would be 1970 or so if not synced However, now when I power up the Shelly, it reports immediately a date from 2024 but from a wrong day in the past. So the above won't work. Basically there is no way to know if the time is somewhat valid. This can be easily demonstrated. Add a new script and enable autostart: function loop() { console.log(new Date()); } Timer.set(50, true, loop); Enable UDP logging and reboot the device. From logs we can see how the time is from 2024 before NTP sync. As you can see, the Shelly thinks that it's yesterday for some reason (this is recorded at 21.11.2024). Date: Wed Nov 20 2024 22:10:48 GMT+0200 New min heap free: 122840 Date: Wed Nov 20 2024 22:10:48 GMT+0200 Date: Wed Nov 20 2024 22:10:48 GMT+0200 Setting time from SNTP (1732169472.405 delta +36023.495) Time set to 4.103275 from 1 Date: Thu Nov 21 2024 08:11:12 GMT+0200 Date: Thu Nov 21 2024 08:11:12 GMT+0200 Date: Thu Nov 21 2024 08:11:12 GMT+0200 If I disable WiFi and reboot Shelly, it will always report a wrong day (but still from 2024), as there is no NTP available. This is a serious issue in my end, as the script is depending on the time. If the the is not known, the script must detect it somehow and operate accordingly. Firmware version 1.4.4 - tested with Shelly Plus 1 and Shelly Pro 3. Questions: - Is this a bug or a feature? - How can I know if the time is (somewhat) valid / is the shelly synced to a NTP? - Has this changed? I have never had issues like this before. I can't see any changes from the changelog. Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish
Jussi Posted November 21 Author Posted November 21 It seems that the unixtime under sys component displays null, if the NTP is not synced. This is new info for me and seems to be a lifesaver! Basically my new code is: timeOK = Shelly.getComponentStatus("sys").unixtime != null && now.getFullYear() > 2000; However, the issue and questions are still valid. Why does the Date() report strange timestamps before NTP is synced? Some people report timestamps from 5 days ago. Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish
Moderators terae Posted November 25 Moderators Posted November 25 @Lyubomir Petrov ? 1 Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.