-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
67 lines (54 loc) · 1.5 KB
/
app.py
File metadata and controls
67 lines (54 loc) · 1.5 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
57
58
59
60
61
62
63
64
65
66
67
import time, requests
from flask import Flask, render_template, jsonify, request, redirect, url_for
from department import Department
from deviceCount import devCount
from random import randint
from device import Device
from getRequest import getData
from getPi import getPi
import os
app = Flask(__name__)
dep = Department()
device = []
@app.context_processor
def inject_user():
return dict(depID = dep.depID)
@app.route("/")
def renderRoot():
if(not dep.depID):
return render_template("area.html")
return redirect(url_for("update"))
@app.route("/update")
def update():
dev = devCount()
devPi = getPi()
for i in range(dev):
device.append(Device(100+i,"Connected"))
data = getData()
print(data)
if float(data['curr']) > 0.5:
d = True
else:
d = False
return render_template("index.html",dev = dev, devPi = devPi, curr = d)
@app.route("/setDept", methods = ["POST"])
def setDevice():
if request.method == "POST":
dep.setDepID(request.form['depID'])
print("Device set as: ", dep.depID)
return redirect(url_for("renderRoot"))
@app.route("/delete")
def delete():
out = os.popen("echo 'Disconnect\r\n' > /dev/ttyACM0").read()
return redirect(url_for("update"))
@app.route("/vis")
def vis():
return render_template("vis.html")
@app.route("/alexa")
def alex():
return render_template("form.html")
# =========
# Start App
# =========
if __name__ == "__main__":
app.run(debug = True, host='0.0.0.0', port=8000, passthrough_errors=True)