diff --git a/app.py b/app.py index f6c0868..183305b 100644 --- a/app.py +++ b/app.py @@ -139,6 +139,15 @@ def trips(): def gps_status(): return jsonify(app_gps.get_status()) +@app.route('/api/obd/status') +def obd_status(): + return jsonify({ + "adapter_present": bool(app_obd._find_obd_port()), + "port": app_obd._find_obd_port(), + "car_connected": app_obd._is_car_connected(), + "status_label": "Connected" if app_obd._is_car_connected() else "Disconnected", + }) + @app.route('/api/trip/') def trip_route(trip_id): trip = app_sql.get_trip_route(trip_id) diff --git a/static/js/yaris.js b/static/js/yaris.js index 8ef1a52..cfcb327 100644 --- a/static/js/yaris.js +++ b/static/js/yaris.js @@ -235,8 +235,8 @@ function renderGpsStatus(status) { badgeClass = stale ? 'text-bg-warning' : 'text-bg-success'; detail = formatGpsAge(status.fix_age_seconds); // Show lat/lon from API response (not just socket events) - if (locX) locX.textContent = status.latitude != null ? status.latitude.toFixed(6) : '—'; - if (locY) locY.textContent = status.longitude != null ? status.longitude.toFixed(6) : '—'; + if (locX) locX.textContent = status.latitude != null ? Number(status.latitude).toFixed(6) : '—'; + if (locY) locY.textContent = status.longitude != null ? Number(status.longitude).toFixed(6) : '—'; } else { label = 'No fix'; badgeClass = 'text-bg-warning'; @@ -305,3 +305,18 @@ window.setInterval(function () { if (fixDetail) fixDetail.textContent = error.message; }); }, 15000); + +async function refreshObdStatus() { + try { + const resp = await fetch('/api/obd/status'); + const status = await resp.json(); + const el = document.getElementById('obd-status'); + if (el) el.textContent = status.adapter_present + ? (status.car_connected ? 'Connected' : 'Adapter only') + : 'Not detected'; + } catch (e) { + // Socket events will eventually update it + } +} +refreshObdStatus(); +window.setInterval(refreshObdStatus, 15000);