-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebserver.py
More file actions
56 lines (45 loc) · 1.3 KB
/
webserver.py
File metadata and controls
56 lines (45 loc) · 1.3 KB
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
#-*- coding: utf-8 -*-
import RPi.GPIO as GPIO
import finedust as dust
import weather as we
import time
from flask import Flask, render_template
app = Flask(__name__)
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO_RP = 4 #Input Pin
GPIO_RN = 25 #Input Pin
GPIO_EN = 12 #Enable Pin
GPIO.setup(GPIO_RP, GPIO.OUT)
GPIO.setup(GPIO_RN, GPIO.OUT)
GPIO.setup(GPIO_EN, GPIO.OUT)
rp = GPIO.PWM(GPIO_RP,100)
rn = GPIO.PWM(GPIO_RN,100)
rp.start(90)
rn.start(90)
@app.route('/')
def index():
value = dust.display_value10()
state = dust.grade_state()
precipitation = we.requestCurrentPrec()
return render_template('layout.html',pm10value=value,pm10grade=state, prec=precipitation)
@app.route('/forward')
def window_open():
rp.ChangeDutyCycle(1)
GPIO.output(GPIO_RP, True)
GPIO.output(GPIO_RN, False)
GPIO.output(GPIO_EN, True)
time.sleep(1)
GPIO.output(GPIO_EN, False)
return (''), 204
@app.route('/backward')
def window_close():
rn.ChangeDutyCycle(1)
GPIO.output(GPIO_RP, False)
GPIO.output(GPIO_RN, True)
GPIO.output(GPIO_EN, True)
time.sleep(1)
GPIO.output(GPIO_EN, False)
return (''), 204
#if __name__ == "__main__":
# app.run(debug=True, host='0.0.0.0',port=8080)