-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_server.py
74 lines (57 loc) · 2.35 KB
/
simple_server.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
import PyCmdMessenger
import random as rand
import subprocess
from pathlib import Path
from flask import Flask, render_template, request
app = Flask(__name__)
port = '/dev/ttyACM'
for i in range(0,5):
file = Path(port+str(i))
if file.exists():
port = port + str(i)
print("Found open serial port: {}".format(port))
break
ard = PyCmdMessenger.ArduinoBoard(port, baud_rate=115200)
commands = [["setLed","i"]]
c = PyCmdMessenger.CmdMessenger(ard, commands)
@app.route("/asd")
def hello():
return "Hello world"
@app.route("/")
def json():
return render_template('json.html')
@app.route("/upload_are_we")
def upload_are_we():
subprocess.run("sudo arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:avr:uno /home/pi/Development/view-house-lights/are_we", shell=True)
return "done"
@app.route("/upload_basic_tests")
def upload_basic_tests():
subprocess.run("sudo arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:avr:uno /home/pi/Development/view-house-lights/basic_tests", shell=True)
return "done"
@app.route("/upload_color_tests")
def upload_color_tests():
subprocess.run("sudo arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:avr:uno /home/pi/Development/view-house-lights/color_tests", shell=True)
return "done"
@app.route("/upload_bouncing")
def upload_bouncing():
subprocess.run("sudo arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:avr:uno /home/pi/Development/view-house-lights/bouncing", shell=True)
return "done"
@app.route("/upload_pulsating")
def upload_pulsating():
subprocess.run("sudo arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:avr:uno /home/pi/Development/view-house-lights/pulsating", shell=True)
return "done"
@app.route("/upload_color_pulse")
def upload_color_pulse():
subprocess.run("sudo arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:avr:uno /home/pi/Development/view-house-lights/color_pulse", shell=True)
return "done"
@app.route("/upload_kombat")
def upload_kombat():
subprocess.run("sudo arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:avr:uno /home/pi/Development/view-house-lights/kombat", shell=True)
return "done"
@app.route("/setBrightness")
def setBrightness():
level = request.args.get("level", rand.randint(0,255))
c.send("setLed", level)
return "done"
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8080, debug=True)