Skip to content

Instantly share code, notes, and snippets.

Created Oct 11, 2016
What would you like to do?
Flask server
# -*- coding: utf-8 -*-
import time
import Tkinter as tk
from serial import Serial
from minirobots import Turtle
from flask import Flask, request, render_template
serial = Serial('/dev/rfcomm0', 57600)
except OSError:
print "Can't connect to serial device on", args.port
turtle = Turtle(serial)
app = Flask(__name__)
commands = ['forward', 'backward', 'left', 'right']
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__':'', port=8000, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment