-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
77 lines (62 loc) · 1.87 KB
/
app.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
71
72
73
74
75
76
77
# app.py
from flask import Flask, render_template, request, jsonify
from flask_assets import Bundle, Environment
import random
app = Flask(__name__)
assets = Environment(app)
css = Bundle("src/main.css", output="dist/main.css")
assets.register("css", css)
css.build()
@app.route("/")
def homepage():
return render_template("index.html")
#Route for manual mode
@app.route("/manual")
def tw():
return render_template("manual.html")
#Route for automatic mode
@app.route("/auto")
def auto():
return render_template("auto.html")
@app.route("/semi")
def semi():
return render_template("semi.html")
#Modify to get data
@app.route('/api/datapoint')
def api_datapoint():
deg = [int(random.random() * 100) / 100 for _ in range(3)]
dictionary_to_return = {
'angle1': deg[0],
'angle2': deg[1],
'angle3': deg[2]
}
return jsonify(dictionary_to_return)
@app.route("/sendData", methods =["GET", "POST"])
def sendData():
rot = request.form.get("rot")
try:
rot = int(rot)%360
rot = rot-360 if rot > 180 else rot
print("Activated")
import socket
s=socket.socket()
host="raspberrypi" #This is your Server IP!
port=2345
s.settimeout(10)
s.connect((host,port))
s.send(str(rot).encode())
rece=s.recv(1024)
print("Received",rece)
s.close()
rece = "Confirm Sent: "+rece.decode("ASCII")
return render_template("manual.html", conf=rece)
except ValueError:
return render_template("manual.html", conf='Invalid Input "'+rot+'"')
except:
return render_template("manual.html", conf='Timeout: Unable to reach Pi')
if __name__ == "__main__":
app.run(debug=True)
#Commands to run
# npm install -D tailwindcss
#npx tailwindcss -i ./static/src/input.css -o ./static/dist/css/output.css --watch
#python app.py