Feat: add SLM live monitoring improvements #60
@@ -169,25 +169,18 @@ async def get_live_view(request: Request, unit_id: str, db: Session = Depends(ge
|
|||||||
is_measuring = False
|
is_measuring = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with httpx.AsyncClient(timeout=10.0) as client:
|
# Read SLMM's CACHED status (NL43Status) — no device call. The live monitor
|
||||||
# Get measurement state
|
# keeps it fresh (~1.3s) and the live-stream WS provides ongoing updates, so we
|
||||||
state_response = await client.get(
|
# no longer fire Measure? + a fresh DOD read at the device on every command-
|
||||||
f"{SLMM_BASE_URL}/api/nl43/{unit_id}/measurement-state"
|
# center load (which competed with DOD polling for the single connection).
|
||||||
)
|
async with httpx.AsyncClient(timeout=5.0) as client:
|
||||||
if state_response.status_code == 200:
|
r = await client.get(f"{SLMM_BASE_URL}/api/nl43/{unit_id}/status")
|
||||||
state_data = state_response.json()
|
if r.status_code == 200:
|
||||||
measurement_state = state_data.get("measurement_state", "Unknown")
|
current_status = r.json().get("data", {})
|
||||||
is_measuring = state_data.get("is_measuring", False)
|
measurement_state = current_status.get("measurement_state")
|
||||||
|
is_measuring = measurement_state in ("Start", "Measure")
|
||||||
# Get live status (measurement_start_time is already stored in SLMM database)
|
|
||||||
status_response = await client.get(
|
|
||||||
f"{SLMM_BASE_URL}/api/nl43/{unit_id}/live"
|
|
||||||
)
|
|
||||||
if status_response.status_code == 200:
|
|
||||||
status_data = status_response.json()
|
|
||||||
current_status = status_data.get("data", {})
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to get status for {unit_id}: {e}")
|
logger.error(f"Failed to get cached status for {unit_id}: {e}")
|
||||||
|
|
||||||
return templates.TemplateResponse("partials/slm_live_view.html", {
|
return templates.TemplateResponse("partials/slm_live_view.html", {
|
||||||
"request": request,
|
"request": request,
|
||||||
|
|||||||
Reference in New Issue
Block a user