first commit based on running system
parent
8f5104ee80
commit
b59c94ccbf
40
README.md
40
README.md
|
@ -1,2 +1,42 @@
|
||||||
# doorbuzz
|
# doorbuzz
|
||||||
raspberry Pi opening the front door and playing videos
|
raspberry Pi opening the front door and playing videos
|
||||||
|
the button has an RGB led to show status
|
||||||
|
|
||||||
|
how to install
|
||||||
|
==============
|
||||||
|
put into /etc/rc.local the following line:
|
||||||
|
su pi -c '/home/pi/buzzctrl.sh' &
|
||||||
|
|
||||||
|
sudo vi /etc/xdg/lxsession/LXDE/autostart
|
||||||
|
remove screensaver
|
||||||
|
sudo apt-get install unclutter xdotool git-core screen imagemagick
|
||||||
|
git clone git://git.drogon.net/wiringPi
|
||||||
|
cd wiringPi
|
||||||
|
./build
|
||||||
|
|
||||||
|
mkdir -p /home/pi/.config/lxsession/LXDE/
|
||||||
|
cat > /home/pi/.config/lxsession/LXDE/autostart <<"EOF"
|
||||||
|
@xset s off
|
||||||
|
@xset -dpms
|
||||||
|
@xset s noblank
|
||||||
|
@unclutter -display :0 -noevents -grab
|
||||||
|
@./videoplayer.sh
|
||||||
|
EOF
|
||||||
|
|
||||||
|
|
||||||
|
connect the button and LED to pins as shown in buzzctrl.sh
|
||||||
|
create a file "secret.txt" containing the http://user:pass@10.1.1.xx part of the URL
|
||||||
|
adapt the URL in buzzctrl.sh
|
||||||
|
adapt spaceapi URL in spacestatus.py
|
||||||
|
put .mp4 videos into ~pi/ and they will show when your hackerspace is open
|
||||||
|
you can add videos and they will be taken into account automatically
|
||||||
|
|
||||||
|
when booting, the button led uses morsecode to send the low byte of the
|
||||||
|
IP adress in decimal
|
||||||
|
|
||||||
|
todo
|
||||||
|
====
|
||||||
|
create a config file
|
||||||
|
put more of the hardcoded values from code into parameters
|
||||||
|
make code resilient against missing commands (e.g. gpio not in PATH)
|
||||||
|
move script to run in screen instead starting from rc.local
|
||||||
|
|
|
@ -0,0 +1,140 @@
|
||||||
|
#!/bin/bash
|
||||||
|
BUTTONPIN=25
|
||||||
|
REDLEDPIN=23
|
||||||
|
GREENLEDPIN=18
|
||||||
|
BLUELEDPIN=24
|
||||||
|
BUZZERURL="$(cat "$(dirname "$0")"/secret.txt)/state.xml?relay1State=2&pulseTime1=5"
|
||||||
|
BUZZERSTATUSURL="$(cat "$(dirname "$0")"/secret.txt)/state.xml"
|
||||||
|
|
||||||
|
# file secret.txt should contain username:password
|
||||||
|
|
||||||
|
# install by putting into /etc/rc.local
|
||||||
|
# su pi -c '/home/pi/buzzctrl.sh' &
|
||||||
|
|
||||||
|
echo "Initializing hardware"
|
||||||
|
# the button
|
||||||
|
gpio -g mode $BUTTONPIN up
|
||||||
|
gpio -g mode $BUTTONPIN in
|
||||||
|
# R
|
||||||
|
gpio -g mode $REDLEDPIN out
|
||||||
|
# G
|
||||||
|
gpio -g mode $GREENLEDPIN out
|
||||||
|
# B
|
||||||
|
gpio -g mode $BLUELEDPIN out
|
||||||
|
|
||||||
|
pulseon() {
|
||||||
|
pin=$1
|
||||||
|
value=0
|
||||||
|
valueinc=64
|
||||||
|
gpio -g mode $pin pwm
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
gpio -g pwm $pin $value
|
||||||
|
value=$((value+valueinc))
|
||||||
|
if [ $value -gt 1023 ] || [ $value -lt 0 ]
|
||||||
|
then
|
||||||
|
valueinc=$((0-valueinc))
|
||||||
|
value=$((value+valueinc))
|
||||||
|
fi
|
||||||
|
sleep 0.2
|
||||||
|
done
|
||||||
|
}
|
||||||
|
pulseoff() {
|
||||||
|
pin=$1
|
||||||
|
kill $2
|
||||||
|
gpio -g mode $pin out
|
||||||
|
gpio -g write $pin 0
|
||||||
|
}
|
||||||
|
ledcolor() {
|
||||||
|
red=$1
|
||||||
|
green=$2
|
||||||
|
blue=$3
|
||||||
|
gpio -g write $REDLEDPIN $red
|
||||||
|
gpio -g write $GREENLEDPIN $green
|
||||||
|
gpio -g write $BLUELEDPIN $blue
|
||||||
|
}
|
||||||
|
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
|
||||||
|
echo $message
|
||||||
|
msglen=${#message}
|
||||||
|
pos=0
|
||||||
|
while [ $pos -lt $msglen ]
|
||||||
|
do
|
||||||
|
morsecode=${morse[${message:${pos}:1}]}
|
||||||
|
pos=$((pos+1))
|
||||||
|
echo $morsecode
|
||||||
|
morselen=${#morsecode}
|
||||||
|
morsepos=0
|
||||||
|
while [ $morsepos -lt $morselen ]
|
||||||
|
do
|
||||||
|
ledcolor $2 $3 $4
|
||||||
|
#echo "c($morsepos)=${morsecode:${morsepos}:1}"
|
||||||
|
if [ "${morsecode:${morsepos}:1}" = "." ]
|
||||||
|
then
|
||||||
|
#echo "."
|
||||||
|
sleep 0.1
|
||||||
|
else
|
||||||
|
#echo "-"
|
||||||
|
sleep 0.2
|
||||||
|
fi
|
||||||
|
ledcolor 0 0 0
|
||||||
|
sleep 0.1
|
||||||
|
morsepos=$((morsepos+1))
|
||||||
|
done
|
||||||
|
sleep 0.2
|
||||||
|
echo
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "morsing IP"
|
||||||
|
ledcolor 1 1 1
|
||||||
|
sleep 3
|
||||||
|
ledcolor 0 0 0
|
||||||
|
sleep 1
|
||||||
|
morseled "$(hostname -I|awk -F. '{sub(" ","",$NF);printf $NF}')" 1 0 0
|
||||||
|
ledcolor 1 1 1
|
||||||
|
sleep 1
|
||||||
|
echo "Main loop"
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
ledcolor 0 1 1
|
||||||
|
pulseon $GREENLEDPIN &
|
||||||
|
pulsepid=$!
|
||||||
|
trap "pulseoff $GREENLEDPIN $pulsepid;ledcolor 0 0 0;exit" 1 2 3
|
||||||
|
gpio -g wfi $BUTTONPIN falling
|
||||||
|
while [ $(gpio -g read $BUTTONPIN) != 0 ]
|
||||||
|
do
|
||||||
|
gpio -g wfi $BUTTONPIN falling
|
||||||
|
done
|
||||||
|
pulseoff $GREENLEDPIN $pulsepid
|
||||||
|
ledcolor 0 1 1
|
||||||
|
echo "Pushiii"
|
||||||
|
wget -O - -S --timeout=1 --tries=1 "$BUZZERURL" 2>&1
|
||||||
|
ret=$?
|
||||||
|
if [ $ret -ne 0 ]
|
||||||
|
then
|
||||||
|
morseled "$ret" 1 0 0
|
||||||
|
else
|
||||||
|
while wget -O - --timeout=1 --tries=1 $BUZZERSTATUSURL|grep '<relay1state>1</relay1state>'
|
||||||
|
do
|
||||||
|
ledcolor 0 1 0
|
||||||
|
sleep 0.9
|
||||||
|
ledcolor 0 1 1
|
||||||
|
sleep 0.1
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
echo "DOOONE"
|
||||||
|
done
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
import urllib, json
|
||||||
|
url = "https://spaceapi.syn2cat.lu/status/json"
|
||||||
|
response = urllib.urlopen(url);
|
||||||
|
data = json.loads(response.read())
|
||||||
|
print data["state"]["open"]
|
|
@ -0,0 +1,21 @@
|
||||||
|
#!/bin/bash
|
||||||
|
if [ ! -f black.png ]
|
||||||
|
then
|
||||||
|
convert -size 1920x1080 xc:#000000 black.png
|
||||||
|
fi
|
||||||
|
killall feh
|
||||||
|
trap "killall feh; killall omxplayer" 1 2 3 15
|
||||||
|
feh -x black.png &
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
if [ "$(python ./spacestatus.py)" = "False" ]
|
||||||
|
then # test on false, so in case of network fail, it defaults to playing
|
||||||
|
sleep 60
|
||||||
|
else
|
||||||
|
ls *mp4 |
|
||||||
|
while read video
|
||||||
|
do
|
||||||
|
omxplayer "$video" </dev/null
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
done
|
Loading…
Reference in New Issue