mobile-linux-push-notifications: show how to integrate with SXMO
This commit is contained in:
parent
44fab94efa
commit
bfac21d5de
|
@ -240,7 +240,60 @@ i've only authored this module to alert me on jingle calls. one could presumably
|
|||
[mod_ntfy_push]: https://git.uninsane.org/colin/nix-files/src/commit/01de6f84cfc2291092a6809e61339e992f9b97b4/hosts/by-name/servo/services/prosody/modules/mod_sane_ntfy.lua
|
||||
[mod_ntfy_push_mirror]: mod_sane_notify.lua
|
||||
|
||||
### Pinephone Wowlan Race Condition
|
||||
|
||||
## SXMO Integration
|
||||
|
||||
[SXMO][sxmo] is a mobile-friendly Linux desktop notable for being extremely hackable (it's really just a collection of shell scripts layered over [sway][sway]), and as such we can integrate all the client-side work we did above into something the desktop environment handles for us transparently.
|
||||
|
||||
SXMO includes an [`autosuspend`][sxmo_autosuspend.sh] service. it's just a bash `while` loop that periodically checks if conditions are suitable to sleep the phone (is the screen off, is the user not in a call, are no media players active, and so on) and if so, calls out to `sxmo_suspend.sh`.
|
||||
|
||||
[`sxmo_suspend.sh`][sxmo_suspend.sh] looks like this (simplified -- it does a little more to make cronjobs reliable)
|
||||
|
||||
```bash
|
||||
suspend_time=99999999 # far away
|
||||
sxmo_log "calling suspend with suspend_time <$suspend_time>"
|
||||
|
||||
doas rtcwake -m mem -s "$suspend_time" || exit 1
|
||||
|
||||
sxmo_hook_postwake.sh
|
||||
```
|
||||
|
||||
since the different components of SXMO communicate by shelling out to each other, we can patch it just by putting our own `sxmo_suspend.sh` script somewhere on the PATH. that's intentional behavior: SXMO goes out of its way to add `~/.config/sxmo/hooks` as a PATH entry to its services, so we can just drop a file like this into `~/.config/sxmo/hooks/sxmo_suspend.sh`:
|
||||
|
||||
```bash
|
||||
ntfy sub TEST_WOWLAN_TOPIC &
|
||||
NTFY_PID=$!
|
||||
|
||||
port=
|
||||
while [ -z "$port" ]; do
|
||||
# netstat output will look like:
|
||||
# tcp 0 0 127.0.0.1:12345 10.11.12.13:443 ESTABLISHED 2798004/ntfy
|
||||
# pipe through sed/cut to extract the `12345` local port component
|
||||
# do this in a loop to allow time for ntfy to establish the connection
|
||||
port="$(netstat --tcp --program --numeric-ports | grep ntfy | sed 's/ */ /g' | cut -d' ' -f 4 | cut -d':' -f2)"
|
||||
done
|
||||
|
||||
# configure to wake on any traffic to that ntfy connection
|
||||
rtl8723cs-wowlan enable-clean
|
||||
rtl8723cs-wowlan tcp --src-port "$port"
|
||||
|
||||
sxmo_log "calling suspend with suspend_time 600"
|
||||
doas rtcwake -m mem -s 600 || exit 1
|
||||
kill $NTFY_PID
|
||||
sxmo_hook_postwake.sh
|
||||
|
||||
wait # for ntfy to exit
|
||||
```
|
||||
|
||||
and that's it. use your phone as you normally would, and everything should be the same except that now it'll wake up whenever you get a Matrix/XMPP/ntfy notification.
|
||||
|
||||
[sxmo]: https://sxmo.org/
|
||||
[sway]: https://swaywm.org/
|
||||
[sxmo_autosuspend.sh]: https://git.sr.ht/~mil/sxmo-utils/tree/master/item/scripts/core/sxmo_autosuspend.sh
|
||||
[sxmo_suspend.sh]: https://git.sr.ht/~mil/sxmo-utils/tree/master/item/scripts/core/sxmo_suspend.sh
|
||||
|
||||
|
||||
## Pinephone Wowlan Race Condition
|
||||
|
||||
as alluded, sending a wake packet within about a second of sending the SoC to sleep will fail to wake the system. worse, the SoC will be _stuck_ in the sleep state, not waking on any _future_ wake packets (you can still wake it via the power button, and it should behave correctly during the next sleep cycle). one can imagine lots of ways an edge-triggered interrupt could be misimplemented to cause this type of race, but i wasn't able to diagnose it any more than this.
|
||||
|
||||
|
|
Loading…
Reference in New Issue