Working with DateTime #6616
Replies: 1 comment
-
Posted at 2019-11-08 by @allObjects There is a checkbox in IDE settings that seeds date and time from your IDE machine on code upload to Espruino board. Posted at 2019-11-08 by michael_101 Ok, I can now see the correct date and time, but, my tests shows that if I'm using onInite function when the board is connected to an external power source the date goes back to 1970, is that mean that I need to manage getting the current datetime from the internet or whatever so the board can continue from there or there is another better solution for boards that does not connect to the internet like Puck.js etc. ? Thanks, Posted at 2019-11-08 by AkosLukacs Yes, removing power from it resets the clock. Posted at 2019-11-13 by @gfwilliams If you're worried about losing the time, the best bet is to ensure that you have some backup battery always connected to the device via a diode. Posted at 2022-02-20 by TeppoKurki I'd like to use my Pico as a temperature logger. The script's working, but how do I now set the time and keep it from resetting? I am planning to use 4xAA Eneloops as the power source. Do I just keep them connected and connect IDE also via USB to set the time? I'd like to add some indication that time needs setting, like flash a led. But how should I check that time is set correctly - just some lower bound as a sanity check? Posted at 2022-02-21 by @allObjects @TeppoKurki, I guess you figure when connected - and powered over USB - you can make the upload of code to set the time - an option in the ide-settings... Unfortunately, as far as I know, any power cycle loses the time. You can power the pico from the batteries over the designated connector, then connect to usb, then upload the code into RAM with time setting - do not start your code / application yet, but have an onInit() function which includes the start of your code / application. While still connected, you can write the current time to Storage with function you call from console or with statements executed in the console. In your code, your read that time and compare it to the time stored - your hinted lower bound as a sanity check. If the stored time is ahead, you obviously got a power cycle and lost your time and you can signal that. You reconnect and you can set the time with some js statements in the console. To resolve time for good, get yourself a simple RTC clock module w/ battery backup - either Dallas DS1302 or DB3231. (I assume you had planned to have nothing else connected to Esuprino except the batteries and temp sensor(s)). |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-11-07 by michael_101
Hi,
I'm a little confused...
Is 'new Date()' supposed to return the current DateTime like 'Thu Nov 07 2019 17:36:22 GMT+0200'?
Somehow I'm getting 'Thu Jan 1 1970 02:46:57 GMT+0000'
Am I missing something?
Thanks
Michael.
Beta Was this translation helpful? Give feedback.
All reactions