-
Notifications
You must be signed in to change notification settings - Fork 4
/
api.py
39 lines (30 loc) · 855 Bytes
/
api.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
from sprinkler_control import *
from flask import Flask, request
import json
app = Flask(__name__)
@app.before_request
def auth():
apikey = request.get_json('key')
if apikey['apikey'] != apikeyvalue:
return 'Unauthorized'
def convert_to_integer(prgm):
return {
prgrma: 0,
prgrmb: 1,
prgrmc: 2,
prgrmd: 3
}.get(prgm, 18)
@app.route('/sprinkler/<prgm>')
def start(prgm):
someint = convert_to_integer(prgm)
if someint == 18:
return 'Invalid program'
controller.startProgram(convert_to_integer(prgm))
#return str(convert_to_integer(prgm))
return "Started program " + prgm
@app.route('/sprinkler/stop')
def stop():
controller.stopIrrigation()
return "Stopping irrigation"
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0')