From 494c662344e775b8cb36cd85b36557cea92b4ef4 Mon Sep 17 00:00:00 2001 From: chenchacha Date: Sun, 30 Dec 2018 11:22:09 +0800 Subject: [PATCH 1/3] Add gevent monkey patch This patch replace functions and classes in the standard socket module with their cooperative counterparts. That way even the modules that are unaware of gevent can benefit from running in a multi-greenlet environment. Signed-off-by: chenchacha --- app/run.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/run.py b/app/run.py index 888f217..afe8815 100644 --- a/app/run.py +++ b/app/run.py @@ -1,3 +1,6 @@ +from gevent import monkey +monkey.patch_all() + from flask import Flask, render_template from flask_socketio import SocketIO, emit from app.modules.lepd.LepDClient import LepDClient From 2bc44c0809c92a4425cc8847dd64a0be863ca8ce Mon Sep 17 00:00:00 2001 From: chenchacha Date: Sun, 30 Dec 2018 11:23:12 +0800 Subject: [PATCH 2/3] Update app start entry The socketio.run() function encapsulates the start up of the web server and replaces the app.run() standard Flask development server start up. Signed-off-by: chenchacha --- app/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/run.py b/app/run.py index afe8815..8871deb 100644 --- a/app/run.py +++ b/app/run.py @@ -90,4 +90,4 @@ def test(): return render_template("test.html", languages=languages) if __name__ == '__main__': - app.run(debug=True, host='0.0.0.0', port=8889) + socketio.run(app, debug=True, host='0.0.0.0', port=8889) From c672c9eeb594cfb700969bb63e73ee7ca111eb80 Mon Sep 17 00:00:00 2001 From: chenchacha Date: Mon, 31 Dec 2018 23:18:52 +0800 Subject: [PATCH 3/3] Add multi-device support Move device server address entry to left bar. Signed-off-by: chenchacha --- app/run.py | 28 ++++++++++++- app/templates/index.html | 91 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 112 insertions(+), 7 deletions(-) diff --git a/app/run.py b/app/run.py index 8871deb..59c9503 100644 --- a/app/run.py +++ b/app/run.py @@ -12,7 +12,33 @@ app.json_encoder = MyJSONEncoder socketio = SocketIO(app, ping_timeout=3600) - +deviceList = [] + +#Add device to devices list +@socketio.on('lepd.device.add') +def add_lepd_device(device): + if device not in deviceList: + deviceList.append(device) + + print('add_lepd_device: ' + device) + res = {} + res['device'] = device + emit('lepd.device.add.successed', res) + +#Rmove device form devices list +@socketio.on('lepd.device.del') +def del_lepd_device(device): + if device in deviceList: + deviceList.remove(device) + + print('del_lepd_device: ' + device) + +#List device +@socketio.on('lepd.device.list') +def lsit_lepd_device(): + res = {} + res['list'] = deviceList + emit('lepd.device.list.result', res) @socketio.on('lepd.ping') def ping_lepd_server(request): diff --git a/app/templates/index.html b/app/templates/index.html index 7f4731c..3b0fa5a 100755 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -49,7 +49,24 @@ - + + +