Skip to content

Instantly share code, notes, and snippets.

@dt
Last active December 18, 2015 12:49
Show Gist options
  • Save dt/5785982 to your computer and use it in GitHub Desktop.
Save dt/5785982 to your computer and use it in GitHub Desktop.
light-on-new-thing.sh
#!/bin/bash
echo 18 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio18/direction
echo 1 > /sys/class/gpio/gpio18/value
LAST=`curl -s https://api-davidtaylor-staging.foursquare.com/latest.id`
echo 0 > /sys/class/gpio/gpio18/value
sleep 2
echo 1 > /sys/class/gpio/gpio18/value
echo "waiting..."
killfile=/opt/watcher.kill
if [ -f "$killfile" ]; then
rm "$killfile"
fi
while [ ! -f "$killfile" ]; do
ID=`curl -s https://api-davidtaylor-staging.foursquare.com/latest.id`
if [ -z "$ID" ]; do
ID="$LAST"
fi
if [ "$ID" != "$LAST" ]; then
echo "changed: $LAST -> $ID"
echo 0 > /sys/class/gpio/gpio18/value
sleep 10
echo 1 > /sys/class/gpio/gpio18/value
fi
LAST="$ID"
sleep 1
done
echo "exiting due to kill file"
rm "$killfile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment