fix: add /api/obd/status endpoint, dashboard OBD fallback on page load, fix GPS string-to-number crash

This commit is contained in:
Mathieu Moran
2026-08-11 16:26:30 -04:00
parent e223a43170
commit 91281b1e55
2 changed files with 26 additions and 2 deletions
+17 -2
View File
@@ -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);