Advertisement
tomateblue

mainLuz.py

Jun 20th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. from flask import Flask, request,render_template
  4.  
  5. import serial
  6.  
  7. app = Flask(__name__)
  8. try:
  9.  try:   # crie um serial na porta ACM0
  10.   ser = serial.Serial("/dev/ttyACM0",9600)
  11.   status = True
  12.  except: # crie um serial na porta ACM1
  13.   ser = serial.Serial("/dev/ttyACM1",9600)
  14.   status = True
  15. except:
  16.   status = False
  17.  
  18. @app.route("/",methods=["GET","POST"])  
  19. def index():
  20.   if request.method == "POST":
  21.      if request.form['submit'] == "ON":
  22.          print "Ligar Luz"
  23.          # send comand RUN to robot
  24.          if status:
  25.            ser.write("l")
  26.          else:
  27.             print "No Send comand "  
  28.      elif request.form['submit'] == "OFF":
  29.          print 'Desligar Luz'    
  30.          # send comand BACK to robot
  31.          if status:
  32.            ser.write("d")
  33.          else:
  34.             print "No Send comand "  
  35.          
  36.    
  37.   return render_template('luz.html')
  38.  
  39.  
  40. if __name__ == "__main__":
  41.     app.run(host="0.0.0.0",port=8080,debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement