You wouldn’t download a car?

Wito Mir
3 min readApr 11, 2018

--

A story about building a website, which could wirelessly connect to your car’s ECU using JavaScript and Bluetooth.

In MOT project, we help DVSA to keep UK roads safe. Our R&D team works hard to find a way to connect with vehicles and testing equipment, to make testing process easier, more robust, and fraud-free.

One of our main interests is connecting to a vehicle, and pulling data from it. We could try to aid testers, by automatically reading VIN number, trouble codes, checking if MIL is on (Malfunction Indicator Lamp/Check Engine), or help with emissions testing. Our goal is to be able to quickly read possibly useful data and submit it automatically to MOT system. To make it happen we want to connect with OBDII, which is a diagnostic port, present in all modern cars produced after 2004 (in EU), as an industry standard. In most cases, it allows us to read VIN number, trouble codes, Check Engine light status, and many more. Unfortunately, mileage info is not a part of the specification.

A webpage can connect directly to your car!

Before I started working on the project, I already knew that Google Chrome supports Bluetooth Web API, which allows us to connect to Bluetooth Low Energy devices. I also knew that there are some dongles that support BLE stack.

I started with some sample JS code which was shared on Google Developers blog, to see how does it work. Soon, I created this proof of concept - Chrome connects to my phone, which is simulating a BLE peripheral that exposes battery level info. It sends a BLE notification to the browser, each time slider value changes:

It was nice and easy. Unfortunately there is no documentation on how to communicate with a BLE OBDII dongle (at least I couldn’t find any), and I didn’t even know if Google Chrome will be able to do so. All I had was just my gut feeling, that this might be possible.

I found out, that Chrome is able to read the dongle. That got my hopes up! It also could connect to dongle’s BLE services. I was halfway there. Now comes the worst part — how to make it actually transmit anything? Fortunately, after some “reverse engineering”, I set up the connection and could finally read VIN, engine RPM, temperatures, throttle pedal position or clear trouble codes. I sat in my car, in freezing cold, with my wife angry at me for not helping with Christmas preparations and I finally made it happen!

I couldn’t be happier. What was next, was up to my imagination. The easiest demo I could imagine was repeatedly asking for current engine RPM to create a live RPM gauge on my page and that’s what is shown below. I leave you to it, so you could think about some other fancy Web Bluetooth applications.

More in depth explanation below:

The biggest problem was — there’s absolutely no info on how to communicate with Bluetooth Low Energy OBDII dongle. Using old Bluetooth 2.x you can open a standard serial port connection, by only attaching to a Bluetooth profile. Then you could write to a serial port and read command output from it. In this BLE implementation that’s different — you can send something to a device, and receive the response through a BLE notification.
I started by scanning the dongle with nRF Connect for Mobile. It found 1 interesting service with UUID 0000fff0–0000–1000–8000–00805f9b34fb. It had two characteristics:
- 0000fff2–0000–1000–8000–00805f9b34fb (writable) for sending commands
- 0000fff1–0000–1000–8000–00805f9b34fb (notifications) for receiving the responses as BLE notifications

It wasn’t very intuitive, but fortunately, after registering for notifications from 0000fff1 characteristic, when I sent my first command to 0000fff2, I got a proper response. That’s how I created this proof of concept, that can be found on my github. That code is hacky, and ugly, but demonstrates “the art of possible”. The rest is up to you — here’s how to commincate with ELM327 and it’s AT command list along with OBDII PIDs .

I hope this will help you, whoever you are, if you stumble upon this when searching for OBDII BLE. Good luck! ;)

--

--