UDP answerer and notifier
Goal: On receiving a packet, pause the music and play a notification sound.
Background: When I have headphones on, I am oblivious to someone at the door, or other potential things that are good to be aware of. Being able to accept a usable network signal and turning it into a noticeable alarm would be useful to use in certain applications.
Details: As a test trigger, another computer is used to send a test UDP packet as described here:
echo -n "mot" | nc -4u -w 1 172.21.42.4 42001
Second, we’ll need a script to pause gmusicbrowser, play a sound, and resume playing. Lets call this /opt/motalert:
export DISPLAY=:0.0
gmusicbrowser -cmd PlayPause
mplayer -ao alsa /usr/share/sounds/chirp.ogg >> /home/derek/motest
gmusicbrowser -cmd PlayPause
Note that the export DISPLAY line is necessary for the command run in a system service to carry over into the running instance on the display session, and mplayer’s “-ao alsa” option is needed to properly play the sound from the service-launched script. Finally, as described here, we’ll use xinetd to catch the packet, using the following configuration file:
# /etc/xinetd.d/motrigger service motrigger { disable = no type = UNLISTED socket_type = dgram protocol = udp wait = yes server = /opt/motalert bind = 172.21.42.4 port = 42001 user = derek }
At this point it’s also possible to relay the sound to another computer via the pulseaudio system by adding to our script the following line:
mplayer -ao pulse:172.21.42.3:1 /usr/share/sounds/chirp.ogg