fix: add /api/obd/status endpoint, dashboard OBD fallback on page load, fix GPS string-to-number crash
This commit is contained in:
@@ -139,6 +139,15 @@ def trips():
|
|||||||
def gps_status():
|
def gps_status():
|
||||||
return jsonify(app_gps.get_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/<int:trip_id>')
|
@app.route('/api/trip/<int:trip_id>')
|
||||||
def trip_route(trip_id):
|
def trip_route(trip_id):
|
||||||
trip = app_sql.get_trip_route(trip_id)
|
trip = app_sql.get_trip_route(trip_id)
|
||||||
|
|||||||
+17
-2
@@ -235,8 +235,8 @@ function renderGpsStatus(status) {
|
|||||||
badgeClass = stale ? 'text-bg-warning' : 'text-bg-success';
|
badgeClass = stale ? 'text-bg-warning' : 'text-bg-success';
|
||||||
detail = formatGpsAge(status.fix_age_seconds);
|
detail = formatGpsAge(status.fix_age_seconds);
|
||||||
// Show lat/lon from API response (not just socket events)
|
// Show lat/lon from API response (not just socket events)
|
||||||
if (locX) locX.textContent = status.latitude != null ? status.latitude.toFixed(6) : '—';
|
if (locX) locX.textContent = status.latitude != null ? Number(status.latitude).toFixed(6) : '—';
|
||||||
if (locY) locY.textContent = status.longitude != null ? status.longitude.toFixed(6) : '—';
|
if (locY) locY.textContent = status.longitude != null ? Number(status.longitude).toFixed(6) : '—';
|
||||||
} else {
|
} else {
|
||||||
label = 'No fix';
|
label = 'No fix';
|
||||||
badgeClass = 'text-bg-warning';
|
badgeClass = 'text-bg-warning';
|
||||||
@@ -305,3 +305,18 @@ window.setInterval(function () {
|
|||||||
if (fixDetail) fixDetail.textContent = error.message;
|
if (fixDetail) fixDetail.textContent = error.message;
|
||||||
});
|
});
|
||||||
}, 15000);
|
}, 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);
|
||||||
|
|||||||
Reference in New Issue
Block a user