Skip to content

Instantly share code, notes, and snippets.

@brunoliveira8
Created August 30, 2015 19:14
Show Gist options
  • Save brunoliveira8/be1affcd5dc3d0368cb9 to your computer and use it in GitHub Desktop.
Save brunoliveira8/be1affcd5dc3d0368cb9 to your computer and use it in GitHub Desktop.
Aciona um dispositivo serial através de uma página web.
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 28 19:41:13 2014
@author: Bruno
"""
from flask import Flask
import serial
app = Flask(__name__)
ser = serial.Serial('COM3', 9600, timeout=0)
@app.get('/comando') # or @route('/login')
def comando():
return '''
<form action="/comando" method="post">
Comando: <input name="comando" type="text" />
<input value="Enviar" type="submit" />
</form>
'''
@app.post('/comando') # or @route('/login', method='POST')
def do_comando():
comando = request.forms.get('comando')
ser.write(comando)
return "<p>Comando enviado!</p>"
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment