Home Automation Case Study
- Need Flask installed
- Need Flask Bootstrap module installed
- Bootstrap is a piece of software from Twitter that makes it easy to create slick looking websites with little effort.
- Need RPi.GPIO installed
- Get the class source code, by doing ONE of the following options:
- On your Raspberry Pi type
git clone https://github.com/raspberrypi-aa/raspberrypi-aa.git
- In the Adafruit WebIDE, clone the above repository
- Download Zip file by running
- On your Raspberry Pi type
- Be sure to build the circuit on your board before testing the code that uses those pins
Running the webserver
- Point your computer's web browser at http://piname.local:5000/. You should see a webpage with a "Test" button on it.
- Clicking the "Test" button will make a request to "/test". If you click the button, it should fail with a 404 error, because no handler exists for the "/test" path
- Open another ssh connection and use
nanoto edit the flaskGpio.py file. Add a handler for "/test" that will display a successful message to the user. You can display a message by setting the "successMsg" parameter in the call to render_template()
- Clicking the button should now display a success message in the browser
Click to turn lamp on/off
Use the "Lighting" tab on the left for this section.
- Before we can use the RPi.GPIO library, you must import it first. This should happen at the top of the source file
- Next, call RPi.GPIO.setmode() to use the board in Broadcom (BCM) mode. This will match the numbers on your breakout board. This should be done as part of the server setup, but before starting the server
- Call RPi.GPIO.setup(pin#, GPIO.OUT) to set the lamp pin (#18) as an output. This should be done immediately after the code for step #2
- As part of the request handler for clicking the "On" and "Off" buttons, use RPi.GPIO.output(pin#, GPIO.HIGH/GPIO.LOW) to turn the LED on or off
Set schedule to turn the coffee maker on/off
- Before using any timer, you must import the threading library
- To run a timer, create a timer object containing the remaining time and function to run when the timer expires.
- Call timer.start()
- To stop the timer, call timer.stop()
- You should set the timer in coffeeset() and cancel the timer in coffeestop()
Check if dryer still running
- Set the dryer pin as an input pin in the setup function.
- In appliances(), read the state of the input pin.
- Put the state of the pin in applianceData['dryer']
- You may want to add this code to coffee_set() and coffee_stop() as well
Check if doorbell rung since last check
- Set the doorbell pin as an input pin in the setup function
- Call add_event_detect() for the doorbell_pin
- In the exterior() function, call event_detected() on the doorbell_pin.
- If the doorbell has been pushed, set exterior['doorbell'] to False
Track the time the mailman shows up
- Write a callback function (
mailboxCallback()) that will record the current time into lastMailboxPush
- Set the mailbox pin as an input pin in the setup function
- Call add_event_detect() for the mailbox pin and provide the name of the callback from step 1