Hardware Reference
In-Depth Information
# Sleep for 1 second to allow the remote to receive
sleep 1
# Pull the pin low
/bin/echo 0 > /sys/class/gpio/gpio17/value
# Create a file to indicate current outlet state
/bin/echo power-off > outlet-status
# Give the user a nice message
echo "Power is OFF"
echo "Click your browsers back button to return"
There really is no difference between these scripts except that you are toggling different GPIO pins.
Last up is the server-power-control.rb Ruby script. This Ruby script is where all the above scripts come
together. Take a look at the script in Listing 10-6.
Listing 10-6. The WEBrick HTTP Server Used to Pull Everything Together
#!/usr/bin/ruby
# Description : Ruby webrick html server and gpio setup
# this app will run out of one directory self contained
# ensure on.cgi, off.cgi and index.html are in the same dir
# Author : Brendan Horan
# Include
require 'webrick'
include WEBrick
# Set up the webrick
dir = Dir::pwd
port = "80"
access_log_stream = File.open('access.log', 'w')
access_log = [ [ access_log_stream, AccessLog::COMBINED_LOG_FORMAT ] ]
puts "Access at :-"
puts "URL: http://#{Socket.gethostname}:#{port} "
# run a script to configure gpio
puts "Setting up GPIO on pid:"
pipe = IO.popen("./gpio-setup.sh")
puts pipe.pid
server = HTTPServer.new(
:Port => port,
:DocumentRoot => dir,
:AccessLog => access_log
)
 
Search WWH ::




Custom Search