-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
65 lines (48 loc) · 1.51 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Raspberry Pi 3 GPIO Pins Status And Control Using Flask Web Server and Python
import RPi.GPIO as GPIO
from flask import Flask, render_template, request
app = Flask(__name__)
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
ledRed = 13
ledYellow= 19
ledGreen= 26
ledRedSts = 0
ledYellowSts = 0
ledGreenSts = 0
GPIO.setup(ledRed, GPIO.OUT)
GPIO.setup(ledYellow,GPIO.OUT)
GPIO.setup(ledGreen, GPIO.OUT)
GPIO.output(ledRed, GPIO.LOW)
GPIO.output(ledYellow, GPIO.LOW)
GPIO.output(ledGreen, GPIO.LOW)
@app.route('/')
def index():
ledRedSts = GPIO.input(ledRed)
ledYellowSts = GPIO.input(ledYellow)
ledGreenSts = GPIO.input(ledGreen)
templateData = { 'ledRed' : ledRedSts,
'ledYellow' : ledYellowSts,
'ledGreen' : ledGreenSts }
return render_template('index.html', **templateData)
@app.route('/<deviceName>/<action>')
def do(deviceName, action):
if deviceName == "ledRed":
actuator = ledRed
if deviceName == "ledYellow":
actuator = ledYellow
if deviceName == "ledGreen":
actuator = ledGreen
if action == "on":
GPIO.output(actuator, GPIO.HIGH)
if action == "off":
GPIO.output(actuator, GPIO.LOW)
ledRedSts = GPIO.input(ledRed)
ledYellowSts = GPIO.input(ledYellow)
ledGreenSts = GPIO.input(ledGreen)
templateData = { 'ledRed' : ledRedSts,
'ledYellow' : ledYellowSts,
'ledGreen' : ledGreenSts }
return render_template('index.html', **templateData )
if __name__ == "__main__":
app.run(host = '0.0.0.0', debug=True)