Created
October 14, 2013 19:56
-
-
Save dt/6981235 to your computer and use it in GitHub Desktop.
lightup script
This file contains 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-davidt-staging.foursquare.com/norep.id` | |
echo "`date` starting up..." | |
echo "`date` initial id: $LAST" | |
killfile=/opt/watcher.kill | |
if [ -f "$killfile" ]; then | |
rm "$killfile" | |
fi | |
COUNTER=0 | |
echo 0 > /sys/class/gpio/gpio18/value | |
sleep 1 | |
echo 1 > /sys/class/gpio/gpio18/value | |
while [ ! -f "$killfile" ]; do | |
ID=`curl -s https://api-davidt-staging.foursquare.com/norep.id` | |
if [ -z "$ID" ]; then | |
echo "" | |
echo "`date` skipping blank ID" | |
ID="$LAST" | |
fi | |
if [ "$ID" != "$LAST" ]; then | |
echo "" | |
echo "`date` changed: $LAST -> $ID" | |
echo 0 > /sys/class/gpio/gpio18/value | |
sleep 8 | |
echo 1 > /sys/class/gpio/gpio18/value | |
COUNTER=0 | |
else | |
COUNTER=$(((COUNTER + 1) % 3600)) | |
if [ $COUNTER -eq 0 ]; then | |
echo "`date` still waiting..." | |
fi | |
if [ $((COUNTER % 30)) -eq 0 ]; then | |
printf "." | |
fi | |
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