-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
53 lines (43 loc) · 1.16 KB
/
main.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
from math import acos, degrees
import requests
from flask import Flask, render_template, request
app = Flask(__name__)
host = '192.168.10.3:80'
Vcc = 5.0
Vccm = 3.3
Ka = 1000.0
Kb = -5.0
Kt = 0.02
Kp = 0.5
Kf = 0.85
T = 25.0
@app.route("/")
def main():
return render_template("home.html")
@app.route("/data", methods=["GET"])
def deg():
try:
req = requests.get(f"http://{host}/", timeout=3)
temp, volt, z = req.text.rstrip().split(';')
valid = True
except Exception:
temp, volt, z = -1, -1, 1
valid = False
Vm = float(volt) * Vcc / 1023
S = Ka * pow((Vccm - Kf * Vm) / 2, Kb)
EC = S / (1 + Kt * (float(temp) - T))
TDS = EC * Kp
z = float(z) / 16384
if z < 0:
angle = 90 - degrees(acos(z))
else:
angle = degrees(acos(-z)) - 90
js = {'temp': temp, 'elek': round(S, 2), 'density': round(TDS, 2), 'orient_z': round(angle, 0),
'valid': valid}
return js
@app.route("/engine", methods=["POST", "GET"])
def engine():
requests.post(f'http://{host}/', data=request.get_json()['task'])
return '1'
if __name__ == "__main__":
app.run(host='0.0.0.0', debug=True)