-
Notifications
You must be signed in to change notification settings - Fork 1
/
doorlock-arduino-server.py
70 lines (49 loc) · 1.01 KB
/
doorlock-arduino-server.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
from Door import *
from flask import Flask
import os
app = Flask(__name__)
door = None
def connect():
global door
doorPath = ""
for f in os.listdir("/dev"):
if "ttyACM" in f:
doorPath = "/dev/" + f
door = Door(doorPath)
@app.route('/lock')
def lock():
try:
door.lock_control()
return "ok"
except:
connect()
lock()
@app.route('/unlock')
def unlock():
try:
door.unlock_control()
return "ok"
except:
connect()
unlock()
@app.route('/sweep/<int:iterations>')
def sweep(iterations=4):
door.sweep(iterations)
return "ok"
@app.route('/timer/<float:delay>')
def timer(delay=15):
door.timer(delay)
return "ok"
@app.route('/state')
def state():
return State(door.state).name
return "ok"
@app.route('/lockstate')
def lock_state():
return LockState(door.lockState).name
return "ok"
@app.route('/')
def hello_world():
return 'Hello World!'
connect()
app.run("0.0.0.0", 8080)