Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- from flask import Flask, request,render_template # importando metodos da biblioteca flask
- import serial
- #ser = serial.Serial("/dev/ttyACM0",9600)
- app = Flask(__name__)
- @app.route("/",methods=['POST','GET']) # definindo metodos a serem usados
- def index(): # funcao principal
- if request.method == 'POST': # request.method ele valida o metodo
- if request.form['submit'] == 'OPEN': # request.form acessa submit se igual 'ON' luz desligada
- print 'Luz Ligada'
- # ser.write('l') # envia letra l para arduino ligar luz ^_^
- elif request.form['submit'] == 'CLOSE': # request.form acessa submit se igual 'OFF' luz desligada
- print 'Luz Desligada'
- # ser.write('d') # envia letra d para arduino desligar luz
- return render_template('index.html') # renderiza isso do arquivo da pasta template
- if __name__ == "__main__":
- app.run(host="0.0.0.0",port=80,debug=True)
- # 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