Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # programado por Juanmol para http://rsppi.blogspot.com
- RESPONSE=/tmp/webresp
- log=/var/log/pixel-access.log
- status=/tmp/estados.led
- leds2=/tmp/leds2.sh
- temp=/tmp/estados.led.tmp
- num_leds=50
- max=ff
- [ -p $RESPONSE ] || mkfifo $RESPONSE
- while true ;
- do
- ( cat $RESPONSE ) | nc -l -p 8080 | (
- REQUEST=`while read L && [ " " "<" "$L" ] ; do echo "$L" ; done`
- REQ="`echo \"$REQUEST\" | head -n 1`"
- pixel=$(echo $REQ | cut -f3 -d\/ | cut -f1 -d\ )
- if [ "$(cat $status | grep ^$pixel\ | wc -l)" -eq "1" ] || [ $pixel = reset ];
- then
- echo "[ `date '+%Y-%m-%d %H:%M:%S'` ] $REQ" >>$log
- if [[ $REQ =~ ^GET\ /pixel[\ \/\#?] ]]; then
- estado=$(echo $REQ | cut -f4 -d\/ | cut -f1 -d\ )
- case $estado in
- 1 )
- color="\\\\x$max\\\\x00\\\\x00"
- ;;
- 2 )
- color="\\\\x00\\\\x$max\\\\x00"
- ;;
- 3 )
- color="\\\\x00\\\\x00\\\\x$max"
- ;;
- 4 )
- color="\\\\x$max\\\\x$max\\\\x00"
- ;;
- 5 )
- color="\\\\x$max\\\\x00\\\\x$max"
- ;;
- 6 )
- color="\\\\x00\\\\x$max\\\\x$max"
- ;;
- 7 )
- color="\\\\x$max\\\\x$max\\\\x$max"
- ;;
- * )
- color="\\\\x00\\\\x00\\\\x00"
- ;;
- esac
- cat $status | sed "s/^"$pixel"\ .*/"$pixel"\ "$color"/g" > $temp
- cp $temp $status
- fi
- if [ $(echo $pixel) = reset ];
- then
- rm $status;
- for n in $(seq 1 $[$num_leds+1]);
- do
- echo $n\ \\\\x00\\\\x00\\\\x00 >> $status;
- done
- fi
- cat $status | awk '{ print $2 }' | sed 's/^\\/echo\ \-ne\ \"\\/g' | tr "\n" "\"" | sed 's/\"e/\"\ \> \/dev\/spidev0\.0\ \&\&\ e/g' | sed 's/\"\"/\"\ \> \/dev\/spidev0\.0/g' > $leds2;
- /bin/bash $leds2;
- fi
- cat >$RESPONSE <<EOF
- HTTP/1.0 200 OK
- Cache-Control: no-cache
- Content-Type: text/html
- Server: bash/2.0
- Connection: Close
- Content-Length: 0
- EOF
- )
- done
Advertisement
Add Comment
Please, Sign In to add comment