Projects/Netlight: verschil tussen versies
< Projects
Geen bewerkingssamenvatting |
|||
| Regel 21: | Regel 21: | ||
Image:Zarya_15776.jpg| | Image:Zarya_15776.jpg| | ||
Image:Zarya_15775.jpg|Raspberry PI with a relay board connected to it | Image:Zarya_15775.jpg|Raspberry PI with a relay board connected to it | ||
Image: | Image:netlightSchematic2.jpg|The schematic of the relay board | ||
</gallery> | </gallery> | ||
== Script == | == Script == | ||
#!/bin/sh | |||
IP="8.8.8.8" | IP="8.8.8.8" | ||
TIMEOUT="2" | TIMEOUT="2" | ||
GPIO_RED="23" | |||
GPIO_GREEN="24" | |||
THRESHOLD="2" | |||
# no user-servicable parts below | # no user-servicable parts below | ||
echo ${GPIO_RED} > /sys/class/gpio/export | |||
echo "out" > /sys/class/gpio/gpio${GPIO_RED}/direction | |||
echo ${GPIO_GREEN} > /sys/class/gpio/export | echo ${GPIO_GREEN} > /sys/class/gpio/export | ||
echo "out" > /sys/class/gpio/gpio${GPIO_GREEN}/direction | echo "out" > /sys/class/gpio/gpio${GPIO_GREEN}/direction | ||
COUNT=0 | |||
while [ 1 ]; do | while [ 1 ]; do | ||
| Regel 48: | Regel 49: | ||
if [ ${ec} -eq 0 ]; then | if [ ${ec} -eq 0 ]; then | ||
COUNT=0 | |||
else | |||
COUNT=`expr ${COUNT} + 1` | |||
fi | |||
if [ ${COUNT} -ge ${THRESHOLD} ]; then | |||
echo "1" > /sys/class/gpio/gpio${GPIO_RED}/value | |||
echo "0" > /sys/class/gpio/gpio${GPIO_GREEN}/value | |||
else | |||
echo "1" > /sys/class/gpio/gpio${GPIO_GREEN}/value | echo "1" > /sys/class/gpio/gpio${GPIO_GREEN}/value | ||
sleep 3 | sleep 3 | ||
echo "0" > /sys/class/gpio/gpio${GPIO_RED}/value | echo "0" > /sys/class/gpio/gpio${GPIO_RED}/value | ||
fi | fi | ||
done | done | ||
Versie van 28 jul 2012 15:03
| Project Netlight | |
|---|---|
| Naam | Netlight |
| Beschrijving | The network traffic light at haxogreen |
| Website | |
| Start | 2012-07-27 |
| Contact | User:Pietdv |
| Status | Production |
Because of a faulty switch the network at haxogreen 2012 was quite buggy for a while. After a couple of hours we were sick of opening up a terminal and starting a ping to check if the internet was up. We had a raspi and a traffic light available, so we started hacking. We made a little relay board to let the raspi control the traffic light, and wrote a shell script to check if there was an internet connection and set the traffic light to green if there was, to red if there wasn't.
http://www.youtube.com/watch?v=uxdJv-h0Fks
People who helped
Gallery
-
Raspberry PI with a relay board connected to it
-
The schematic of the relay board
Script
#!/bin/sh
IP="8.8.8.8"
TIMEOUT="2"
GPIO_RED="23"
GPIO_GREEN="24"
THRESHOLD="2"
# no user-servicable parts below
echo ${GPIO_RED} > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio${GPIO_RED}/direction
echo ${GPIO_GREEN} > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio${GPIO_GREEN}/direction
COUNT=0
while [ 1 ]; do
ping -c 1 -W 2 -qq ${IP} > /dev/null 2>&1
ec=$?
if [ ${ec} -eq 0 ]; then
COUNT=0
else
COUNT=`expr ${COUNT} + 1`
fi
if [ ${COUNT} -ge ${THRESHOLD} ]; then
echo "1" > /sys/class/gpio/gpio${GPIO_RED}/value
echo "0" > /sys/class/gpio/gpio${GPIO_GREEN}/value
else
echo "1" > /sys/class/gpio/gpio${GPIO_GREEN}/value
sleep 3
echo "0" > /sys/class/gpio/gpio${GPIO_RED}/value
fi
done