-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathapp.py
43 lines (33 loc) · 887 Bytes
/
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
from flask import Flask, render_template, request, redirect, url_for, make_response
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
import motors
import socket
motors.stop()
# 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()
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html', server_ip=server_ip)
@app.route('/<changepin>', methods=['POST'])
def reroute(changepin):
changePin = int(changepin)
if changePin == 1:
motors.turnLeft()
elif changePin == 2:
motors.forward()
elif changePin == 3:
motors.turnRight()
elif changePin == 4:
motors.backward()
elif changePin == 5:
motors.stop()
else:
print("Wrong command")
response = make_response(redirect(url_for('index')))
return(response)
app.run(debug=True, host='0.0.0.0', port=8000)