Created
August 30, 2015 19:14
-
-
Save brunoliveira8/be1affcd5dc3d0368cb9 to your computer and use it in GitHub Desktop.
Aciona um dispositivo serial através de uma página web.
This file contains 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
# -*- 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