Date Time issues rPi4

Then I think it’s ok?
the stop and start is just to avoid rebooting for testing.

Now I changed to

sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"

and is

volumio@cichy5000:~$ cat /home/volumio/setdatetime.sh
#!/bin/bash
date -s “$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d’ ’ -f5-8)Z”
volumio@cichy5000:~$

Not because after reboot I have:

volumio@cichy5000:~$ date
Wed Jan 31 01:01:35 CET 2024

after start and stop:
volumio@cichy5000:~$ date
Wed Jan 31 21:59:10 CET 2024

1 Like

Before reboot:
image

After reboot:
image

Did you hear me cursing…

No clue why this happens…

oooo you have the same… I broke your Pi :upside_down_face:

I checked both

First give me 01:00:00 after reebot

second give me 00:00:00 after reboot.

Both give me correct time after stop and start service.

I tried to add

to /home/volumio/setdatetime.sh :slight_smile: but it change nothing

systemctl disable setdatetime.service && sudo rm /lib/systemd/system/setdatetime.service

sudo cat <<EOF >>/lib/systemd/system/setdatetime.service
[Unit]
Description=Date Time service
Wants=network-online.target
After=network-online.target
After=volumio.service

[Service]
ExecStart=/bin/bash /home/volumio/setdatetime.sh

[Install]
WantedBy=multi-user.target
EOF

sudo chmod 644 /lib/systemd/system/setdatetime.service && sudo systemctl daemon-reload && sudo systemctl enable setdatetime.service && sudo systemctl start setdatetime.service

After reboot the time is correct on my rPi.

are you shure ??

I done:

1:

have :

volumio@cichy5000:~$ systemctl disable setdatetime.service && sudo rm /lib/systemd/system/setdatetime.service
Removed /etc/systemd/system/multi-user.target.wants/setdatetime.service.
volumio@cichy5000:~$

2:

and

insert pasword: volumio

3:

and have:

olumio@cichy5000:~$ sudo chmod 644 /lib/systemd/system/setdatetime.service && sudo systemctl daemon-reload && sudo systemctl enable setdatetime.service && sudo systemctl start setdatetime.service
Created symlink /etc/systemd/system/multi-user.target.wants/setdatetime.service → /lib/systemd/system/setdatetime.service.
volumio@cichy5000:~$

4:

sudo reboot

and… after reboot:

volumio@cichy5000:~$ date
Wed Jan 31 00:00:31 CET 2024
volumio@cichy5000:~$ sudo systemctl stop setdatetime.service
volumio@cichy5000:~$ sudo systemctl start setdatetime.service
volumio@cichy5000:~$ date
Wed Jan 31 22:42:57 CET 2024
volumio@cichy5000:~$

what goes wrong ??

EDIT:

volumio@cichy5000:~$ cat /lib/systemd/system/setdatetime.service
[Unit]
Description=Date Time service
Wants=network-online.target
After=network-online.target
After=volumio.service

[Service]
ExecStart=/bin/bash /home/volumio/setdatetime.sh

[Install]
WantedBy=multi-user.target
volumio@cichy5000:~$

After=volumio.service is add.

It’s working here.
After Volumio is loaded, I see the time being corrected.
At startup 22:54, after Volumio GUI is loaded the time jumps to 22:57.
Using MPD_Oled to verify

Via putty I have still wrong time. The same wrong time after reboot is on screen.

but in NowPlaying preview kiosk mode I have good time:

??

me too ???

Would it help to add an RTC module to Pi4?
for example:
RTC DS1302 SPI - real-time clock - Waveshare 9709

yes it would help, like with the ri5

I thought about it but first. Thank you for this job with NTC server.

I hope it will help. I don’t need correct time but without date after few days Volumio stop.

I bought Raspberry Pi RTC DS3231. It is better than DS1302. I hope that in Volumio is possibility to use it.

All you have to do is adding to /boot/userconfig.txt
dtoverlay=i2c-rtc,ds3231

Reboot, make sure your date is correct and run:
sudo hwclock -w

The overlay exist in the Volumio images: “i2c-rtc.dtbo”

Today I had an incorrect time on one of my Pi4 Volumios and tried to follow the thread here. This part worked to correct the time, but it doesn’t survive a reboot. So I then need to stop and start setdatetime.service again. Was there a permanent solution that I missed? Maybe adding this to userconfig?

Hi @SimonE

Currently I Have this running, which seems to do the trick for me on a rPi4, bypassing the script. All in the service.
I know the sleep is all but elegant, but I experienced the same issue as @eMCZe mentioned. 7 out of 10 it worked, but not consistent.

sudo nano /lib/systemd/system/setdatetime.service

[Unit]
Description=Set local time using time server

[Service]
Type=oneshot
ExecStart=/bin/bash -c "sleep 30; /usr/bin/sudo /bin/date -s \"$(/usr/bin/curl -s --head http://google.com | grep ^Date: | sed 's/Date: //g')\""

[Install]
WantedBy=multi-user.target

ctrl+o, ctrl+x

sudo chmod 644 /lib/systemd/system/setdatetime.service && sudo systemctl daemon-reload && sudo systemctl enable setdatetime.service && sudo systemctl start setdatetime.service

1 Like

Thanks, this is working for me too.
Simon

I have this Pi 4 in my home but in my net works without problem :slight_smile:

Now I almost finish soldering all parts in one great sounding tube DAC and will connect it via USB to Pi. GPIO will be free for external RTC.

I tried with internal Pi5 RTC with battery and without WLAN and LAN. I still have good time after disconnected power.

I hope the same will be with Pi4.

Just let us know :slight_smile: