Advertisement
tomateblue

porta.py

Aug 28th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. from flask import Flask, request,render_template # importando metodos da biblioteca flask
  4. import serial
  5. #ser = serial.Serial("/dev/ttyACM0",9600)
  6. app = Flask(__name__)
  7.  
  8. @app.route("/",methods=['POST','GET'])  # definindo metodos a serem usados
  9. def index(): # funcao principal
  10.    if request.method == 'POST':               # request.method ele valida o metodo
  11.       if request.form['submit'] == 'OPEN':     #  request.form acessa submit se igual 'ON' luz desligada
  12.            print 'Luz Ligada'
  13. #           ser.write('l')  # envia letra l para arduino ligar luz ^_^
  14.       elif request.form['submit'] == 'CLOSE': # request.form acessa submit se igual 'OFF' luz desligada
  15.            print 'Luz Desligada'
  16. #           ser.write('d') # envia letra d para arduino desligar luz
  17.    return render_template('index.html')      # renderiza isso do arquivo da pasta template
  18.  
  19. if __name__ == "__main__":
  20.    app.run(host="0.0.0.0",port=80,debug=True)
  21.  
  22. # parametro host: pega ip local, porta: 80 para navegador, debug: para caso der algo errado ele mostrar
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement