-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hornetparking.py
146 lines (132 loc) · 3.88 KB
/
Hornetparking.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
'''
main script Hornetparking.py
'''
import RPi.GPIO as GPIO
from flask import Flask, render_template
import datetime
app = Flask(__name__)
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
#define actuators GPIOs
operat = 13
l1full = 19
l2full = 26
#initialize GPIO status variables
operatSts = 0
l1fullSts = 0
l2fullSts = 0
# Define led pins as output
GPIO.setup(operat, GPIO.OUT)
GPIO.setup(l1full, GPIO.OUT)
GPIO.setup(l2full, GPIO.OUT)
# turn leds OFF
GPIO.output(operat, GPIO.LOW)
GPIO.output(l1full, GPIO.LOW)
GPIO.output(l2full, GPIO.LOW)
@app.route('/')
def page():
now = datetime.datetime.now()
timeString = now.strftime("%H:%M")
datestamp = now.strftime("%Y-%m-%d")
# Read Sensors Status
operatSts = GPIO.input(operat)
l1fullSts = GPIO.input(l1full)
l2fullSts = GPIO.input(l2full)
templateData = {
'title' : 'Hornet Parking',
'greeting' : 'Welcome to Hornet Parking',
'csus' : 'California State University, Sacramento',
'saying' : "Sac State's best parking",
'date': datestamp,
'time': timeString,
'operat' : operatSts,
'l1full' : l1fullSts,
'l2full' : l2fullSts
}
return render_template('hornetparking.html', **templateData)
@app.route('/login')
def login():
now = datetime.datetime.now()
timeString = now.strftime("%Y-%m-%d, %H:%M")
templateData = {
'title' : 'Hornet Parking',
'greeting' : 'Welcome to Hornet Parking',
'csus' : 'California State University, Sacramento',
'saying' : "Sac State's best parking",
'time': timeString
}
return render_template('log_in.html', **templateData)
@app.route("/home")
def hornet():
now = datetime.datetime.now()
timeString = now.strftime("%H:%M")
datestamp = now.strftime("%Y-%M-%D")
# Read Sensors Status
operatSts = GPIO.input(operat)
l1fullSts = GPIO.input(l1full)
l2fullSts = GPIO.input(l2full)
templateData = {
'title' : 'Hornet Parking',
'greeting' : 'Welcome to Hornet Parking',
'csus' : 'California State University, Sacramento',
'saying' : "Sac State's best parking",
'date': datestamp,
'time': timeString,
'operat' : operatSts,
'l1full' : l1fullSts,
'l2full' : l2fullSts
}
return render_template('hornet.html', **templateData)
@app.route('/override')
def override():
now = datetime.datetime.now()
timeString = now.strftime("%Y-%m-%d, %H:%M")
# Read Sensors Status
operatSts = GPIO.input(operat)
l1fullSts = GPIO.input(l1full)
l2fullSts = GPIO.input(l2full)
templateData = {
'time': timeString,
'operat' : operatSts,
'l1full' : l1fullSts,
'l2full' : l2fullSts
}
return render_template('override.html', **templateData)
@app.route("/<deviceName>/<action>")
def action(deviceName, action):
now = datetime.datetime.now()
timeString = now.strftime("%Y-%m-%d, %H:%M")
if deviceName == 'operat':
actuator = operat
if deviceName == 'l1full':
actuator = l1full
if deviceName == 'l2full':
actuator = l2full
if action == "on":
GPIO.output(actuator, GPIO.HIGH)
if action == "off":
GPIO.output(actuator, GPIO.LOW)
operatSts = GPIO.input(operat)
l1fullSts = GPIO.input(l1full)
l2fullSts = GPIO.input(l2full)
templateData = {
'time': timeString,
'operat' : operatSts,
'l1full' : l1fullSts,
'l2full' : l2fullSts,
}
return render_template('override.html', **templateData)
@app.route('/camera')
def camera():
now = datetime.datetime.now()
timeString = now.strftime("%Y-%m-%d, %H:%M")
templateData = {
'title' : 'Hornet Parking',
'greeting' : 'Welcome to Hornet Parking',
'csus' : 'California State University, Sacramento',
'saying' : "Sac State's best parking",
'time': timeString
}
return render_template('camera.html', **templateData)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=80, debug=True)