Skip to content

Instantly share code, notes, and snippets.

@lvidarte
Created October 11, 2016 15:06
Show Gist options
  • Save lvidarte/a68339667311738c5030d3d556aa2da6 to your computer and use it in GitHub Desktop.
Save lvidarte/a68339667311738c5030d3d556aa2da6 to your computer and use it in GitHub Desktop.
Flask server
#!/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