Hardware Reference
In-Depth Information
Interfacing the web server
In this secion, we will learn to interface one decoraive appliance and a speaker. We will
create a form and butons on an HTML page to control the devices.
Prepare for lift off
In this task, we will review the code (available along with this chapter) required to interface
decoraive appliances and lighing arranging to a web page and controlled over a local network.
Let's get started with opening the ile using a text ediing tool (Python IDLE's text editor or any
other text editor).
Engage thrusters
1.
We will import the following modules to get started with the program:
import web
from web import form
import RPi.GPIO as GPIO
import os
2. The GPIO module is iniialized, the board numbering is set, and ensure that all
appliances are turned of by seing the GPIO pins to low or false and declare
any global variables:
#Set board
GPIO.setmode(GPIO.BCM)
#Initialize the pins that have to be controlled
GPIO.setup(25,GPIO.OUT)
GPIO.output(25,False)
3. This is followed by deining the template locaion:
urls = ('/', 'index')
render = web.template.render('templates')
4. The butons used in the web page are also deined:
appliances_form = form.Form(
form.Button("appbtn", value="tree", class_="btntree"),
form.Button("appbtn", value="Santa", class_="btnSanta"),
form.Button("appbtn", value="audio", class_="btnaudio")
)
In this example, three buttons are used, a value is assigned to each
button along with their class.
 
Search WWH ::




Custom Search