Fix slow OBD value load on dashboard (BUG-19)
This commit is contained in:
@@ -314,9 +314,26 @@ async function refreshObdStatus() {
|
||||
if (el) el.textContent = status.adapter_present
|
||||
? (status.car_connected ? 'Connected' : 'Adapter only')
|
||||
: 'Not detected';
|
||||
|
||||
// Fill the value cards from the REST snapshot so they appear immediately
|
||||
// on load, even if the socket connection is slow to establish. Socket
|
||||
// events keep updating them live afterward.
|
||||
if (status.car_connected) {
|
||||
fillObdValueCard('obd-speed', status.speed, 'km/h');
|
||||
fillObdValueCard('obd-rpm', status.rpm, 'rpm');
|
||||
fillObdValueCard('obd-coolant', status.coolant_temp, '°C');
|
||||
fillObdValueCard('obd-fuel', status.fuel_level, '%');
|
||||
fillObdValueCard('obd-throttle', status.throttle_position, '%');
|
||||
}
|
||||
} catch (e) {
|
||||
// Socket events will eventually update it
|
||||
}
|
||||
}
|
||||
|
||||
function fillObdValueCard(id, value, unit) {
|
||||
if (value == null) return;
|
||||
const el = document.getElementById(id);
|
||||
if (el) el.textContent = value + ' ' + unit;
|
||||
}
|
||||
refreshObdStatus();
|
||||
window.setInterval(refreshObdStatus, 15000);
|
||||
|
||||
Reference in New Issue
Block a user