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

[Solved / Archived] Alternative implementation for system-near Witty Pi 4 usage

2 Posts
2 Users
0 Likes
201 Views
(@jonas-hochst)
Posts: 1
New Member Customer
Topic starter
 

Hey there,

I've done an alternative implementation on the Raspberry Pi level, which I want to share here. My design goals were:
- be close to the system, i.e. the kernel
- use system-components where possible
- use a safe programming language for the scheduling part.

What I came up with is a set of components which works tightly with Linux:

- The power led and the on/off-switch are handled by dtoverlays already available in the Raspberry Pi Firmware (gpio-shutdown/gpio-led).
- The real-time clock is handled by a modified driver forked from the linux kernel (addresses needed to be adjusted).
- A python library and daemon is available which enables easy access to the WittyPi property (get and set) as well as define a schedule for operation of your installation. You also have the option to schedule your device according to a static location (lat/lon) provided and the dusk/dawn sunset/sunrise relative timestamps. 

In principle the implementation is compatible with the default one, although there is one major difference, that being the clock set in UTC time. This solves problems regarding boot up and shutdown when switching winter-summertime and also is the default way of handling RTCs in Linux.

At it's current stage the project is not documented too well, nevertheless it could be interesting to checkout the repository (licensed GPL-3.0) and fiddle around a bit: https://github.com/tRackIT-Systems/wittypi4/tree/main

Cheers
Jonas

 
Posted : 06/09/2024 12:15 pm
(@arjenr)
Posts: 28
Eminent Member Customer
 

I don't understand much of this, but the Linux default handling of the RTC sounds appealing.

WittyPi disables chrony and systemd-timesyncd at boot, which UUgear says is necessary as these services cause problems for WittyPi, although it is not clear to me what sort of problems.

I have a setup with Pi4B and Witty Pi 4 L3V7. It is intended as an essential part of my LAN.

It runs PiHole with Unbound for local DNS (and eventually Wireguard like the Pi4 without WittyPi it is going to replace). It should also work as the local NTP server for the other machines on the LAN, and even the DD-WRT router. For this purpose I adopted chrony.

It doesn't help that WittyPi disables chrony at boot up. Without reasonably correct time (how close?) on this DNS server, it will not be able to do DNS (because of DNSSEC), so it will not be able to find the IP and connect to a NTP server on the WAN. This would be a catch-22 situation. So a local RTC is essential.

If I use an RTC module like with a DS1307 and battery, this time problem is solved, but then the DNS server is not protected against black-outs, which will leave OS partitions as 'dirty' or worse.

Currently I simply enable chrony at reboot in cron. Chrony works and the only odd thing I notice, which could potentially be worrying is this:

sep 21 10:31:05 PiHole2 systemd[1]: Starting chrony.service - chrony, an NTP client/server...
sep 21 10:31:06 PiHole2 chronyd[3225]: chronyd version 4.3 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCD>
sep 21 10:31:06 PiHole2 chronyd[3225]: Frequency 12.125 +/- 0.122 ppm read from /var/lib/chrony/chrony.drift
sep 21 10:31:06 PiHole2 chronyd[3225]: Using right/UTC timezone to obtain leap second data
sep 21 10:31:06 PiHole2 chronyd[3225]: Loaded seccomp filter (level 1)
sep 21 10:31:06 PiHole2 systemd[1]: Started chrony.service - chrony, an NTP client/server.
sep 21 10:31:09 PiHole2 chronyd[3225]: Selected source 81.172.225.142 (pool.ntp.org)
sep 21 10:31:09 PiHole2 chronyd[3225]: System clock wrong by 4.069726 seconds
sep 21 10:31:13 PiHole2 chronyd[3225]: System clock was stepped by 4.069726 seconds
sep 21 10:31:13 PiHole2 chronyd[3225]: System clock TAI offset set to 37 seconds

The clock is always wrong after reboot, but mostly just some seconds. Somehow it looses a few seconds. I can only guess why this is (nothing like that happens with a separate RTC module and no WittyPi). This is with internet connected. I think I tested also without internet connection, but so much has been going on that I'm not sure about the result. I think it survived OK. Apart from all connected clients, my R7800 router also gets correct time from this NTP server on its own LAN when starting up (by IP).

Timedatectl doesn't show RTC time and hwclock doesn't work as expected when WittyPi is installed. The RTC on WittyPi appears to be a real one and not simulated, but it doesn't behave like a separate RTC module. It is not the only UPS to do this. Omzlo's PiVoyager is similar in 'hiding' the RTC. With a PiJuice HAT on two other Pi4B's hwclock, timedatectl and status chronyd work normally.

WittyPi functions which copy time from RTC to system will disable chrony, so I have to avoid using those, or re-enable chronyd again.

All this fussing creates doubt as if to this server setup will be doing 100% what is is intended for: keep the LAN running and connected to the internet when there's no operator present to handle blackouts. This is just a summer cottage and things happen ... but I run off-site backups here every three hours ...

Jonas's project might solve these problems, but it is way over my head, unfortunately.

 
Posted : 21/09/2024 12:19 pm
Join Waitlist We will inform you when the product arrives in stock. Please leave your valid email address below.