Difference between revisions of "Bash the Lights"

From Technologia Incognita
Jump to: navigation, search
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{Project
 
{{Project
 +
|picture=Powerbutton.jpg
 
|ProjectSkills=Basic electronics, Programming, Bash, Powerbar
 
|ProjectSkills=Basic electronics, Programming, Bash, Powerbar
|ProjectStatus=Active
+
|ProjectStatus=Finished
 
|ProjectNiche=Electronics
 
|ProjectNiche=Electronics
 
|ProjectPurpose=World domination
 
|ProjectPurpose=World domination
 
}}
 
}}
A simple light switch that can turn on and off the [[Powerbar]] lights.
+
A simple light switch that turns on all the lights and off everything hooked up to the [[Powerbar]] system.
  
 
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/alloff
 +
                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>
 +
[[File:Powerbutton_location.jpg|thumb|The PowerButton]]
 +
It runs from the /etc/rc.local
 +
 
 +
Currently it only polls once every second so please be patient . .
 +
 
 +
As you can see from the code the safest way to boot the thing is with the button in the OFF state and after it is booted switch the lights ON.
 +
 
 +
This is not meant to replace the [[Lightswitch]] project, but just a quickly built addition to switch on the lights when you enter, and switch off everything when you leave without the need to go to [http://powerbar.ti powerbar.ti]

Latest revision as of 00:10, 3 September 2015

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

A simple light switch that turns on all the lights and off everything hooked up to the Powerbar system.

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/alloff
                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
The PowerButton

It runs from the /etc/rc.local

Currently it only polls once every second so please be patient . .

As you can see from the code the safest way to boot the thing is with the button in the OFF state and after it is booted switch the lights ON.

This is not meant to replace the Lightswitch project, but just a quickly built addition to switch on the lights when you enter, and switch off everything when you leave without the need to go to powerbar.ti