Experiment 6
Experiment 6
OBJECTIVE
PROGRAM
PROGRAM
Python Program:
# Python 2.7 on raspberry pi
# Script to trigger thermostat control on heating
# Reads room temperatures from Prodserver DONE - from Thermostat01.py
# All heating control logic is on prodserver. This just reads on/off commands
# Dependencies
# sudo pip install max7219 - 7 seg 8 digit display driver
# sudo pip install bs4 - beautiful soup web scraper
# sudo pip install requests - python http library for GET and POST
# sudo apt-get install python-blinkt blinkt led library
# GPIO PINS
# MAX7129 7 seg display
# DIN = GPIO10(MOSI)
# CS = GPIO8(SPI CE0)
# CLK = GPIO11(SPI CLK)
# Blinkt uses GPIO23,24
Pin Constants
PIN_RELAY = 17
PIN_BOOST_DETECT = 4
import blinkt
blinkt.set_clear_on_exit(False)
blinkt.set_all(0,0,0)
blinkt.set_brightness(0.1)
blinkt.show()
# blinkt Timer leds 0,1
# blinkt Heat leds 2,3
# blinkt Boost leds 4,5
import sys
# 7 seg display set up
import max7219.led as led
device = led.sevensegment()
device.brightness(1)
import requests
from bs4 import BeautifulSoup
fp.write(logstring)
fp.close()
print logstring
def do_7segdisplay(status):
"display on 7 seg"
now=status[0]
segnumber = 10000*now.hour + 100*now.minute + float(status[5])
device.write_number(0,segnumber,decimalPlaces=2,zeroPad=True)
def do_timer(status):
"Deals with timer status led"
if(status[3]): # timer on
r,g,b = (0,250,0)
else:
r,g,b = (0,0,0)
blinkt.set_pixel(0,r,g,b)
#blinkt.set_pixel(1,r,g,b)
blinkt.show()
return
def do_heat(status):
"Deals with Heat status led and switches relay"
if(status[4]): # heat on
r,g,b = (200,000,000)
GPIO.output(PIN_RELAY, GPIO.LOW)
else:
r,g,b = (0,0,0)
GPIO.output(PIN_RELAY, GPIO.HIGH)
blinkt.set_pixel(2,r,g,b)
#blinkt.set_pixel(3,r,g,b)
blinkt.show()
return
def do_boost():
"No function as yet"
# MAIN PROGRAMME
status = get_status(server, status)
do_log(status)
do_7segdisplay(status)
do_timer(status)
do_heat(status)
( c ) Get the status of a bulb at a remote place (on the LAN) through web.
THEORY
One function that makes the Internet of Things the Internet of Things is remote control of devices,
being able to trigger action from a remote location. This is otherwise known as remote
configuration. Whether it’s a home, an office, or an industrial site, connected devices rely on
some form of automation through sensors or machines and need a mechanism to control their
operation remotely.
Hardware Requirements
For this demonstration, we will use the following hardware:
Web Application
The web interface will look something like this:
This is a very simple web page with a visual indicator for the device and a button to toggle the
on/off state of LED.
Behind the scenes, we have the PubNub Javascript API that performs two operations upon
receiving certain events.
glow = False
When a toggle request is received, the application checks the current state of the GPIO driving pin
of the LED, toggles its state and then sends the new state back to the web application as a response
message.
The exchange of messages between the web application and Raspberry Pi can be visualized as
follows.