Skip to content

Instantly share code, notes, and snippets.

@mwvent
Created February 20, 2020 17:26
Show Gist options
  • Save mwvent/fd9e489551fd72adb86a3aa1bdc93b61 to your computer and use it in GitHub Desktop.
Save mwvent/fd9e489551fd72adb86a3aa1bdc93b61 to your computer and use it in GitHub Desktop.
LAN home events - sending and listenting for UDP broadcasts
# Example broadcast command triggered in my case by the RPi doorbell
echo "doorbell" | socat - UDP-DATAGRAM:255.255.255.255:12345,broadcast
# Script to listen for UDP broadcasts from doorbell computer
# and play a sound on doorbell press or pir motion
# Installed on the X96-mini TV box that we use as a camera monitor
# under /data/mwvent/soundPlayer/service.sh
# required socat binary ( found online static arm build ) to be placed
# in /system/bin/socat
# The script is called at boot by hijacking an existing boot script
# in this case I added the following line to /system/bin/preinstall.sh
# /data/mwvent/soundPlayer/service.sh &
socat -u udp-recv:12345 - | while read LN; do
echo "Got $LN"
case "$LN" in
doorbell)
tinyplay "/data/mwvent/soundPlayer/doorbell.wav"
;;
pir_door)
tinyplay "/data/mwvent/soundPlayer/motion.wav"
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment