-
Notifications
You must be signed in to change notification settings - Fork 0
/
local.py
executable file
·49 lines (37 loc) · 1.04 KB
/
local.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
import robot_basics as rb
from flask import Flask, render_template, redirect, url_for, make_response
import socket
# get server ip
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
server_ip = s.getsockname()[0]
s.close()
# create a Flask web server from the Flask module (__name__ = this file)
app = Flask(__name__)
@app.route('/')
def webui():
return render_template('local.php', server_ip=server_ip)
@app.route('/<instruction>', methods=['POST'])
def reroute(instruction):
command = int(instruction)
if command == 1:
rb.Left()
elif command == 2:
rb.Forwards()
elif command == 3:
rb.Right()
elif command == 4:
rb.Backwards()
elif command == 5:
rb.StopMotors()
elif command == 6:
rb.Low()
elif command == 7:
rb.Medium()
elif command == 8:
rb.High()
else:
print("Wrong command")
response = make_response(redirect(url_for('webui')))
return(response)
app.run(debug=True, host='0.0.0.0', port=8000)