Cool stuff for Raspberry Pi, Arduino and all electronics hobby projects
Notifications
Clear all

Daylight savings time & RTC?

3 Posts
2 Users
0 Likes
13 Views
(@arjenr)
Posts: 26
Eminent Member Customer
Topic starter
 

How is the WittyPi L3V7 supposed to behave when time changes from summer to winter time?

Because I use the Pi as the DNS server (PiHole with Unbound) on my LAN and also as the time server for my LAN (including router) I have installed chrony. Upon reboot it is always re-enabled because WittyPi disables it. This works for me and this question is not really about that.

After the change to winter time a few days ago, the RTC was about a whole hour off. Of course this can easily be remedied manually with the button in the UWI web interface. However I prefer to have it happen automatically.

I have also observed that the RTC occasionally deviates from the synchronized system time after some time by a few seconds, so the RTC requires setting from time to time.

I am not sure how the wittypi is supposed to behave with respect to the RTC. Is there any automatic correction supposed to happen? The RTC seems somehow hidden from standard commands like hwclock.

I have currently solved this with code in the afterStartup script (beforeShutdown isn't executed when shutting down with the CLI shutdown command):

datetime=$(date +'[%Y-%m-%d %H:%M:%S]')
/usr/bin/echo $datetime ">>> Executing afterStartup.sh"
/usr/bin/echo $datetime ">>> Re-enable chrony service after start-up"
/usr/bin/echo $datetime ">>> as Witty Pi disables NTP service ..."
# Enable & start chrony; no other documented mechanism
# to prefer chrony over systemd-timedated actually worked ...
sudo systemctl enable --now chrony
/usr/bin/sleep 10
/usr/bin/echo $datetime ">>> If the system clock is synchronized, copy system time to RTC."
[ $(timedatectl show --property=NTPSynchronized --value) ] \
  && source /home/pi/wittypi/utilities.sh; system_to_rtc > /dev/null \
  || /usr/bin/echo "System clock is not synchronized ..."

I may have to wait until spring 2025 to see if this really works for the change to summer time, but as far as regular operation is concerned it is fine. Rebooting every night.

I am really looking forward to your comments!

 
Posted : 29/10/2024 11:00 pm
(@admin)
Posts: 466
Member Admin
 

I previously made an explaination about daylight saving time on Witty Pi here: https://www.uugear.com/forums/technial-support-discussion/witty-pi-4-about-daylight-saving-time-dst/

 
Posted : 30/10/2024 8:20 am
(@arjenr)
Posts: 26
Eminent Member Customer
Topic starter
 

I will have to study those messages later, but I have changed the 'system' I adopted above slightly to wait until the system time is actually synchronized (in my setup with chrony).

#!/bin/bash
# Last modified by ar -- 30-10-2024
# file: afterStartup.sh
#
# This script will run after Raspberry Pi boot up and finish running the schedule script.
# If you want to run your commands after boot, you can place them here.
# 
# Remarks: please use absolute path of the command, or it can not be found (by root user).
# Remarks: you may append '&' at the end of command to avoid blocking the main daemon.sh.
#
datetime=$(date +'[%Y-%m-%d %H:%M:%S]')
/usr/bin/echo $datetime ">>> Executing afterStartup.sh"
/usr/bin/echo $datetime ">>> Re-enable chrony service after start-up"
/usr/bin/echo $datetime ">>> as Witty Pi disables NTP service ..."
# Enable & start chrony; no other documented mechanism
# to prefer chrony over systemd-timedated actually worked ...
sudo systemctl enable --now chrony
# Loop until system clock has been synchronized, then copy time to RTC.
/home/pi/wittypi/systemTime2RTC.sh &

and

#!/bin/bash
# Last modified by ar -- 30-10-2024
datetime=$(date +'[%Y-%m-%d %H:%M:%S]')
/usr/bin/echo $datetime ">>> Check if system clock is synchronized ..."
until [ $(timedatectl show --property=NTPSynchronized --value) ]
do
  /usr/bin/echo $datetime ">>> Waiting ..."
  sleep 10
done
/usr/bin/echo $datetime ">>> Copy system time to RTC."
source /home/pi/wittypi/utilities.sh; system_to_rtc > /dev/null

As such this works on reboot. Normally there's no looping. The system time has been synchronized immediately after enabling chrony.

There will be an interruption of network services at my location in the next few days, so we'll see how that plays out. DST change requires a longer wait ...

This post was modified 5 hours ago by ArjenR
 
Posted : 30/10/2024 12:07 pm
Join Waitlist We will inform you when the product arrives in stock. Please leave your valid email address below.