Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

OBD2 Reader

A mobile-friendly Next.js app for the ELM327 WiFi OBD-II adapter. Implements the full SAE J1979 service mode set (01–0A):

  • Mode 01 — live powertrain PIDs with a two-tier (fast / slow) polling loop
  • Mode 02 — freeze-frame snapshots per stored DTC
  • Mode 03 / 07 / 0A — stored, pending, and permanent DTCs
  • Mode 04 — clear DTCs (confirmation required)
  • Mode 05 / 06 — on-board monitor test results
  • Mode 08 — bidirectional control (EVAP, fuel pump, fan, A/C, …)
  • Mode 09 — VIN, calibration ID, CVN, ECU name

Architecture

Browser (mobile / desktop)
      │  WebSocket  (ws://host:3000/ws/obd)
      ▼
Next.js custom server (server.mjs)
      │  TCP socket
      ▼
ELM327 WiFi adapter  (e.g. 192.168.0.10:35000)
      │  CAN / ISO / KWP
      ▼
Vehicle ECU(s)

A tiny Node.js WebSocket ↔ TCP bridge is run as a custom Next.js server (server.mjs). The browser never speaks to the adapter directly — everything goes through the local proxy so you get auto-reconnect, a serialized command queue, and a command-response state machine.

Quick start

With the bundled simulator (no hardware required)

pnpm install
pnpm mock   # terminal 1 — starts the fake ELM327 on TCP 35000
pnpm dev    # terminal 2 — starts Next.js + WS bridge on http://localhost:3000

Open http://localhost:3000, enter localhost / 35000 on the setup page, and you'll get:

  • Live gauges updating in real time (drifting RPM, speed, temps, voltage, fuel rate…)
  • Two stored DTCs (P0133, P0420) and one pending (P0171)
  • Freeze-frame snapshot with triggering DTC
  • Vehicle info reporting VIN 1HGCM82633A123456
  • Mode 06 monitor tests with pass/fail indicators

Emulating the Peugeot 206 profile

The mock can also emulate a 2005 Peugeot-style K-line ECU — KWP Fast, thin PID set, no Mode 06 / Mode 0A coverage:

# Windows PowerShell
$env:MOCK_PROFILE = "peugeot"; pnpm mock

# macOS / Linux
MOCK_PROFILE=peugeot pnpm mock

Then pick Peugeot 206 1.6 16V (2005) in the Setup page's vehicle profile dropdown.

With real hardware

  1. Power the vehicle (ignition on).
  2. Connect to the adapter's WiFi SSID (WiFi_OBDII, V-LINK, etc).
  3. pnpm dev, navigate to the setup page, enter the adapter's IP (usually 192.168.0.10) and port 35000.
  4. Pick a vehicle profile. For a 2005 Peugeot 206 1.6 16V, choose Peugeot 206 1.6 16V (2005) — the app will try KWP Fast first, then KWP 5-baud, then ISO 9141-2 before giving up, and apply K-line-friendly adapter timings.
  5. Optional: force a protocol from the dropdown if auto-detect is flaky.
  6. The app handshakes the ELM327, probes each candidate protocol, reads the supported-PID bitmaps, and starts the live poll loop.
  7. Open Diagnostics to run the post-connect smoke test and view the protocol / PID / mode capability report.

Project layout

src/
├── app/
│   ├── layout.tsx             Dark automotive theme + font setup
│   ├── page.tsx               Redirects to /setup or /dashboard
│   ├── setup/                 Adapter host/port + test connection
│   └── dashboard/
│       ├── layout.tsx         AppShell + shared ObdProvider
│       ├── page.tsx           Overview gauges
│       ├── live/              Every supported PID (two-tier toggle)
│       ├── dtc/               Modes 03/07/0A + Mode 04 clear
│       ├── freeze/            Mode 02 freeze-frame snapshots
│       ├── sensors/           Mode 06 on-board monitor results
│       ├── vehicle/           Mode 09 VIN / cal ID / ECU name
│       ├── diagnostics/       Protocol negotiation log, smoke test,
│       │                      mode / PID capability report
│       ├── control/           Mode 08 bidirectional actions
│       └── settings/          Fast-tier PID selection + reset
├── components/
│   ├── layout/                Sidebar, mobile bottom-nav, AppShell
│   ├── obd/                   GaugeCard, PidRow, DtcCard, …
│   └── ui/                    shadcn primitives
├── hooks/
│   ├── use-obd-connection.ts  WebSocket + ELM327 state machine
│   ├── use-live-pids.ts       Two-tier fast/slow polling loop
│   ├── use-dtc-scanner.ts     Mode 03 / 07 / 0A / 04
│   └── use-vehicle-info.ts    Mode 09
├── lib/
│   ├── obd/                   Framework-agnostic OBD core (types, parser,
│   │                          ELM327 state machine, PID dictionary, DTC
│   │                          descriptions, vehicle profiles, capability
│   │                          layer)
│   └── psa/                   Reserved for PSA-specific diagnostics —
│                              stubbed, see docs/psa-diagnostics-architecture.md
└── styles/globals.css         Automotive dark tokens

server.mjs                     Custom Next.js server with WS ↔ TCP bridge
mock-elm327.mjs                Dev-only ELM327 simulator (TCP 35000)

Two-tier live polling

The live polling hook (src/hooks/use-live-pids.ts) interleaves two pools over the single ELM327 command queue:

  • Fast tier — a small set of user-selected PIDs (RPM, speed, coolant, throttle, load, MAF, voltage by default). Polled continuously.
  • Slow tier — every other supported PID, cycled through round-robin.

The ratio is configurable (slowRatio — default 4 means four fast queries per slow query). The fast-tier selection persists in localStorage and can be edited per-PID from the Live Data and Settings pages.

Scripts

Command What it does
pnpm dev Starts Next.js + the WS↔TCP bridge on port 3000
pnpm mock Starts the ELM327 simulator on TCP 35000
pnpm build Production build
pnpm start Production start (Next.js only; no WS bridge)
pnpm check next lint && tsc --noEmit
pnpm format:write Prettier format

For production you would deploy server.mjs (not next start) so the WS bridge remains available.

Safety notes

  • Mode 08 bidirectional controls (EVAP leak test, fan control, pump cycling, etc.) actuate vehicle systems. The UI wraps every dangerous action in a confirmation dialog, but you should still only run them with the engine in a safe state.
  • Clear DTCs (Mode 04) resets emissions monitor readiness — most US states fail emissions inspections until the monitors re-complete a drive cycle.

Vehicle profiles

The app ships with five profiles in src/lib/obd/vehicle-profiles.ts:

Profile Target
Generic EOBD / OBD-II Auto-detect protocol, trust the supported-PID bitmap.
Peugeot 206 1.6 16V (2005) TU5JP4/NFU, K-line, KWP Fast first, trimmed PID set, weak Mode 06/08/0A.
Ford Ranger PJ 2.2 Petrol (2008, SA) Mazda F2-family 2.2 L petrol on PJ Ranger platform, K-line, thin base-spec PID set, no MAF.
Tata Indica 1.4 Petrol (2014, SA) Tata 475SI / Safire MPFI (eV2 / Vista), K-line, slow ECU timings, very thin PID set.
Hyundai H100 2.6 Diesel (2024, SA) D4BB IDI turbo-diesel light commercial. K-line if it talks at all; diesel semantics (no O2 / no fuel trims). Best-effort only — Hyundai-specific tooling often required.

A profile declares:

  • protocolStrategy — ordered list of ELM327 protocols to try (auto, CAN variants, KWP Fast/5-baud, ISO 9141-2, etc.).
  • expectedPids / optionalPids / unreliablePids — what to show on the fast tier, what to probe, and what to suppress from slow-tier polling.
  • weakModes — modes that are known to be unsupported on this ECU (disabled or warned-about in the UI).
  • postInitCommands — adapter settings applied after protocol negotiation (e.g. ATAT1, ATST64 for slow K-line ECUs).

The runtime capability.ts layer combines the profile with the live ECU's supported-PID / supported-MID / supported infotype bitmaps to classify each PID and mode (supported, expected, optional, unreliable, unsupported). The Diagnostics page visualises this and lets you run a post-connect smoke test.

PSA-specific diagnostics (Lexia / DiagBox territory)

Generic ELM327 + J1979 covers only the emissions-related powertrain surface. PSA-specific diagnostics (ABS, airbag, BSI, body, actuator tests, key programming, ECU coding, deep engine adaptations) is a separate integration track and is intentionally not implemented in this app.

See docs/psa-diagnostics-architecture.md for the architectural decision, hardware/protocol requirements, and the rules for src/lib/psa/ (which is reserved for that track and decoupled from src/lib/obd/).

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages