Book Image

Raspberry Pi Embedded Projects Hotshot

Book Image

Raspberry Pi Embedded Projects Hotshot

Overview of this book

Table of Contents (20 chapters)
Raspberry Pi Mechatronics Projects HOTSHOT
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Interfacing the web server


In this section, we will learn to interface one decorative appliance and a speaker. We will create a form and buttons 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 decorative appliances and lighting arranging to a web page and controlled over a local network. Let's get started with opening the file using a text editing 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 initialized, the board numbering is set, and ensure that all appliances are turned off by setting 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 defining the...