RTC watchdog configuration guide
Perform a debug run with rtcwake
to make sure everything is working:
sudo rtcwake -m on -s 5
The command should run for 5 seconds, and then return nothing.
You can also check the wake alarms with:
sudo cat /sys/class/rtc/rtc0/wakealarm
Create the RTC watchdog script, assuming that it’s put inside /home/user/
:
nano /home/user/rtc-watchdog.sh
Add the following script, then save and exit:
#!/bin/bash
rtcwake -m no -s 60
-s 60
: boot 60 seconds after the command is run, adjust to your likings.
Note that this script needs to be run with sudo
privileges to take effect.
Add execute permission to the script:
chmod +x /home/user/rtc-watchdog.sh
Create a systemd
service:
sudo nano /etc/systemd/system/rtc-watchdog.service
Add the following, assuming that the script is located at /home/user/rtc-watchdog.sh
:
[Unit]
Description=RTC watchdog
DefaultDependencies=no
Before=poweroff.target shutdown.target
[Service]
Type=oneshot
ExecStart=/home/user/rtc-watchdog.sh
RemainAfterExit=true
[Install]
WantedBy=poweroff.target shutdown.target
Save and exit, then enable the service:
sudo systemctl enable rtc-watchdog.service
The RTC watchdog is now good to go!
Additional config for Raspberry Pi
Edit the bootloader configuration:
sudo -E rpi-eeprom-config --edit
Add the following two lines:
POWER_OFF_ON_HALT=1
WAKE_ON_GPIO=0
Save and exit. This enables the poorly-documented “low power mode” of Raspberry Pi, which supports wake alarms.
References
ChatGPT
https://www.freedesktop.org/software/systemd/man/latest/systemd-halt.service.html
https://askubuntu.com/questions/587639/rtcwake-command-not-found-ubuntu-14-10
https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#real-time-clock-rtc