Files
yaris-obd/readme.md
T
Mathieu Moran 0d67a21ae1 Add phone-relay dashcam upload to bypass the Pi's slow WiFi
Root-caused the slow-upload complaint to the Pi's own congested 2.4GHz
WiFi radio (confirmed via iperf3 - same degraded throughput even on
pure local LAN traffic, ruling out Cloudflare/ISP). Since the Pi 3 B
has no 5GHz radio, add a way to bypass it for the internet-bound leg:
a phone opens /dash and manually relays pending dashcam files straight
to the remote server over its own network, reusing the exact same
chunked upload protocol the Pi's client already uses.

- server/app.py: add CORS headers (after_request) so the phone's
  browser can call the remote server cross-origin from a page served
  by the Pi.
- app.py: new endpoints - GET /api/dash/pending (list not-yet-uploaded
  files), GET /api/dash/file/<path> (Range-request-capable download,
  path-traversal safe), GET /api/dash/relay/config (hands the phone
  the device credentials), POST /api/dash/relay/heartbeat|stop (lease-
  based pause of the Pi's own background uploader, self-heals if the
  phone's tab closes uncleanly), POST /api/dash/relay/mark_uploaded.
- modules/app_upload.py: list_pending_dashcam_files(), relay lease
  helpers, _upload_dashcam_files() now pauses while a relay lease is
  active.
- modules/app_sql.py: new dashcam_hash_cache table so a file's sha256
  is only computed once (keyed by path+size+mtime) instead of being
  recomputed on every loop iteration/pending-list call - benefits the
  existing background uploader too.
- templates/dash.html / static/js/dash.js: new "Relay via phone" card
  - per-file and "relay all" buttons (manual trigger only, per user
  preference), downloads+uploads one 40MB slice at a time so the
  phone never holds a whole file in memory, retries chunks up to 3x.
- PLAN.md/readme.md/server/README.md updated (Phase 11).

Tested via a full local end-to-end simulation driving the real Pi and
server Flask apps side by side (Postgres mocked only at the db module
boundary - all HTTP/chunking/auth/CORS logic is real): verified Range
downloads (206), byte-for-byte reassembly via SHA256, path-traversal
rejection, and the relay lease correctly pausing/resuming the
background uploader. Not yet tested against a real phone/live network.
2026-08-09 00:15:27 -04:00

87 lines
4.1 KiB
Markdown

# yaris-obd 🚗📡
A Raspberry Pi 3-based OBD-II + GPS tracker for my 2013 Toyota Yaris — reads live vehicle data
over USB, tracks position with a SIM868 GNSS/GSM HAT, and serves it all from a local web UI you
can pull up on your phone by connecting to the car's own WiFi hotspot. Fully usable offline: no
internet needed in the car, offline map tiles included. Also handles pulling dashcam footage off
a USB dashcam for local/remote backup.
<table>
<tr>
<td width="120">
<a href="https://open.spotify.com/playlist/5u9vSw39FrIz7KghBkmgH4">
<img src="https://image-cdn-fa.spotifycdn.com/image/ab67706c0000d72c979ac180a23a70139d1ebd81" width="100" />
</a>
</td>
<td>
**rené lévesque bangers**
i have a dream
[![Listen on Spotify](https://img.shields.io/badge/Listen_on-Spotify-1DB954?style=for-the-badge&logo=spotify&logoColor=white)](https://open.spotify.com/playlist/5u9vSw39FrIz7KghBkmgH4)
</td>
</tr>
</table>
## Screenshot
![UI](https://github.com/quoije/yaris-obd/blob/698adee41532fed0ba1a7fe0ab83b26d569764cb/pics/ui.png)
## Features
- 📊 **Live OBD-II data** (speed, RPM, DTC codes) over a cheap USB ELM327-compatible adapter
- 🛰️ **Real GPS tracking** via a Waveshare SIM868 GNSS/GSM/Bluetooth HAT, plotted live on an
offline Leaflet map (pre-cached map tiles — no internet needed in the car)
- 📶 **Self-hosted WiFi hotspot** so you can load the web UI on your phone from inside the car,
with automatic fallback to your home WiFi when in range (`http://yaris.local` — no port number)
- 🎥 **Dashcam file retrieval** — detects a USB dashcam automatically (any brand/folder layout,
no hardcoded device path), copies its footage locally, verified against real hardware
- ☁️ **Remote upload** — a self-hosted server (Flask + Postgres, `server/`) receives trip/GPS
logs and dashcam footage over the internet (via Cloudflare Tunnel or a plain port-forward).
Dashcam videos upload in resumable 40MB chunks (works around tunnel body-size limits and keeps
the Pi's memory footprint flat regardless of file size); a UI toggle can pause dashcam uploads
independently while trip logs keep syncing
- 📱 **Phone-relay upload** — if the Pi's own WiFi is slow/congested, open `/dash` on your phone
to download pending dashcam files locally and re-upload them straight to the remote server
using the phone's own network instead, automatically pausing the Pi's own upload meanwhile
- 🗄️ Local SQLite trip logging, retried/synced to the remote server with automatic backoff
- 🔌 Runs fully headless as a `systemd` service, autostarting on boot
## Hardware
| Part | Notes |
| --- | --- |
| Raspberry Pi 3 Model B | Web UI host + hotspot |
| Waveshare SIM868 HAT | GNSS (GPS) + GSM/GPRS, unused Bluetooth |
| USB OBD-II adapter | PL2303-based, ELM327-compatible (originally Bluetooth, switched to USB) |
| USB dashcam | Any brand — detected as generic USB mass storage |
| 2013 Toyota Yaris | The patient |
See [PLAN.md](./PLAN.md) for full hardware bring-up notes (SIM868 jumper/UART setup, antenna
gotchas, etc.) and the detailed project history.
## Getting started
```bash
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python3 app.py
```
The app serves on `http://<host>:5000`. On the Pi it also runs as a `systemd` service
(see [deploy/](./deploy)) and is reachable with no port number at `http://yaris.local` once the
mDNS + port-redirect setup described in [PLAN.md](./PLAN.md) is installed.
For the remote server (receives trip logs + dashcam uploads), see [server/README.md](./server/README.md).
## Project status
This project was revived after a couple of years on the shelf. All 11 planned phases are done and
the full pipeline — OBD/GPS logging, offline web UI, WiFi hotspot, dashcam retrieval, remote
upload, and phone-relay upload — has been verified against real hardware end-to-end, including a
full real dashcam import and upload run. Only the SIM868 cellular fallback (for uploading while
out of WiFi range) and the phone-relay feature's real-phone/live-network test remain untested.
Full phase-by-phase history in [PLAN.md](./PLAN.md).