Discussions related to network, internet and socket programming; also to serial, parallel, Bluetooth, USB etc.
3 posts • Page 1 of 1
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...
Yes, you can issue the necessary command from inside a BBC BASIC program:
The string can of course be 'calculated' as required, rather than being a literal string as shown above.
Code: Select all
OSCLI "run sudo date --set='2019-11-05 20:21:42'"
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.
My posts are moderated; if you are seeing this it has already been approved. If you have a comment about the style or tone of the message please report it to the moderators by clicking the exclamation mark icon rather than complaining on the public forum.