A few days ago I mentioned on my sustainable fuel site TheSmartDrive that I was given a Tesla Roadster to drive for a few days. I was asked to see what ECU information is available, collect and parse the data from it. Tesla Motors periodically collects information from their vehicles presumably to see what real-world driving the cars see. On original Roadster models there is no method to collect this information remotely thus someone must go out to the vehicle and collect it. The owner of the vehicle saw this and wanted to know what information was collected on these service calls.
After some digging I found information on the Tesla Motors Club forum about log files that can be collected via a cabin USB port. To get the logs use a USB stick and add a folder named “VehicleLogs” to the root, plug it in, turn the key on and off and watch the screen tell you it is downloading the logs. I have no idea why, but it takes about 15 min to download a 12M TAR file.
As one can expect the data logs are not in clear text, but rather a proprietary binary format. After some more digging I found a Tesla Motor Club post on the format of the binary data logs done by someone with way more time than myself. Many thanks go to users scott451 and tomsax for their reverse engineering. The binary file contains two sections, the first is a long term data logging section with 1 entry per day since the vehicle was made along with firmware update information and other vehicle data. The second section is an 8M wrapped block for data on driving and charging of the vehicle. Data while driving is saved once per second, minute and 10 minutes. Data from charging is once per minute as well as other unknown entries.
The information write up by tomsax includes a parser for Windows. I’m not sure how well the parser works because I use Linux for all my computers and didn’t bother trying it, plus there is no source, so no freedom. No problem, armed with the binary format I decided to parse the logs myself, enter Python. A few months ago I learned about the construct library for parsing packets of data, so I whipped up a really simple script to brute process the log and dump the data out. Pipe the data to a .CSV file and you have all the data for your spreadsheet-of-choice program.
Because I am a big fan of freedom to modify a program to fit ones needs, I have uploaded the (very basic and kinda ugly) python script to parse Tesla logs. (Since my webhost is paranoid change extension to .py from .txt). Because the actual logs I pulled are not from my own vehicle I have not put them up here, for obvious privacy reasons. If you want to get some to play with, check the Tesla Motors Club forums.
There are still a number of entries in the logs that have not been identified so if someone out there is a decoding genius and looking for something to do here is a prime candidate.
It was really cool playing with the Tesla logs. I really like the fact that an owner can get information about the history of their vehicle. There are tons of after market OBDII add-ons that allow data logging and I honestly wish more vehicles would allow their owners to collect this information. I will keep wishing.
A quick note on vehicle security. The data logs are downloaded to a USB stick and as far as I know there is no read-write sequence back to the main vehicle ECU so I am assuming this is a one way dump. The USB port in the Tesla is not hidden and one would expect that anything plugged into the car other than a USB stick would require validation or handshaking routine to access anything on the ECU. I write hybrid battery ECU code and that’s what I did in my systems.
Enjoy the code and leave some comments