· via dev.to (home feed)
obd2_kit brings ELM327 OBD-II adapter support to Dart over any transport
A new Dart package handles the ELM327 session, SAE J1979 services, multi-ECU replies and live PID polling, leaving the transport — Bluetooth, BLE, Wi-Fi or USB — to the app.

A new Dart package named obd2_kit lets Dart and Flutter applications talk to ELM327 OBD-II adapters without caring how the bytes travel. According to its announcement on dev.to, the library implements the adapter session, the SAE J1979 diagnostic services, replies that span several ECUs or several frames, and live polling, while the app supplies the transport: Bluetooth SPP, BLE UART, Wi-Fi TCP or USB serial.
The protocol half, isolated
Reading a car looks simple on paper: send 010C and get the engine speed back. The dev.to post lays out why it is not. The adapter is effectively a text terminal that echoes commands, prints SEARCHING... while locating the bus, answers in several small chunks, and reports failures as plain words such as NO DATA or BUS BUSY. obd2_kit puts all of that behind a three-member interface, ObdTransport, exposing input, write and close. A TCP transport for Wi-Fi dongles ships with the package — most listen on 192.168.0.10:35000 — and Bluetooth, BLE or USB is a matter of implementing the interface over an existing stream. The package is consumed as a Git dependency from its GitHub repository.
Session, services and polling
The Elm327 class runs the init sequence (ATZ, ATE0, ATL0, ATS0, ATH1 or ATH0, ATAT1, ATSP0), triggers the protocol search with a 0100 request, and reads the detected protocol via ATDPN. It waits for the > prompt even when replies arrive in fragments, strips echo lines and bus-init chatter, and converts error replies into a typed ElmErrorException carrying an ElmError value, so calling code matches on a type instead of comparing strings. Commands pass through a FIFO queue that sends one at a time, each with a timeout and an optional ObdCancelToken. A running command that times out or is cancelled is interrupted: the session sends a single byte, waits for the prompt, then continues, so a late reply is never matched to the next command.
ObdClient covers J1979 modes 01 (current data), 02 (freeze frame), 03 (stored codes), 04 (clear codes), 07 (pending codes), 09 (VIN and other vehicle information) and 0A (permanent codes). Modes 05, 06 and 08, along with manufacturer-specific services, are out of scope. Clearing codes requires clearDtcs(confirm: true) and throws an ArgumentError without it. That guard is deliberate: clearing turns off the malfunction indicator lamp and resets every readiness monitor, which can leave the vehicle failing an emissions inspection until it has been driven through its monitors again.
Frames, typed values and trouble codes
Frame parsing handles replies with headers enabled — 11-bit and 29-bit CAN, plus ISO 9141-2, ISO 14230-4 KWP and SAE J1850 with their header bytes and checksum. Replies from multiple ECUs are separated by identifier, and ISO 15765-2 multi-frame messages are reassembled with sequence-number checks, including the wrap from F to 0. Decoding returns typed values: a NumericValue with its unit, monitor status, supported-PID bitmaps, DTC values, or a RawValue fallback for PIDs the package does not decode, such as fuel system status and the oxygen-sensor range. The Dtc class parses P, C, B and U codes, sorts them into generic, manufacturer or reserved categories using SAE J2012 ranges, and reports the P0 subsystem group. No DTC description texts ship with the package; the author found no generic P0xxx list under an MIT-compatible licence, so descriptions plug in through a DtcDescriptionProvider.
For live data, ObdMonitor polls a set of PIDs, each on its own interval, and emits a stream of readings. Only one request is in flight at a time, the most overdue PID goes next with round-robin tie-breaking, and request errors surface as stream errors while polling continues.
Clone adapters
Most cheap adapters are ELM327 clones, and the session accounts for their known behaviours. A banner reporting v1.5 — a version Elm Electronics never released — sets isKnownCloneVersion, though a clone can also report a genuine version, so a false value proves nothing. ATAT1 and ATS0 are optional during initialization because some clones reply with a question mark, and readVoltage returns null when the voltage query does too. NUL bytes and garbage around ATZ are removed, ATZ is retried once after a timeout, echo lines are stripped even when the adapter keeps echoing after ATE0, and a minGap option spaces requests apart for clones that misbehave when commands arrive back to back.
Why it matters
For anyone building a car dashboard, trip logger or diagnostics tool in Flutter, the transport-agnostic split means one protocol implementation serves every link type, and the awkward edge cases — multi-frame VINs, multi-ECU replies, clone quirks, timed-out commands — are handled once instead of per app. The stated limits are also clear: tests run against a scripted fake adapter modelled on datasheet examples rather than every clone, only one PID is requested per Mode 01 query for compatibility with older buses, and the package contains no copied dataset, with its formulas written from the public standards it lists (the ELM327 datasheet, SAE J1979, SAE J2012 and ISO 15765).
- #dart
- #flutter
- #obd-ii
- #elm327
- #open-source
- #automotive