Exp9 (Final)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

23/10/2023, 17:51 app.

py

1 import RPi.GPIO as GPIO


2 from flask import Flask, render_template, request
3 app = Flask( name )
4 @app.route('/')
5 def index():
6 return render_template('index.html')
7 if name == ' main ':
8 app.run(debug=True, host='0.0.0.0')
9 @app.route('/hello/<name>')
10 def hello(name):
11 return render_template('index.html', name=name)
12 app = Flask( name )
13 GPIO.setmode(GPIO.BCM)
14 GPIO.setwarnings(False)
15 ledRed = 18
16 ledYellow = 19
17 ledRedsts = 0
18 ledYellowsts = 0
19 GPIO.setup(ledRed, GPIO.OUT)
20 GPIO.setup(ledYellow, GPIO.OUT)
21 GPIO.output(ledRed, GPIO.LOW)
22 GPIO.output(ledYellow, GPIO.LOW)
23 @app.route('/')
24 def index():
25 ledRedsts = GPIO.input(ledRed)
26 ledYellowsts = GPIO.input(ledYellow)
27 templateData = {'ledRed' : ledRedsts, 'ledYellow' : ledYellowsts}
28 return render_template('index.html', **templateData)
29 @app.route('/<deviceName>/<action>')
30 def do(deviceName, action):
31 if deviceName == "ledRed":
32 actuator = ledRed
33 if deviceName == "ledYellow":
34 actuator = ledYellow
35 if action == "Turn on":
36 GPIO.output(actuator, GPIO.HIGH)
37 if action == "Turn off":
38 GPIO.output(actuator, GPIO.LOW)
39 ledRedsts = GPIO.input(ledRed)
40 ledYellowsts = GPIO.input(ledYellow)
41 templateData = {'ledRed' : ledRedsts, 'ledYellow' : ledYellowsts}
42 return render_template('index.html', **templateData)
43 if name ==" main ":
44 app.run(host = '0.0.0.0', debug=True)
45
46

Output A(Terminal)-:
Output B(Dashboard window)-:
Output c(Hardware)-:

You might also like