Update Contec monitor service, parser, dashboard and tunneling
This commit is contained in:
@@ -105,7 +105,8 @@ async def lifespan(app: FastAPI):
|
||||
print("\n" + "=" * 65)
|
||||
print(f" Contec {model} Patient Monitor - Vital Signs Forwarder")
|
||||
print("=" * 65)
|
||||
print(f" DASHBOARD: http://localhost:{port}/api/dashboard")
|
||||
print(f" DASHBOARD: http://localhost:{port}/dashboard")
|
||||
print(f" http://localhost:{port}/api/dashboard")
|
||||
print(f" API Docs: http://localhost:{port}/docs")
|
||||
print(f" Contec Ports: {settings.contec_ports}")
|
||||
print(f" Monitor Model: {model}")
|
||||
@@ -124,10 +125,34 @@ async def lifespan(app: FastAPI):
|
||||
# Startup: Start the background retry task
|
||||
retry_task = asyncio.create_task(retry_failed_transmissions())
|
||||
|
||||
# Startup: Start bore tunnel for remote monitors if available and not already running
|
||||
bore_proc = None
|
||||
bore_exe = os.path.join(os.path.dirname(os.path.abspath(__file__)), "bore.exe")
|
||||
if os.path.exists(bore_exe):
|
||||
import subprocess
|
||||
try:
|
||||
check_out = subprocess.check_output('tasklist /FI "IMAGENAME eq bore.exe"', shell=True).decode()
|
||||
if "bore.exe" not in check_out:
|
||||
bore_proc = subprocess.Popen(
|
||||
[bore_exe, "local", "511", "--to", "159.223.110.159", "--port", "61501"],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL
|
||||
)
|
||||
logger.info(" [OK] Bore tunnel active for remote hotspot monitors (159.223.110.159:61501)")
|
||||
else:
|
||||
logger.info(" [INFO] Bore tunnel is already running")
|
||||
except Exception as e:
|
||||
logger.debug(f"Could not check/start bore tunnel: {e}")
|
||||
|
||||
yield
|
||||
|
||||
# Shutdown
|
||||
logger.info("Shutting down servers...")
|
||||
if bore_proc:
|
||||
try:
|
||||
bore_proc.terminate()
|
||||
except Exception:
|
||||
pass
|
||||
retry_task.cancel()
|
||||
for server in servers:
|
||||
server.close()
|
||||
@@ -156,6 +181,13 @@ app.add_middleware(
|
||||
# Include dashboard routes
|
||||
app.include_router(dashboard.router, prefix="/api")
|
||||
|
||||
# Also serve dashboard at root and /dashboard directly for convenience
|
||||
from fastapi.responses import HTMLResponse
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
@app.get("/dashboard", response_class=HTMLResponse)
|
||||
def serve_dashboard_root():
|
||||
return dashboard.serve_dashboard()
|
||||
|
||||
# Serve static folder
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
app.mount("/static", StaticFiles(directory="static"), name="static")
|
||||
|
||||
Reference in New Issue
Block a user