-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
executable file
·48 lines (35 loc) · 1.05 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#########################
#Author: James Poole
#Date: 10 October 2016
#########################
from flask import Flask, render_template, request, redirect, request, url_for, make_response
import RPi.GPIO as GPIO
app = Flask(__name__)
GPIO.setmode(GPIO.BCM)
#dictionary to hold each pin's associated colour and state
pins = {
18 : { 'colour' : 'blue', 'state' : GPIO.LOW},
23 : { 'colour' : 'red', 'state' : GPIO.LOW},
24 : { 'colour' : 'green', 'state' : GPIO.LOW}
}
for pin in pins:
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, GPIO.LOW)
@app.route('/')
def index():
for pin in pins:
pins[pin]['state'] = GPIO.input(pin)
templateData = {
'pins' : pins
}
return render_template('index.html', **templateData)
@app.route('/<changepin>/<action>', methods=['POST'])
def reroute(changepin, action):
changePin = int(changepin)
if action == "on":
GPIO.output(changePin, GPIO.HIGH)
elif action == "off":
GPIO.output(changePin, GPIO.LOW)
response = make_response(redirect(url_for('index')))
return(response)
app.run(debug=True, host='0.0.0.0', port=8000)