Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from controller import COMController
- from flask import Flask, request, redirect
- app = Flask(__name__)
- state = False
- controller = COMController('<', '>', 6, 7)
- @app.route('/', methods=['GET', 'POST'])
- def index():
- global state
- if request.method == 'GET':
- return '''<!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta name="viewport"
- content="width=device-width, initial-scale=1, shrink-
- <link rel="stylesheet"
- href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0
- integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh
- crossorigin="anonymous">
- </head>
- <body>
- <form method="post" enctype="multipart/form-data">
- <button type="submit" class="btn btn-primary">Toggle
- </form>
- </body>
- </html>'''
- elif request.method == 'POST':
- controller.send('05000' + ('0' if state else '1'))
- state = ~state
- return redirect('#')
- if __name__ == '__main__':
- app.run(host='192.168.0.102', port=80)
Advertisement
Add Comment
Please, Sign In to add comment