Guest User

Untitled

a guest
Jun 18th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. from flask import Flask, request, render_template
  2. from fiotclient.iot import FiwareIotClient
  3.  
  4. app = Flask(__name__)
  5.  
  6. entity_id = "DOOR"
  7. device_id = "STELA_DOOR"
  8. #command_open = "STELA_DOOR@change_state"
  9. name="change_state"
  10. #command_close = "STELA_DOOR@change_state"
  11.  
  12. @app.route('/', methods=['GET', 'POST'])
  13. def index():
  14. # create fiware iot client
  15. client_iot = FiwareIotClient("config.ini")
  16.  
  17. if request.method == 'POST':
  18. if request.form['submit'] == 'Open':
  19. client_iot.send_command(entity_id, device_id, name, params={'state':True})
  20. elif request.form['submit'] == 'Close':
  21. client_iot.send_command(entity_id, device_id, name, params={'state':False})
  22. return render_template('index.html')
  23. elif request.method == 'GET':
  24. return render_template('index.html')
  25.  
  26. if __name__ == '__main__':
  27. app.run(debug=True)
Add Comment
Please, Sign In to add comment