Last active
December 18, 2015 12:49
-
-
Save dt/5785982 to your computer and use it in GitHub Desktop.
light-on-new-thing.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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