-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSENSOR_TEMP.py
55 lines (50 loc) · 1.6 KB
/
SENSOR_TEMP.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
import time
import requests
from flask import Flask, request
from PREDCITING import create_data
from utils.configing import updateconf, readconf
from utils.data_menager import read_csv
app = Flask(__name__)
SOURCE = 'data/1temp.csv'
data_list = read_csv(SOURCE)
config_file = "5050.ini"
config_keys = {
"switch": "wlacznik",
}
@app.route('/wlacznik', methods=['GET', 'POST'])
def wlacznik():
client_data = request.args.to_dict()
if "wlacz" in client_data:
global wlacz
wlacz = client_data["wlacz"]
validation = [
"True" == wlacz,
"False" == wlacz
]
if any(validation):
topic = config_keys["switch"]
updateconf(config_file, topic, client_data['wlacz'])
status = readconf(config_file, topic)
if status == 'True':
for data in data_list:
status = readconf(config_file, topic)
if status == 'True':
print(create_data(float(data)))
data = {"data": data}
requests.post("http://127.0.0.1:5060/", data=data)
else:
return {"1": 1}
time.sleep(1)
else:
return {"1": 1}
else:
return {
"status": 400,
"message": "Wybrana opcja nie jest obslugiwana"
}, 400
else:
return {
"status": 400,
"message": "Zle argumenty"
}, 400
app.run(port=5050, debug=True)