Difference between revisions of "Bash the Lights"

From Technologia Incognita
Jump to: navigation, search
Line 8: Line 8:
  
 
It's a  simple [https://revspace.nl/GL-Inet GL-Inet] device running some curl and bash magic
 
It's a  simple [https://revspace.nl/GL-Inet GL-Inet] device running some curl and bash magic
<pre>echo 20 > /sys/class/gpio/export
+
<pre>#!/bin/ash
echo in > /sys/class/gpio/gpio20/direction</pre>
 
  
To read button state
+
echo 20 > /sys/class/gpio/export
 +
echo in > /sys/class/gpio/gpio20/direction
  
<pre>cat /sys/class/gpio/gpio20/value</pre>
+
state=`cat /sys/class/gpio/gpio20/value`
 +
 
 +
while true
 +
do
 +
        if [[ `cat /sys/class/gpio/gpio20/value` -eq 0 && $state -ne 0 ]]
 +
        then
 +
                curl -d state=Off http://powerbar.ti:5000/preset/lightsoff
 +
                state=0
 +
        fi
 +
        if [[ `cat /sys/class/gpio/gpio20/value` -eq 1 && $state -ne 1 ]]
 +
        then
 +
                curl -d state=Off http://powerbar.ti:5000/preset/lightson
 +
                state=1
 +
        fi
 +
        sleep 1
 +
done
 +
</pre>

Revision as of 00:43, 22 November 2014

Projects
Participants Brainsmoke, Realitygaps, The JinX, Wizzup
Skills Basic electronics, Programming, Bash, Powerbar
Status Active
Niche Electronics
Purpose World domination

A simple light switch that can turn on and off the Powerbar lights.

It's a simple GL-Inet device running some curl and bash magic

#!/bin/ash

echo 20 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio20/direction

state=`cat /sys/class/gpio/gpio20/value`

while true
do
        if [[ `cat /sys/class/gpio/gpio20/value` -eq 0 && $state -ne 0 ]]
        then
                curl -d state=Off http://powerbar.ti:5000/preset/lightsoff
                state=0
        fi
        if [[ `cat /sys/class/gpio/gpio20/value` -eq 1 && $state -ne 1 ]]
        then
                curl -d state=Off http://powerbar.ti:5000/preset/lightson
                state=1
        fi
        sleep 1
done