Created
October 11, 2016 15:06
-
-
Save lvidarte/a68339667311738c5030d3d556aa2da6 to your computer and use it in GitHub Desktop.
Flask server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import time | |
import Tkinter as tk | |
from serial import Serial | |
from minirobots import Turtle | |
from flask import Flask, request, render_template | |
try: | |
serial = Serial('/dev/rfcomm0', 57600) | |
time.sleep(1) | |
except OSError: | |
print "Can't connect to serial device on", args.port | |
sys.exit(1) | |
turtle = Turtle(serial) | |
turtle.pen_down() | |
app = Flask(__name__) | |
commands = ['forward', 'backward', 'left', 'right'] | |
@app.route('/') | |
def index(): | |
if len(request.args.keys()) == 1 and request.args.keys()[0] in commands: | |
command = request.args.keys()[0] | |
value = int(request.args.get(command)) | |
getattr(turtle, command)(value) | |
return render_template('index.html') | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=8000, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment