Squashed rewrite of the project revival work (replaces prior history on this branch to remove personal data that had been accidentally committed - real LAN IP, GPS coordinates, home WiFi SSID, and phone model). See PLAN.md for full phase-by-phase details. Summary: - Phase 2: adapt app_obd.py for a USB OBD-II adapter (was Bluetooth-only), auto-detect /dev/ttyUSB*, fix several pre-existing crash bugs. - Phase 3/4: make the web UI work fully offline (vendored Socket.IO/Leaflet/ Chart.js/FontAwesome, offline map tile downloader script, live GPS marker tracking fix). - Phase 5: systemd deployment/autostart on the Pi. - Phase 6: WiFi hotspot mode via NetworkManager (auto-switch between home WiFi and a local AP for in-car web UI access), mDNS hostname + port 80 redirect so the UI is reachable at a plain hostname with no port number. - Phase 7: fix app_db.py/app_sql.py bugs, wire up local SQLite trip logging. - Phase 8: brand-agnostic USB dashcam file retrieval (lsblk transport-based detection, works with any dashcam brand/folder layout). - Rewritten readme.md with a proper project overview. Co-authored-by: Copilot <[email protected]>
123 lines
3.7 KiB
JavaScript
123 lines
3.7 KiB
JavaScript
const socket = io();
|
|
// map
|
|
|
|
// Offline tiles pre-downloaded via scripts/download_map_tiles.py (see PLAN.md
|
|
// Phase 3). Only zoom 8-15 is cached by default - matches DEFAULT_MIN_ZOOM/
|
|
// DEFAULT_MAX_ZOOM in that script.
|
|
// Generic placeholder center (not a real location) - re-centers automatically
|
|
// to the real live GPS fix once one comes in (see gps_location handler below).
|
|
var map = L.map('map', { minZoom: 8, maxZoom: 15 }).setView([48.505, -0.09], 12);
|
|
L.tileLayer('/static/vendor/tiles/{z}/{x}/{y}.png', {
|
|
attribution: '© <a href="https://www.maptiler.com/copyright/" target="_blank">MapTiler</a> © <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors',
|
|
minZoom: 8,
|
|
maxZoom: 15
|
|
}).addTo(map);
|
|
var carMarker = L.marker(map.getCenter()).addTo(map)
|
|
.bindPopup('your car... soon(tm)');
|
|
|
|
// charts
|
|
|
|
const ctx = document.getElementById('speedGraph').getContext('2d');
|
|
chart = new Chart(ctx, {
|
|
type: 'line',
|
|
data: {
|
|
datasets: [{
|
|
label: 'Vehicle speed',
|
|
borderColor: 'rgba(75, 192, 192, 1)',
|
|
fill: false,
|
|
}]
|
|
},
|
|
options: {
|
|
responsive: true,
|
|
scales: {
|
|
x: {
|
|
reverse: true,
|
|
title: {
|
|
display: true,
|
|
text: 'Time',
|
|
}
|
|
},
|
|
y: {
|
|
title: {
|
|
display: true,
|
|
text: 'Speed'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
// websockets
|
|
|
|
socket.on('connect', function(data) {
|
|
console.log('socket.io is connected')
|
|
});
|
|
|
|
socket.on('obd_status', function(data) {
|
|
console.log(data);
|
|
const status = document.getElementById('obd-status');
|
|
status.innerHTML = data;
|
|
});
|
|
|
|
socket.on('obd_speed', function(data) {
|
|
|
|
const time = data[0]; // Assuming data[0] is the time value
|
|
const speed = data[1]; // Assuming data[1] is the speed value
|
|
const maxDataPoints = 8; // Adjust this value as needed
|
|
|
|
const status = document.getElementById('obd-speed');
|
|
status.innerHTML = speed;
|
|
|
|
// Get a reference to the chart's data
|
|
const chartData = chart.data.datasets[0].data;
|
|
|
|
// Unshift the new data points to the beginning of the chart dataset
|
|
chartData.unshift({ x: time, y: speed });
|
|
|
|
// Remove data points if the number of data points exceeds maxDataPoints
|
|
while (chartData.length > maxDataPoints) {
|
|
chartData.pop(); // Remove the oldest data point from the end
|
|
}
|
|
|
|
// Update the chart
|
|
chart.update();
|
|
|
|
});
|
|
|
|
socket.on('obd_rpm', function(data) {
|
|
console.log("obd rpm "+data);
|
|
const status = document.getElementById('obd-rpm');
|
|
status.innerHTML = data;
|
|
});
|
|
|
|
socket.on('obd_error', function(data) {
|
|
console.log("obd errors "+data);
|
|
const status = document.getElementById('obd-error');
|
|
status.innerHTML = data;
|
|
});
|
|
|
|
socket.on('rpi_uptime', function(data) {
|
|
const status = document.getElementById('rpi-uptime');
|
|
status.innerHTML = data;
|
|
});
|
|
|
|
let mapCentered = false;
|
|
|
|
socket.on('gps_location', function(data) {
|
|
console.log("location received")
|
|
const LocationX = document.getElementById('gpsLocationX');
|
|
const LocationY = document.getElementById('gpsLocationY');
|
|
LocationX.innerHTML = data[0];
|
|
LocationY.innerHTML = data[1];
|
|
|
|
const lat = data[0];
|
|
const lon = data[1];
|
|
if (lat != null && lon != null) {
|
|
carMarker.setLatLng([lat, lon]);
|
|
if (!mapCentered) {
|
|
map.setView([lat, lon], 15);
|
|
mapCentered = true;
|
|
}
|
|
}
|
|
});
|