On Sat, 2 Nov 2019 16:14:54 +0100, "R.Wieser"
declaimed the following:
>Hello all,
>
>Just today I connected a DS3231 Real Time Clock module to my Pi - to use
>when it cannot connect to the internet to get its current time from an NTP
>server..
>
>I'm using python to retrieve the date and time from the RTC module and
>display it. But now I'm stuck at the point where I need to set Raspberry
>Pi's clock with it. I've been googeling for at least half an hour, but
>can't seem to find how to *set* the current time.
>
The "proper" method is to avoid Python and make suitable configuration
changes to the R-Pi boot...
https://pimylifeup.com/raspberry-pi-rtc/
>De closest I have been is to execute
>"datetime.datetime(2019,11,02,16,06,0) - which gets ignored without any kind
>of error or warning message ...
>
No surprise there... All that statement does is create a Python
datetime object/instance initialized to a particular date/time value -- and
then throws it away.. Usage should be:
mydate = datetime.datetime(...)
to keep the created instance with the name "mydate". Of course, that still
does nothing for setting a clock module at the system level.
>Added problem: The Pi might (ofcourse) have problems with "a mere user"
>trying to change the system clock, and might need some kind of "sudo". How
>do I do that from within "Thonny" (in the "shell" window) ?
>
First recommendation -- forget the interactive shell... It is really
just meant for testing snippets of code. If you really want to use Python
for all this, write a script file that can be executed outside of the IDE.
Second -- study the Python Library Reference manual... I'd direct you
to the section on subprocess.popen() (or for quick&dirty, the deprecated
os.execute()).
At least the default R-Pi setup gives the "pi" account sudo privilege
without needing to enter a password (Plain Debian and Beaglebone require
the user account password to perform sudo -- this helps prevent someone
walking by a logged in machine from randomly doing "sudo
something-malicious" as they would need to know the password of the logged
in user). If it did, you might have to study the "expect" module.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/
--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)
|