Best way to wake up and check emails?
#1
Hello all

I'm impressed with the ability to wake up from suspend/crust when a phone call or text comes in. But this won't work for email.

I'm looking for the best way to have the PinePhone wake up every 30 minutes, check email/matrix/signal/etc, then go back to sleep.

I've had some luck with systemd timers, but I haven't been able to work this into a complete solution. I'll stop here for brevity and post another post with more info on my partial solution.

Thank you

[EDIT 2022/05/24:] I did eventually get a hackish version of this to work. See post number https://forum.pine64.org/showthread.php?...0#pid98450 for how I did it.
  Reply
#2
(08-01-2021, 06:22 AM)DrPlamsa Wrote: Hello all

I'm impressed with the ability to wake up from suspend/crust when a phone call or text comes in. But this won't work for email.

I'm looking for the best way to have the PinePhone wake up every 30 minutes, check email/matrix/signal/etc, then go back to sleep.

I've had some luck with systemd timers, but I haven't been able to work this into a complete solution. I'll stop here for brevity and post another post with more info on my partial solution.

Thank you

This is probably something that needs to be built into the production build; wake, connect to internet, check email and IMs, verify complete tasks, sleep......
Maybe do it off of the hour/half-hour to avoid the slowdown of other apps or go random with average of 30 or 60 min between checks.
  Reply
#3
Here, I'll discuss what I've already accomplished. I found that systemd timers can wake up the PinePhone from suspend/crust. For testing purposes, I've used sytemd-run rather than making new .timer and .service files, because of its simplicity. Here's my one-line command which sets a wake timer:

sudo systemd-run --unit='WakeTimer' --on-active=1 --on-unit-active='30m' --timer-property='AccuracySec=1s' --timer-property='WakeSystem=true' /bin/sh -c "date >> /home/[user]/Desktop/MyWakeLog.txt"

So, what is supposed to happen?
1) After 5 minutes, the PinePhone goes into suspend/crust
2) After 30 minutes, the PinePhone wakes up, automatically checks email and chats, and serves any notifications
3) After 5 minutes, the PinePhone goes back into suspend/crust to save battery

Here's what actually happens:
1) After 5 minutes, the PinePhone goes into suspend/crust
2) After 30 minutes, the PinePhone wakes up!
3) The screen stays on, and it never goes back into suspend/crust
4) The battery runs down and it dies

So, does anyone know of either a way of fixing my existing incomplete solution, or a better way of implementing this behavior?

I've tried using xdotool to send a key press, in the hope that this will reset the idle timer and allow the phone to re-suspend after 5 minutes, but xdotool does not seem to actually produce any results on the PinePhone. I've tried using gdbus to call the org.gnome.Mutter.IdleMonitor.GetIdletime method, which works on my desktop but on the PinePhone returns "Not supported." I've tried using gdbus to call the org.gnome.Mutter.IdleMonitor.ResetIdletime method, but this method apparently requires a specific compiler directive to work.

Thanks for your attention and input
  Reply
#4
Hello all. I've made some modest progress.

The script can be made to programmatically turn off the screen to save battery by the addition of this gdbus call to Mutter DisplayConfig:
gdbus call --session --dest org.gnome.Mutter.DisplayConfig --object-path /org/gnome/Mutter/DisplayConfig --method org.freedesktop.DBus.Properties.Set "org.gnome.Mutter.DisplayConfig" "PowerSaveMode" "<int32 3>"

Then it can be made to programmatically suspend again by calling "systemctl suspend" after some delay.

I speculate that a more complete solution:
1) Starts a timer just before suspending, using systemd's /lib/systemd/system-sleep/.
2) This timer wakes up after 30 min and immediately turns off the screen using the gdbus call above. Then it starts a timer to re-suspend after 1 minute.
3) If the user unlocks the phone during this timer, it is deactivated.

I'll post again with my progress.
  Reply
#5
(08-01-2021, 06:29 AM)DrPlamsa Wrote: Here, I'll discuss what I've already accomplished. I found that systemd timers can wake up the PinePhone from suspend/crust. For testing purposes, I've used sytemd-run rather than making new .timer and .service files, because of its simplicity. Here's my one-line command which sets a wake timer:

sudo systemd-run --unit='WakeTimer' --on-active=1 --on-unit-active='30m'  --timer-property='AccuracySec=1s' --timer-property='WakeSystem=true' /bin/sh -c "date >> /home/[user]/Desktop/MyWakeLog.txt"

So, what is supposed to happen?
1) After 5 minutes, the PinePhone goes into suspend/crust
2) After 30 minutes, the PinePhone wakes up, automatically checks email and chats, and serves any notifications
3) After 5 minutes, the PinePhone goes back into suspend/crust to save battery

Here's what actually happens:
1) After 5 minutes, the PinePhone goes into suspend/crust
2) After 30 minutes, the PinePhone wakes up!
3) The screen stays on, and it never goes back into suspend/crust
4) The battery runs down and it dies

So, does anyone know of either a way of fixing my existing incomplete solution, or a better way of implementing this behavior?

I've tried using xdotool to send a key press, in the hope that this will reset the idle timer and allow the phone to re-suspend after 5 minutes, but xdotool does not seem to actually produce any results on the PinePhone. I've tried using gdbus to call the org.gnome.Mutter.IdleMonitor.GetIdletime method, which works on my desktop but on the PinePhone returns "Not supported." I've tried using gdbus to call the org.gnome.Mutter.IdleMonitor.ResetIdletime method, but this method apparently requires a specific compiler directive to work.

Thanks for your attention and input
For what it's worth, I think xdotool doesn't work because it doesn't work on Wayland and Phosh uses Wayland. But also, if you happen to find something like xdotools for wayland I would love to hear about it because I just need a single right click but usb tethering isn't working for me so I am just stuck waiting until the next kernel upgrade which hopefully fixes it.
  Reply
#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
#7
@a-wai, did the ability to wake up from sleep to check emails ever get into the main branch? If not, I'll keep using this hack. Thanks
  Reply
#8
I've done some more asking around and summarized the latest results here: https://forum.pine64.org/showthread.php?...#pid115212
  Reply


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

Forum Jump:


Users browsing this thread: 1 Guest(s)