-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
42 lines (28 loc) · 1007 Bytes
/
app.py
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
import logging
from flask_socketio import SocketIO, emit
from flask import Flask, render_template, jsonify
# import eventlet
# eventlet.monkey_patch()
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
# socketio = SocketIO(app=app, async_mode='eventlet', cors_allowed_origins='*')
socketio = SocketIO(app=app, async_mode=None, cors_allowed_origins='*')
@app.route('/zigbee/index')
def index():
return render_template('index.html')
@app.route('/zigbee/client')
def client():
return render_template('client.html')
@socketio.on('collection_channl', namespace='/zigbee')
def broadcast_message(message):
logging.info(message)
emit('view_channl', {'data': message}, broadcast=True)
@socketio.on('connect', namespace='/zigbee')
def connect():
logging.info('already connected')
emit('view_channl', {'data': 'Connected'})
@socketio.on('disconnect', namespace='/zigbee')
def disconnect():
logging.error('disconnect')
if __name__ == "__main__":
socketio.run(app)