Guest User

Untitled

a guest
Aug 24th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. from controller import COMController
  2. from flask import Flask, request, redirect
  3.  
  4. app = Flask(__name__)
  5. state = False
  6. controller = COMController('<', '>', 6, 7)
  7.  
  8.  
  9. @app.route('/', methods=['GET', 'POST'])
  10. def index():
  11. global state
  12. if request.method == 'GET':
  13. return '''<!doctype html>
  14. <html lang="en">
  15. <head>
  16. <meta charset="utf-8">
  17. <meta name="viewport"
  18. content="width=device-width, initial-scale=1, shrink-
  19. <link rel="stylesheet"
  20. href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0
  21. integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh
  22. crossorigin="anonymous">
  23. </head>
  24. <body>
  25. <form method="post" enctype="multipart/form-data">
  26. <button type="submit" class="btn btn-primary">Toggle
  27. </form>
  28. </body>
  29. </html>'''
  30. elif request.method == 'POST':
  31. controller.send('05000' + ('0' if state else '1'))
  32. state = ~state
  33. return redirect('#')
  34.  
  35.  
  36. if __name__ == '__main__':
  37. app.run(host='192.168.0.102', port=80)
Advertisement
Add Comment
Please, Sign In to add comment