-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStatus_v4.py.save
More file actions
77 lines (61 loc) · 2.33 KB
/
Status_v4.py.save
File metadata and controls
77 lines (61 loc) · 2.33 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
68
69
70
71
72
73
74
75
76
77
'''
Author: Arunas Tuzikas, Martin Duffy
Description: Representing status information by using flask request
Date: 2/27/2017 updated 7/16/2018
'''
import time, json, os
from flask import Flask, jsonify, request, abort
from Status_Display import *
app = Flask(__name__)
display = Display()
@app.route('/Status_Weather', methods=['POST'])
def SetWeather():
return updateModule('weather', ['temp', 'pressure', 'humidity', 'sunset', 'sunrise', 'icon'])
@app.route('/Status_Power', methods=['POST'])
def SetPower():
return updateModule('power', ['current', 'voltage', 'activepower', 'apparentpower', 'powerfactor'])
@app.route('/Status_HVAC', methods=['POST'])
def SetHVAC():
return updateModule('hvac', ['temp', 'humidity', 'ep', 'co2'])
@app.route('/Status_COS', methods=['POST'])
def SetCOS():
return updateModule('cos', ['data'])
@app.route('/Status_TOF', methods=['POST'])
def SetTOF():
return updateModule('tof', ['data'])
@app.route('/Status_TempChart', methods=['POST'])
def SetTempChart():
return updateModule('tempchart', ['temp', 'co2'])
@app.route('/Status_Occupancy', methods=['POST'])
def SetOcupancy():
return updateModule('occupancy',['Total', 'Standing', 'Sitting', 'Lying'])
@app.route('/Status_Lights', methods=['POST'])
def SetLights():
# items = ['light']
# print items
# arguments = [request.json[item] for item in items]
return updateModule('light',['Total', 'Standing', 'Sitting', 'Lying'])
# arguments = request.json[items]
#display.frames['hvac'].updateLights(*arguments)
#return jsonify(request.json), 202
return arguments
@app.route('/Script_Run', methods=['POST'])
def ScriptRun():
script_name = request.json["name"]
script_arg = ""
if "arg" in request.json:
script_arg = str(request.json["arg"])
os.system('python scripts/' + script_name + '.py ' + script_arg + '&')
return jsonify(request.json), 202
@app.route('/Script_Kill', methods=['POST'])
def ScriptKill():
script_name = request.json["name"]
os.system('pkill -f ' + script_name + '.py')
return jsonify(request.json), 202
def updateModule(name, items):
arguments = [request.json[item] for item in items]
display.frames[name].update(*arguments)
return jsonify(request.json), 202
if __name__ == '__main__':
display.root.update()
app.run(host="192.168.0.2", port = 5000)