-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
42 lines (32 loc) · 1.03 KB
/
main.py
File metadata and controls
42 lines (32 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from flask import Flask, render_template
from flask_socketio import SocketIO
from PFDSocket import PFDSocket
from threading import Thread, Event, Timer
import webbrowser
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)
@app.route("/")
def index():
return render_template("dashboard.html")
@socketio.on('my event')
def handle_my_custom_event(json):
print('received json: ' + str(json))
@socketio.on('button click')
def handle_my_custom_event(json2):
print(json2)
if json2['data'] == 'Arm':
arm.set()
elif json2['data'] == 'Disarm':
disarm.set()
def on_data(data):
socketio.emit(data)
if __name__ == '__main__':
arm = Event()
disarm = Event()
# noinspection PyTypeChecker
sock = PFDSocket()
sock.on('data', on_data)
Thread(target=sock.server(), name="Server Thread").start()
Thread(target=socketio.run, args=(app,), name="SocketIO Thread").start()
Thread(target=webbrowser.open, args=('http://127.0.0.1:5000/',), name="Browser Thread").start()