×

INDI Library v2.0.6 is Released (02 Feb 2024)

Bi-monthly release with minor bug fixes and improvements

Raspberry real time (SOLVED)

  • Posts: 348
  • Thank you received: 69

Replied by Giles on topic Raspberry real time


The following chronyd.conf configuration, take the time from whatever is available GPS, Network or whatever, and syncs your system clock to it:
# Welcome to the chrony configuration file. See chrony.conf(5) for more
# information about usuable directives.
pool 2.debian.pool.ntp.org iburst
 
# This directive specify the location of the file containing ID/key pairs for
# NTP authentication.
keyfile /etc/chrony/chrony.keys
 
# This directive specify the file into which chronyd will store the rate
# information.
driftfile /var/lib/chrony/chrony.drift
 
# Uncomment the following line to turn logging on.
#log tracking measurements statistics
 
# Log files location.
logdir /var/log/chrony
 
# Stop bad estimates upsetting machine clock.
maxupdateskew 100.0
 
# This directive enables kernel synchronisation (every 11 minutes) of the
# real-time clock. Note that it can’t be used along with the 'rtcfile' directive.
rtcsync
 
# Step the system clock instead of slewing it if the adjustment is larger than
# one second, but only in the first three clock updates.
makestep 1 3
refclock SHM 0 offset 0.5 delay 0.2 refid GPS

Taken from the default Astroberry 2.0.1 configuration.
The following user(s) said Thank You: Matteo
4 years 1 month ago #49675

Please Log in or Create an account to join the conversation.

  • Posts: 174
  • Thank you received: 27

Replied by Alex Varakin on topic Raspberry real time

Here is another approach which does not require additional hardware: setup laptop as ntp server and get RPi to sync time from laptop.
4 years 1 month ago #49737

Please Log in or Create an account to join the conversation.

  • Posts: 298
  • Thank you received: 46

Replied by Markku on topic Raspberry real time

Hi guys,

I just tried this : www.raspberrypi.org/forums/viewtopic.php?t=161133
I used OSMC for the test and it worked, but it seems that the networkmanager in OSMC is not very happy when booting without any network connection and doesn't bring up the NIC but the time and date is set, I didn't do any debugging about the problem for now so I guess I have to try using Raspian also.

Br,
/Markku
The following user(s) said Thank You: Juhin Christophe
4 years 1 month ago #49782

Please Log in or Create an account to join the conversation.

  • Posts: 298
  • Thank you received: 46

Replied by Markku on topic Raspberry real time

I did a try with Raspbian Buster last evening and after updating and rebooting the time and date was correct from the DS3231 module without any network connection.

Br,
/Markku
The following user(s) said Thank You: Juhin Christophe
4 years 1 month ago #49794

Please Log in or Create an account to join the conversation.

  • Posts: 10
  • Thank you received: 1
Thank you for your answers . I finally opted for an rtc card based on 1307. But if I type sudo hwclock -r the clock is on time but not the system time even after reboot. . If I type sudo hwclock -s the system is set to the correct time but after a reboot I still have the old system time and if I type sudo hwclock -r the time and date are correct. How to have the right time when starting the raspberry? I'm on Ubuntu mate 16.04. Thanks in advance friends
4 years 1 month ago #49957

Please Log in or Create an account to join the conversation.

  • Posts: 29
  • Thank you received: 6
Hi,

Have a look to this thread : www.indilib.org/forum/stellarmate/6494-i...ate-1-5-0.html#49752.
Maybe it could help. In your case, you should probably have to replace ...ds3231 by ...ds1307

Pierre-Yves
4 years 1 month ago #49958

Please Log in or Create an account to join the conversation.

  • Posts: 10
  • Thank you received: 1
Re: The Correct way to add a RTC

Quote
I finally found it. See the penultimate post on page 3:

www.raspberrypi.org/forums/viewtopic.php?p=842661#p842661


Thu Aug 24, 2017 5:54 pm
After searching for a long while, and after a lot of experiments, I've putted togheter all the information I've collected all around the Net about how to connect a realtime clock to the Raspberry and allow the OS use it as system clock even if no connections to a NTP server.
I've used a DS3231, but the following should work even with a DS1307. Just use ds1307 where into the following instructions is used ds3231.

The following, definitively worked for me, using Raspbian Jessie. So:
edit the file using sudo nano /boot/config.txt and add or modify a line that looks like the following:

Code: Select all

dtoverlay=i2c-rtc,ds1307
Edit the file using sudo nano /etc/init.d/hwclock.sh and comment out the content in order to be sure that the content looks like the following:

Code: Select all

#if [ -d /run/udev ] || [ -d /dev/.udev ]; then
# return 0
#fi

Then disable the fake-hwclock and enable the hwclock.sh with the following group of commands:

Code: Select all

sudo apt-get remove fake-hwclock
sudo rm /etc/cron.hourly/fake-hwclock
sudo update-rc.d -f fake-hwclock remove
sudo rm /etc/init.d/fake-hwclock
sudo update-rc.d hwclock.sh enable

Then modify the file using sudo nano /lib/udev/hwclock-set locate the following lines and be sure to comment it out:

Code: Select all

# if [ -e /run/systemd/system ] ; then
# exit 0
# fi

Now, create two system services in order to set the system's clock when the OS boot and also to write to the RTC at the shutdown. So, the first one:

Code: Select all

sudo nano /etc/systemd/system/hwclock-start.service

...and paste in it the following:

Code: Select all

[Unit]
Description=Set time from RTC on startup
After=network.target

[Service]
Type=oneshot
ExecStart=/sbin/hwclock -s
TimeoutSec=0

[Install]
WantedBy=multi-user.target

and the second one:

Code: Select all

sudo nano /etc/systemd/system/hwclock-stop.service

Paste in it the following:

Code: Select all

[Unit]
Description=Synchronise Hardware Clock to System Clock
DefaultDependencies=no
Before=shutdown.target

[Service]
Type=oneshot
ExecStart=/sbin/hwclock --systohc

[Install]
WantedBy=reboot.target halt.target poweroff.target

Finally, enable the services issuing once the following command:

Code: Select all

sudo systemctl enable hwclock-start hwclock-stop

You can also verify that the RTC module has been loaded using

Code: Select all

sudo lsmod
4 years 1 month ago #49965

Please Log in or Create an account to join the conversation.

  • Posts: 10
  • Thank you received: 1
It works so fine !
The following user(s) said Thank You: Markku
4 years 1 month ago #49966

Please Log in or Create an account to join the conversation.

  • Posts: 298
  • Thank you received: 46

Replied by Markku on topic Raspberry real time

Hi,

Interesting stuff.. now I even understand why the timesync to hwclock was working sometimes when shutting down the RPi but not at bootup.
I guess all that could be done with the raspi-config script using options to choose fake-hwclock or a RTC-module.

Nice work!
CS
/Markku
The following user(s) said Thank You: Juhin Christophe
4 years 1 month ago #50032

Please Log in or Create an account to join the conversation.

Time to create page: 0.989 seconds