Setting Time on Raspberry Pi 3

Discussions related to network, internet and socket programming; also to serial, parallel, Bluetooth, USB etc.
atom058
Posts: 25
Joined: Tue 05 Nov 2019, 18:07

Setting Time on Raspberry Pi 3

Post by atom058 »

Hello - I have a Pi3 application where I can not be hooked to the web, so my Pi3 can not update the time when powered down and rebooted. I know how to set time using sudo commands, but I would like to know if there is a way to write a BBC Basic program (for Pi) that when run will prompt the user for the current date and time and then set it to the Pi. My application will require my Pi to stay powered up continuously so the only time that the time will have to be reset is if the power goes out and I want anyone to be able to easily set the time when it comes back up. For example... power goes out and Pi shuts down. Power comes back up and shows the Pi desktop. The user clicks on an icon that says "Set Time". A small screen pops up and has 2 fields: Date and Time. The user enters the current date and time and presses a SET button which will send the date and time to the OS. Is that possible? Maybe the program can create a sudo string from the date/time info? Thanks for any suggestions...
RichardRussell

Re: Setting Time on Raspberry Pi 3

Post by RichardRussell »

atom058 wrote: Tue 05 Nov 2019, 18:23I would like to know if there is a way to write a BBC Basic program (for Pi) that when run will prompt the user for the current date and time and then set it to the Pi.
Yes, you can issue the necessary command from inside a BBC BASIC program:

Code: Select all

      OSCLI "run sudo date --set='2019-11-05 20:21:42'"
The string can of course be 'calculated' as required, rather than being a literal string as shown above.

However a caveat: somebody else doing the same thing discovered that SDL 2.0 (some versions at least) seems to have a bug whereby if they set the time 'backwards' their BASIC program froze until the time 'caught up'. This could obviously be a serious issue if you may be changing the time in that direction (unless you can immediately QUIT at that point). I raised this at the SDL forum but nobody has offered a solution.
atom058
Posts: 25
Joined: Tue 05 Nov 2019, 18:07

Re: Setting Time on Raspberry Pi 3

Post by atom058 »

Thank you! I am new to BBC Basic so it may take me a while to try this, but now I have some incentive! Thanks again! Jeff