Best way to wake up and check emails?
#6
Ok, I have a functional system! It wakes up every 15 minutes to check emails and chats, then if the phone isn't unlocked in one minute it goes back to sleep. The solution consists of the following:
1) SuspendTimer timer and service, which waits 60 seconds then puts the phone to sleep
2) DontSuspendOnUnlock service and script, which starts up automatically and disables SuspendTimer if the phone is unlocked
3) WakeTimer timer, service, and script which wakes the phone every 15 minutes, turns the phone screen off (by default it turns on), then starts the SuspendTimer timer
4) StartWakeTimer script in /lib/systemd/system-sleep/ which starts the WakeTimer timer

Thus, when the phone suspends, on the nearest 15 minutes it wakes up, connects to wifi, checks email and chats, then goes back to sleep. Some important lessons learned along the way were:
- Using gdbus and dbus-monitor to access the user session dbus from root is tricky. That's why you see things like su [username] -c 'dbus-monitor --address "unix:path=/run/user/1000/bus"' etc. The script is going to be run by the system, but it needs to be able to access your user session.
- When the phone starts up as a result of a systemd timer with WakeSystem=true, it wakes into a weird state! The screen comes on, and the idle timers which usually turn the screen off and put it back to sleep are disabled. That's why SuspendTimer has to exist, and why WakeTimer.sh first turns off the screen.
- For some reason, using the regular monotonic clock in WakeTimer.timer didn't work. It would be better to have the phone wake 15 minutes after sleep, rather than on the exact 15 minute point four times per hour, but for some reason it would wake up after 15 minutes then wait *another* 15 minutes to start SuspendTimer if I did this.
- You can absolutely test these by adding "date >> /path/to/a/log.txt" to each script. Then you know when and if they ran. I recommend testing each step in turn; after step 1, do sudo systemctl start SuspendTimer.timer and see if the phone suspends after a minute. If not, something is wrong. After step 2, start the SuspendTimer.timer as before, then log into the phone and check that SuspendTimer stopped using sudo systemctl status SuspendTimer.timer. After step 3, start the WakeTimer manually using sudo systemctl start WakeTimer.timer, then suspend manually using sudo systemctl suspend. See if it wakes up on the 15 minute.
- I am by no means a developer. My day job has nothing to do with linux. Please let me know if there's a better way, or if I did something contraindicated.

Here's how I did it. "[username]" should be replaced with your username, by default "mobian":

1) SuspendTimer timer and service, which waits 60 seconds then puts the phone to sleep

sudo nano /etc/systemd/system/SuspendTimer.service
%%%%%%%%% START BLOCK TO PASTE INTO THAT FILE %%%%%%%%%
[Unit]
Description=Suspend

[Service]
Type=simple
ExecStart=systemctl suspend

[Install]
WantedBy=default.target
%%%%%%%%% END BLOCK TO PASTE INTO THAT FILE %%%%%%%%%

sudo nano /etc/systemd/system/SuspendTimer.timer
%%%%%%%%% START BLOCK TO PASTE INTO THAT FILE %%%%%%%%%
[Timer]
#Run 60 seconds after start
OnActiveSec=60
#Accuracy
AccuracySec=10s

[Install]
WantedBy=timers.target
%%%%%%%%% END BLOCK TO PASTE INTO THAT FILE %%%%%%%%%

2) DontSuspendOnUnlock service and script, which starts up automatically and disables SuspendTimer if the phone is unlocked

sudo touch /usr/local/sbin/DontSuspendOnUnlock.sh
sudo chmod u+x /usr/local/sbin/DontSuspendOnUnlock.sh
sudo nano /usr/local/sbin/DontSuspendOnUnlock.sh
%%%%%%%%% START BLOCK TO PASTE INTO THAT FILE %%%%%%%%%
su [username] -c 'dbus-monitor --address "unix:path=/run/user/1000/bus" "type='signal',interface='org.gnome.ScreenSaver'"' |
while read x; do
case "$x" in
*"boolean false"*) systemctl stop SuspendTimer.timer;systemctl stop WakeTimer.timer;;
esac
done
%%%%%%%%% END BLOCK TO PASTE INTO THAT FILE %%%%%%%%%

sudo nano /etc/systemd/system/DontSuspendOnUnlock.service
%%%%%%%%% START BLOCK TO PASTE INTO THAT FILE %%%%%%%%%
[Unit]
Description=DontSuspendOnUnlock

[Service]
Type=simple
ExecStart=/bin/sh -c /usr/local/sbin/DontSuspendOnUnlock.sh

[Install]
WantedBy=multi-user.target
%%%%%%%%% END BLOCK TO PASTE INTO THAT FILE %%%%%%%%%
Now enable it
sudo systemctl enable DontSuspendOnUnlock.service

3) WakeTimer timer, service, and script which wakes the phone every 15 minutes, turns the phone screen off (by default it turns on), then starts the SuspendTimer timer

sudo touch /usr/local/sbin/WakeTimer.sh
sudo chmod u+x /usr/local/sbin/WakeTimer.sh
sudo nano /usr/local/sbin/WakeTimer.sh
%%%%%%%%% START BLOCK TO PASTE INTO THAT FILE %%%%%%%%%
su [username] -c 'gdbus call --address "unix:path=/run/user/1000/bus" --dest org.gnome.Mutter.DisplayConfig --object-path /org/gnome/Mutter/DisplayConfig --method org.freedesktop.DBus.Properties.Set "org.gnome.Mutter.DisplayConfig" "PowerSaveMode" "<int32 3>"'
systemctl stop SuspendTimer.timer
systemctl start SuspendTimer.timer
%%%%%%%%% END BLOCK TO PASTE INTO THAT FILE %%%%%%%%%

sudo nano /etc/systemd/system/WakeTimer.service
%%%%%%%%% START BLOCK TO PASTE INTO THAT FILE %%%%%%%%%
[Unit]
Description=WakeTimer

[Service]
Type=simple
ExecStart=/bin/sh -c /usr/local/sbin/WakeTimer.sh

[Install]
WantedBy=default.target
%%%%%%%%% END BLOCK TO PASTE INTO THAT FILE %%%%%%%%%

sudo nano /etc/systemd/system/WakeTimer.timer
%%%%%%%%% START BLOCK TO PASTE INTO THAT FILE %%%%%%%%%
[Timer]
#Run on the 15 mins
OnCalendar=*-*-* *:0/15:00
#Accuracy
AccuracySec=1 minute
WakeSystem=true

[Install]
WantedBy=timers.target
%%%%%%%%% END BLOCK TO PASTE INTO THAT FILE %%%%%%%%%

4) StartWakeTimer script in /lib/systemd/system-sleep/ which starts the WakeTimer timer

sudo touch /lib/systemd/system-sleep/StartWakeTimer.sh
sudo chmod u+x /lib/systemd/system-sleep/StartWakeTimer.sh
sudo nano /lib/systemd/system-sleep/StartWakeTimer.sh
%%%%%%%%% START BLOCK TO PASTE INTO THAT FILE %%%%%%%%%
#!/bin/bash
if [ "${1}" == "pre" ]; then
systemctl stop WakeTimer.timer
systemctl start WakeTimer.timer
fi
%%%%%%%%% END BLOCK TO PASTE INTO THAT FILE %%%%%%%%%
  Reply


Messages In This Thread
RE: Best way to wake up and check emails? - by DrPlamsa - 08-07-2021, 07:10 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Unable to wake up from suspend xavi92 6 2,611 07-28-2024, 02:48 PM
Last Post: dchang0
  How to check if tow-boot is installed? jojuma 3 1,756 09-29-2023, 11:29 PM
Last Post: tllim
  Does tow-boot allow periodic wake from suspension to check for notifications? DrPlamsa 4 3,433 12-31-2022, 10:56 AM
Last Post: DrPlamsa
  Is there a smart-wake yet? DrPlamsa 6 3,373 12-31-2022, 10:55 AM
Last Post: DrPlamsa
  How to check which mobian build I am running jojuma 0 952 08-29-2022, 04:44 AM
Last Post: jojuma
  display will not wake up motox6 0 1,402 06-18-2021, 12:43 AM
Last Post: motox6
  Mobian screen won't wake reliably. StridAst 5 5,837 05-05-2021, 12:07 PM
Last Post: motox6
Bug Wake up from charging problem j4n3z 11 11,324 02-25-2021, 03:53 PM
Last Post: j4n3z

Forum Jump:


Users browsing this thread: 1 Guest(s)