A simple way to enable the Pinephone to wake itself from sleep (ideally) without root privs.
If you're on a KDE Plasma Mobile PostmarketOS Pinephone, you can also use my shell script and OpenRC init script to have all KClock alarms and timers wake your Pinephone from suspend and ring the alarms.
To run rtcwaker
without root your kernel must 1) support xattrs on your filesystem and 2) support Linux capabilities.
If your kernel doesn't meet either of those requirements, you can always run rtcwaker
as a setuid binary
(see option 2 below in Configuring rtcwaker
) or with sudo.
$ gcc -o rtcwaker rtcwaker.c
There are two ways to setup rtcwaker
such that it will run as a regular (non-root) user.
- Using capabilities (Preferred)
$ sudo setcap cap_wake_alarm+ep /full/path/to/rtcwaker
If you get Operation not supported
or similar, either a) your kernel lacks support for
capabilities, b) your filesystem lacks support for xattrs or is mounted without xattr support, or
c) your kernel is not configured with xattr support for your filesystem.
If you're not sure what the 3 possiblilites mean or how to resolve them, you can always try option 2
- Using setuid (Should be fine for
rtcwaker
)
$ sudo chown root:root rtcwaker
$ sudo chmod u+s rtcwaker
To have the Pinephone wake from suspend at time 1619387000:
$ ./rtcwaker 1619387000
To run it in the background after you close your shell, you can run:
$ ./rtcwaker 1619387000 & disown
The rtcsync.sh
shell script fetches the next timer or alarm from Plasma Mobile's KClock
and tells rtcwaker
to wake the phone at that time so the alarm can ring.
If you're on PostmarketOS, feel free to also use the rtcsyncwake
init script to start this
process automatically.
- qdbus
- Plasma Mobile KClock
First, set RTCWAKER
to your rtcwaker
binary. If you placed rtcwaker
in your $PATH
, you
can also set it to just rtcwaker
.
#!/bin/sh
# RTCWAKER=/home/user/rtcwaker
RTCWAKER=/path/to/your/rtcwaker
Next, make it executable and run it
$ chmod +x rtcsync.sh
$ ./rtcsync.sh
Found DBUS session bus address: ...
First, set command
to your rtcsync.sh
shell script, and switch command_user
to your user.
Note: this should probably be the same user who's running KDE
#!/sbin/openrc-run
...
# command="/home/user/rtcsync.sh"
command="/path/to/your/rtcsync.sh"
command_background=true
# command_user="user:user"
command_user="your-user:your-user"
pidfile= ...
...
Next move it to /etc/init.d/
, make it executable, and add it to OpenRC's default runlevel
$ sudo cp rtcsyncwake /etc/init.d/
$ sudo chmod +x /etc/init.d/rtcsyncwake
$ sudo rc-update add rtcsyncwake default
You'll probably find those answers on my blog.
./rtcwaker [TIMESTAMP_1] & ./rtcwaker [TIMESTAMP_2] &
ps -a | grep rtcwaker
rtcwaker
only schedules a wakeup from the hardware clock - it doesn't contain any code to play an alarm sound.
If you're on Plasma Mobile, rtcsync.sh
can be used to synchronise the hardware wakeup with KClock's scheduled
alarms and timers. I.e., rtcwaker
wakes the phone, and KClock rings the alarm.
I wanted rtcwaker
to be useful for more than just alarms. For example, if you wanted to implement a
"wake up and fetch notifications regularly" feature, you could write a script to spawn an
rtcwaker
process every 5 minutes.
Also, KClock already does an awesome job at ringing alarms.
You're probably missing qdbus
, or you're running Plasma Mobile without dbus (? is this even possible?). Try
installing qdbus
, and making sure dbus is running.
I'm not running PostmarketOS / I'm running Manjaro KDE Plasma Mobile, but I really want to use your scripts! How can I do so?
Follow the installation instructions above for rtcwaker
and rtcsync.sh
. Then create a systemd service to start
rtcsync.sh
as your user (with User=
and optionally Group=
).
Ideally, schedule it to start after KDE has started (probably multi-user.target
).
By the way, systemd system timers can already wake the Pinephone from suspend, so you could also consider just using systemd alone instead. Check out the fantastic wake-mobile if you're curious.
I tried Phosh a few times but never really got into it. rtcwaker
will still wake your phone at whatever time you
ask it to, but you'll have to synchronise Gnome Clock alarms with rtcwaker
one way or another.
Also note that this issue is still open in the Mobian Gitlab repo. Phosh has an odd habit of not going back into suspend if woken up by the rtc... YMMV. Also, check out wake-mobile.