You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey, so maybe I'm doing this wrong, but I wondered how to use the RV3028 to have my Raspi auto-set the time on boot using the RTC and also handle the case in which it doesn't have network connection to an optionally configured NTP server.
Here's the script I use for this (via /etc/crontab), does that make any sense?
#!/usr/bin/env python3"""A script to run on reboot to automatically set the system time tothe RTC time. Will disable Automatic time synchronization while running(if enabled) and re-enable it again. This is to ensure that setting from RTCworks without network connection.Add to the system crontab:$ sudo nano /etc/crontabAnd then add:@daily root python3 /path/to/timedatectl-set-time-from-rtc.py(c) Jannis Leidel 2019"""importtimefromsubprocessimportrunimportrv3028TIMEDATECTL="/usr/bin/timedatectl"# Create RV3028 instancertc=rv3028.RV3028()
# Switches RTC to backup battery if VCC goes below 2V# Other settings: 'switchover_disabled', 'direct_switching_mode', 'standby_mode'rtc.set_battery_switchover('level_switching_mode')
rtc_time=rtc.get_time_and_date()
iso_rtc_time=rtc_time.isoformat(" ")
print("The RTC time is: {}".format(iso_rtc_time))
# Disabling NTP now so we can set the time manually# in case network connection isn't there right nowtimedatectl_output=run([TIMEDATECTL], capture_output=True)
ntp_enabled=b"NTP service: active"intimedatectl_output.stdoutifntp_enabled:
run([TIMEDATECTL, "set-ntp", "false"])
time.sleep(1)
try:
# run timedatectl set-time with the time returned from the RTC# The time may be specified in the format "2012-10-30 18:17:16".run([TIMEDATECTL, "set-time", iso_rtc_time])
finally:
print("Successfully set local time using the RV3028.")
# definitely re-enable NTP in case something goes wrong with setting# the time.ifntp_enabled:
run([TIMEDATECTL, "set-ntp", "true"])
The text was updated successfully, but these errors were encountered:
jezdez
changed the title
Add to auto-set local time on reboot/daily with timedatectl
Add script to auto-set local time on reboot/daily with timedatectl
Aug 1, 2019
It wont handle your ntp case, but you might have some luck configuring the rtc-rv3028 kernel module to handle this. I'd totally forgotten that I'd submitted an upstream patch for battery switchover support, but just noticed that the module is available on my Pi 4 with kernel 4.19.58.
Woah! I didn't realize there is a kernel module to do that. The script works for me so far, but I would probably accept a bit of drift in favor of a kernel module.
That would require to add rtc-rv3028 to /etc/modules right? Never done this before, any chance you could update the docs how to do that?
See above regarding the dtoverlay line which you should add to /boot/config.txt- this makes sure the module is configured correctly. I don't have hardware with me to double-check that it works, but it should.
Hey, so maybe I'm doing this wrong, but I wondered how to use the RV3028 to have my Raspi auto-set the time on boot using the RTC and also handle the case in which it doesn't have network connection to an optionally configured NTP server.
Here's the script I use for this (via
/etc/crontab
), does that make any sense?The text was updated successfully, but these errors were encountered: