Hello folks,
I’m converting an NTP server (GPS controled) from a rpi zero with SPI ethernet (10Mb/s) running raspbian lite to a nanopi neo3 with DietPi. I want to use the onboard 1GBps, as that will reduce the local LAN NTP delay from 2msec to 0.5msec from my tests.
The first step of this process is to get the RTC DS3231 (I2C) to work with DietPi.
I was successful in the I2C connection and
sudo i2cdetect -y 0
correctly shows the DS3231 at address 68.
From my searches around the forums I then need to execute the following in order to create the new device:
sudo echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
By the way, even with sudo the command gives permission error, I can only run that as root.
After this the new hardware clock is available as it can be tested by:
sudo hwclock -r -f /dev/rtc1
I also remove the fake-clock by using the dietpi-config → RTC hardware.
Questions:
- Is this enough to have the DS3231 become the true and only hardware clock of the system?
- After reboot this is all lost. On the pi I would edit the rc.local file but that file is not present in my installation and even if I create it and add the following
sudo echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
hwclock -s
it still wouldn’t work (the new I2C device is not created).
So, what is the proper way to run the two command above at boot time on dietpi?
BTW I’m using DietPi v7.0.2.
Thanks a million!!!
Enzo
[SOLVED]
/lib/udev/hwclock-set became:
#!/bin/sh
# Reset the System Clock to UTC if the hardware clock from which it
# was copied by the kernel was in localtime.
dev=$1
if [ -e /run/systemd/system ] ; then
# exit 0
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
fi
#if [ -e /run/udev/hwclock-set ]; then
# exit 0
#fi
.
.
.
HCTOSYS_DEVICE=rtc1
This will attach /dev/rtc1 to the ds3231.
In order to have the system time set from the DS3231 at boot add the following line to /etc/rc.local
sudo hwclock -s -f /dev/rtc1
If your rc.local is not being executed at boot, enable the service:
Check it with: sudo systemctl status rc.local.service
restart it with sudo systemctl restart rc.local.service