Page 1 of 1

Using RTC module and synchronizing time from the net together

Posted: Mon Jul 15, 2019 12:21 pm
by semih_sky
Hi friends,

I want my RaPi to have the right time even it is connected to internet or not. So I bought RTC DS3231 module and installed, works fine. Bu at the same time I want RaPi to syncronize time from internet or the local time server I define.

So for instance, RaPi will try to access to the internet time server or local time server (NTP Server), if it is accessible it will sync it's time with this server and write the same time to RTC. Otherwise it will go on using RTC's current time.

I've worked on timedatectl command, edited /etc/systemd/timesyncd.conf but I could not manage to run these two functions together. If it is needed I can write all these stuff in python to run correctly.

Thanks,
Semih.

Re: Using RTC module and synchronizing time from the net together

Posted: Mon Jul 15, 2019 12:32 pm
by epoch1970
The systemd stuff uses only one server at a time. No idea how long it sticks with it.
As mentioned in the response within the link, if you want to have a local (RTC) and internet clock sources at the same time, you'd need to install ntpd or another NTP server.
Internet NTP servers will usually be stratum 2 or 3, if you set your RTC clock to stratum 4 it should serve as source until a better source is found on the Internet.

Re: Using RTC module and synchronizing time from the net together

Posted: Sun Jul 21, 2019 6:36 pm
by semih_sky
Thanks Epoch,

I've decided to install ntp on Raspberry Stretch cause ntp package has been removed in the last Raspberry OS versions. And I read the details in the link you gave.

I'll write some python code with ntplib library and I suppose that I'll manage to controll time sync and RTC together.

Thanks,
Semih.

Re: Using RTC module and synchronizing time from the net together

Posted: Sun Jul 21, 2019 7:20 pm
by epoch1970
semih_sky wrote:
Sun Jul 21, 2019 6:36 pm
I've decided to install ntp on Raspberry Stretch cause ntp package has been removed in the last Raspberry OS versions
https://manpages.debian.org/buster/ntp/ntpd.8.en.html
Package ntpd is still in Buster.
The wimpy ntp client provided by systemd is used by default in current Raspbian. You can neuter it and install package ntpd if you wish. No need to stay with Stretch, you can do the same in Buster.

Re: Using RTC module and synchronizing time from the net together

Posted: Thu Aug 01, 2019 11:30 am
by semih_sky
I'm using Stretch for a long time for our industrial project and made many custom settings on it, so I don't want to change it to Buster at this period. I've searched the differances between ntpd and ntp, after that I've seen ntp will be better for this project. Thanks for your support.

Re: Using RTC module and synchronizing time from the net together

Posted: Fri Aug 02, 2019 7:11 am
by markkuk
semih_sky wrote:
Thu Aug 01, 2019 11:30 am
I've searched the differances between ntpd and ntp, after that I've seen ntp will be better for this project.
NTP is a protocol and ntpd is a program implementing that protocol. If you install ntpd you will be using NTP to set your system time.

Re: Using RTC module and synchronizing time from the net together

Posted: Fri Aug 02, 2019 8:04 am
by semih_sky
As I researched, you can use ntpd each time you want and call it to set system time, but NTP makes time sync auto in defined periods. So I plan to use NTP.

Re: Using RTC module and synchronizing time from the net together

Posted: Fri Aug 02, 2019 10:44 am
by markkuk
semih_sky wrote:
Fri Aug 02, 2019 8:04 am
As I researched, you can use ntpd each time you want and call it to set system time
ntpd is a service that runs continuously in the background and keeps your system time synchronised with network time servers.

Clearly you don't understand the difference between NTP and ntpd, or between a communication protocol and a computer program.

If you want to use NTP to keep the computer clock synchronized then you must install ntpd or some other implementation of the NTP protocol such as chrony. How exactly are you planning to use NTP without ntpd?