Skip to content
Commits on Source (2)
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
# System modules # System modules
import time import time
import logging
# Third-party modules # Third-party modules
from flask import Flask, request from flask import Flask, request
...@@ -20,6 +21,7 @@ app.threaded = True ...@@ -20,6 +21,7 @@ app.threaded = True
cors = CORS(app) cors = CORS(app)
@app.route('/all/<string:namespace>') @app.route('/all/<string:namespace>')
def get_status(namespace): def get_status(namespace):
'''Build a global status for a given namespace''' '''Build a global status for a given namespace'''
...@@ -46,6 +48,7 @@ def get_status(namespace): ...@@ -46,6 +48,7 @@ def get_status(namespace):
return endpoints return endpoints
if __name__ == "__main__": if __name__ == "__main__":
# System modules # System modules
...@@ -63,9 +66,13 @@ if __name__ == "__main__": ...@@ -63,9 +66,13 @@ if __name__ == "__main__":
port = 5533 port = 5533
hostname = "0.0.0.0" hostname = "0.0.0.0"
print(f"hostname {hostname}") print(f"hostname {hostname}")
if with_web: if with_web:
socketio = instance.enable(app) socketio = instance.enable(app)
socketio.run(app, host=hostname, port=port) socketio.run(app, host=hostname, port=port)
......
...@@ -20,18 +20,21 @@ def enable(app): ...@@ -20,18 +20,21 @@ def enable(app):
app.register_blueprint(routes.web, url_prefix='/web') app.register_blueprint(routes.web, url_prefix='/web')
base_url = {"ext_base_url": "http://fork.orsa.unige.net:5533", base_url = {"ext_base_url": "http://fork.orsa.unige.net:5533", # what form-crud needs
"int_base_url": "http://10.185.119.108:5533"} "int_base_url": "http://10.185.119.108:5533"} # what instance needs
# "int_base_url": "http://130.251.19.108:5533"} # from outside
@app.context_processor @app.context_processor
def inject_variables(): def inject_variables():
return base_url return base_url
socketio = SocketIO(app, socketio = SocketIO(app,
path="/web/socket", path="/web/socket",
async_mode='threading', async_mode='threading',
threaded=True) threaded=True)
connected_clients = {} connected_clients = {}
ws_names = [ ws_names = [
...@@ -91,8 +94,8 @@ def enable(app): ...@@ -91,8 +94,8 @@ def enable(app):
socketio.start_background_task(stream.send_webcam, socketio=socketio, socketio.start_background_task(stream.send_webcam, socketio=socketio,
url=base_url["int_base_url"]+"/api/webcam/snapshot") url=base_url["int_base_url"]+"/api/webcam/snapshot")
# socketio.start_background_task(stream.send_status, socketio=socketio, socketio.start_background_task(stream.send_status, socketio=socketio,
# url=base_url["int_base_url"]+"/api/environment/status", sleep=40) url=base_url["int_base_url"]+"/api/environment/status", sleep=40)
socketio.start_background_task(stream.tail_f, socketio=socketio) socketio.start_background_task(stream.tail_f, socketio=socketio)
......
...@@ -37,10 +37,8 @@ def send_status(socketio, url, sleep=2, once=False): ...@@ -37,10 +37,8 @@ def send_status(socketio, url, sleep=2, once=False):
# First time # First time
socketio.sleep(sleep) socketio.sleep(sleep)
print(url)
old = requests.get(url).json() old = requests.get(url).json()
status.last[name] = old status.last[name] = old
#socketio.emit(name, old)
while not once: while not once:
socketio.sleep(sleep) socketio.sleep(sleep)
...@@ -78,6 +76,7 @@ def tail_f(socketio, num_lines=30, sleep=0.25, once=False): ...@@ -78,6 +76,7 @@ def tail_f(socketio, num_lines=30, sleep=0.25, once=False):
status.last['new_lines'] = lines status.last['new_lines'] = lines
while not once: while not once:
socketio.sleep(sleep) # Sleep before checking again
current_size = os.path.getsize(filename) current_size = os.path.getsize(filename)
if current_size < file_size: if current_size < file_size:
file_size = 0 file_size = 0
...@@ -91,7 +90,6 @@ def tail_f(socketio, num_lines=30, sleep=0.25, once=False): ...@@ -91,7 +90,6 @@ def tail_f(socketio, num_lines=30, sleep=0.25, once=False):
socketio.emit('new_lines', new_lines) socketio.emit('new_lines', new_lines)
status.last['new_lines'] = new_lines status.last['new_lines'] = new_lines
socketio.sleep(sleep) # Sleep before checking again
def send_binary(socketio): def send_binary(socketio):
......