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