-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
68 lines (62 loc) · 1.67 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
66
67
68
from time import sleep
from flask import *
from flask import render_template
from pyfirmata import Arduino
# Trying to connect computer with boarding
for i in range(1,6):
try:
ard=Arduino("COM"+str(i))
break
except:
print("Error")
# Turning off all the switches in circuit
ard.digital[3].write(1)
ard.digital[4].write(1)
ard.digital[2].write(0)
ard.digital[5].write(1)
# Creating a function to give output through arduino
def funcn(n):
if "on" in n:
if "red" in n:
ard.digital[3].write(1)
ard.digital[4].write(1)
ard.digital[5].write(0)
elif "green" in n:
ard.digital[4].write(1)
ard.digital[5].write(1)
ard.digital[3].write(0)
elif "blue" in n:
ard.digital[3].write(1)
ard.digital[5].write(1)
ard.digital[4].write(0)
elif "buzzer" in n:
ard.digital[2].write(1)
else:
return "error"
elif "off" in n:
ard.digital[3].write(1)
ard.digital[4].write(1)
ard.digital[2].write(0)
ard.digital[5].write(1)
elif n == "emergency":
# Declaring function for emergency, where buzzer will sound beep beep in loop
ard.digital[5].write(0)
for i in range(0,21):
ard.digital[2].write(i%2)
sleep(0.3)
ard.digital[5].write(1)
else:
return "error"
#Setting up server and declaring routes
app = Flask(__name__, template_folder="temp", static_folder="static")
# Making route for user handling
@app.route("/", methods=["POST","GET"])
def a():
if request.method == "GET":
return render_template("index.html")
else:
funcn(request.data.decode("utf-8"))
return render_template("index.html")
# Made by Abhineet Raj (https://github.com/abhineetraj1)
if __name__ == '__main__':
app.run()