Wednesday, May 04, 2022

Special Delivery: From A Random Linux Box to My Wrist

I've got a phpunit test suite on a Linux server that now takes a few minutes to run. When it's done, I'd like to get a message on my watch telling me whether it completed successfully or not. This let's me kick off the tests and go on to my next task (probably: eating) and will give me just the nudge I need to either return to work on the tests or keep going with the new task.

Here's the recipe I used to accomplish this feat. The goal here is to keep the script that runs on the Linux server nice and simple so that I can move it around to other locations as I decide to spread around this behavior.

The Linux Script

On the Linux side, I've got a simple script that I can invoke like so:

$ phpunit --stop-on-failure tests/ ; andnotify "Test are done! Status: $?"

The magic variable $? will be zero if tests completed without error, or a non-zero value if there was a problem.

The andnotify script is little more than a wrapper around curl which makes a request to Tasker's AutoRemote:


## Send data to an android device using Tasker's Auto Remote
key='<Your AutoRemote Key>'

if [ $# -eq 0 ] ; then
  echo "Usage: `basename $0` message"
  exit 1

echo "Notify=:=$@" > $HOME/.andnotify
curl -s $base -d "key=$key" --data-urlencode "message@$HOME/.andnotify"  > /dev/null

The Tasker Code

andnotify sends a message to the AutoRemote API endpoint, which can be received by a Tasker Profile. The magic happens when you create a profile under: Event » Plugin » AutoRemote.

This profile will receive the text sent via curl above. I'm using the variable %arcomm, which will grab all the text after =:= in the AutoRemote message.

Once the text is received, it's handed to a trivial Tasker Task, which contains a single Notify Action in the body of the task.

The Notify Action causes the message to appear as an Android Notification.

To The Watch

Finally, I've set my Garmin VivoActive 4 up to pass AutoRemote notifications to my watch.

The ensures that notification that are posted to my device, show up on my watch.

No comments:

Post a Comment