2015-04-08 22:16:20 +02:00
|
|
|
#!/bin/bash
|
|
|
|
BUTTONPIN=25
|
|
|
|
BUZZERURL="$(cat "$(dirname "$0")"/secret.txt)/state.xml?relay1State=2&pulseTime1=5"
|
|
|
|
BUZZERSTATUSURL="$(cat "$(dirname "$0")"/secret.txt)/state.xml"
|
2015-05-02 01:58:10 +02:00
|
|
|
ATTENUATION=4
|
2015-04-08 22:16:20 +02:00
|
|
|
# file secret.txt should contain username:password
|
2015-05-11 22:50:29 +02:00
|
|
|
cd $(dirname "$0")
|
2015-04-08 22:16:20 +02:00
|
|
|
|
2015-05-11 22:50:29 +02:00
|
|
|
showleds() {
|
|
|
|
./redi.sh <<EOF
|
2016-03-24 23:33:11 +01:00
|
|
|
valid=no
|
2015-05-11 22:50:29 +02:00
|
|
|
neoaction=$1
|
|
|
|
neored=$2
|
|
|
|
neogreen=$3
|
|
|
|
neoblue=$4
|
2016-03-24 23:33:11 +01:00
|
|
|
neovalue=$5
|
|
|
|
valid=yes
|
2015-05-11 22:50:29 +02:00
|
|
|
EOF
|
|
|
|
# sudo kill $(ps -edf| awk '/[s]etneocolor.py/{print $2}' ) 2>/dev/null
|
|
|
|
# sudo python /home/pi/doorbuzz/setneocolor.py $1 $2 $3 $4
|
|
|
|
}
|
2015-04-08 22:16:20 +02:00
|
|
|
# install by putting into /etc/rc.local
|
2015-05-02 01:58:10 +02:00
|
|
|
# su pi -c '/home/pi/doorbuzz/buzzctrl.sh' &
|
2015-04-08 22:16:20 +02:00
|
|
|
|
|
|
|
echo "Initializing hardware"
|
|
|
|
# the button
|
|
|
|
gpio -g mode $BUTTONPIN up
|
|
|
|
gpio -g mode $BUTTONPIN in
|
|
|
|
|
|
|
|
pulseon() {
|
2015-05-02 01:58:10 +02:00
|
|
|
red=$1
|
|
|
|
green=$2
|
|
|
|
blue=$3
|
2015-05-11 22:50:29 +02:00
|
|
|
showleds pulse $((red/ATTENUATION)) $((green/ATTENUATION)) $((blue/ATTENUATION)) </dev/null >/dev/null 2>&1 &
|
2015-05-02 01:58:10 +02:00
|
|
|
echo $!
|
2015-04-08 22:16:20 +02:00
|
|
|
}
|
|
|
|
pulseoff() {
|
2015-05-02 01:58:10 +02:00
|
|
|
if [ $(ps -edf | grep pulse | grep "$1"|wc -l) -gt 0 ]
|
|
|
|
then
|
|
|
|
sudo kill "$1"
|
|
|
|
fi
|
2015-04-08 22:16:20 +02:00
|
|
|
}
|
|
|
|
ledcolor() {
|
|
|
|
red=$1
|
|
|
|
green=$2
|
|
|
|
blue=$3
|
2015-05-11 22:50:29 +02:00
|
|
|
showleds set $((red/ATTENUATION)) $((green/ATTENUATION)) $((blue/ATTENUATION))
|
2015-04-08 22:16:20 +02:00
|
|
|
}
|
|
|
|
declare -a morse
|
|
|
|
morse[0]="-----"
|
|
|
|
morse[1]=".----"
|
|
|
|
morse[2]="..---"
|
|
|
|
morse[3]="...--"
|
|
|
|
morse[4]="....-"
|
|
|
|
morse[5]="....."
|
|
|
|
morse[6]="-...."
|
|
|
|
morse[7]="--..."
|
|
|
|
morse[8]="---.."
|
|
|
|
morse[9]="----."
|
|
|
|
morseled() {
|
|
|
|
message=$1
|
2016-03-24 23:33:11 +01:00
|
|
|
logger $0 morseled $message
|
2015-04-08 22:16:20 +02:00
|
|
|
msglen=${#message}
|
|
|
|
pos=0
|
2015-05-02 01:58:10 +02:00
|
|
|
morsecode=""
|
2015-04-08 22:16:20 +02:00
|
|
|
while [ $pos -lt $msglen ]
|
|
|
|
do
|
2015-05-02 01:58:10 +02:00
|
|
|
morsecode="$morsecode ${morse[${message:${pos}:1}]}"
|
2015-04-08 22:16:20 +02:00
|
|
|
pos=$((pos+1))
|
|
|
|
echo $morsecode
|
|
|
|
done
|
2015-05-02 01:58:10 +02:00
|
|
|
red=$2
|
|
|
|
green=$3
|
|
|
|
blue=$4
|
2015-05-11 22:50:29 +02:00
|
|
|
showleds morse $((red/ATTENUATION)) $((green/ATTENUATION)) $((blue/ATTENUATION)) "$morsecode"
|
2015-05-02 01:58:10 +02:00
|
|
|
|
|
|
|
echo
|
2015-04-08 22:16:20 +02:00
|
|
|
}
|
2016-03-24 23:33:11 +01:00
|
|
|
dialcode() {
|
|
|
|
# shows number code on clock dial
|
|
|
|
message=$1
|
|
|
|
logger $0 dialcode $message
|
|
|
|
msglen=${#message}
|
|
|
|
pos=0
|
|
|
|
while [ $pos -lt $msglen ]
|
|
|
|
do
|
|
|
|
dcode="${message:${pos}:1}"
|
|
|
|
dcode=$((dcode*5)) # convert numbers into clock values
|
|
|
|
pos=$((pos+1))
|
|
|
|
echo $dcode
|
|
|
|
red=$2
|
|
|
|
green=$3
|
|
|
|
blue=$4
|
|
|
|
showleds set 0 0 0
|
|
|
|
showleds number $((red/ATTENUATION)) $((green/ATTENUATION)) $((blue/ATTENUATION)) "$dcode"
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
showleds set 0 0 0
|
|
|
|
}
|
2015-04-08 22:16:20 +02:00
|
|
|
|
2016-03-24 23:33:11 +01:00
|
|
|
logger $0 "morsing IP"
|
|
|
|
#morseled "$(hostname -I|awk -F. '{sub(" ","",$NF);printf $NF}')" 255 0 0
|
|
|
|
dialcode "$(hostname -I|awk -F. '{sub(" ","",$NF);printf $NF}')" 255 0 0
|
|
|
|
sleep 1
|
|
|
|
logger $0 "Main loop"
|
2015-04-08 22:16:20 +02:00
|
|
|
while true
|
|
|
|
do
|
2016-03-24 23:33:11 +01:00
|
|
|
#ledcolor 0 255 255
|
2015-05-02 01:58:10 +02:00
|
|
|
pulsepid=$(pulseon 0 0 255 )
|
2015-05-11 22:50:29 +02:00
|
|
|
trap "ledcolor 0 0 0;exit" 1 2 3
|
2015-04-08 22:16:20 +02:00
|
|
|
gpio -g wfi $BUTTONPIN falling
|
|
|
|
while [ $(gpio -g read $BUTTONPIN) != 0 ]
|
|
|
|
do
|
|
|
|
gpio -g wfi $BUTTONPIN falling
|
|
|
|
done
|
2015-05-02 01:58:10 +02:00
|
|
|
ledcolor 0 255 255
|
2016-03-24 23:33:11 +01:00
|
|
|
logger $0 "Big Red Button pushed"
|
2015-04-08 22:16:20 +02:00
|
|
|
wget -O - -S --timeout=1 --tries=1 "$BUZZERURL" 2>&1
|
|
|
|
ret=$?
|
|
|
|
if [ $ret -ne 0 ]
|
|
|
|
then
|
2016-03-24 23:33:11 +01:00
|
|
|
#morseled "$ret" 255 0 0
|
|
|
|
dialcode "$ret" 255 0 0
|
2015-05-11 22:50:29 +02:00
|
|
|
sleep 5
|
2015-04-08 22:16:20 +02:00
|
|
|
else
|
|
|
|
while wget -O - --timeout=1 --tries=1 $BUZZERSTATUSURL|grep '<relay1state>1</relay1state>'
|
|
|
|
do
|
2015-05-02 01:58:10 +02:00
|
|
|
ledcolor 0 255 0
|
2015-04-08 22:16:20 +02:00
|
|
|
sleep 0.9
|
2015-05-02 01:58:10 +02:00
|
|
|
ledcolor 0 255 255
|
2015-04-08 22:16:20 +02:00
|
|
|
sleep 0.1
|
|
|
|
done
|
|
|
|
fi
|
2016-03-24 23:33:11 +01:00
|
|
|
logger $0 "button push action finished"
|
2015-04-08 22:16:20 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
|