Tesla Roadster Log Parsing

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

S1axter

  • By Adam, November 4, 2010 @ 4:08 pm

    Very neat! Any idea from the logs what brand of data logger they used, or who manufactured it?

  • By Marcus Wanner, November 4, 2010 @ 4:57 pm

    Slashdotted; Have fun 😉

  • By notbenh, November 4, 2010 @ 6:17 pm

    Seems like github.com would be a great place to host this.

  • By dia, November 5, 2010 @ 12:51 am

    wow.
    dude, you have been /.ed and yet there are no comments.
    how does that make you feel?

  • By Rohit, November 5, 2010 @ 1:37 am

    This is pretty awesome stuff.

  • By Ramjet, November 5, 2010 @ 5:47 am

    I just stated learning Python yesterday, saw this on Slashdot and thought I’d have a look. And having done so I think you may have a small typo in the text version of your Python code as in “processPacketToCSV” there’s a line that reads:

    elif(header.type == 6and (specifictype==header.type or specifictype==0)):

    Whereas I think it should be:

    elif(header.type == 6 and (specifictype==header.type or specifictype==0)):

    i.e. I think the condition should be “6 and” not “6and”.

    Then again Python probably works this out for you so what do I know ?

    Cheers.

  • By s1axter, November 5, 2010 @ 8:27 am

    Eh, I was busy traveling, just getting around to approving them now.

  • By s1axter, November 5, 2010 @ 8:29 am

    Thanks Ramjet, fixed it.

  • By Tom Saxton, November 5, 2010 @ 11:53 am

    Although I haven’t made my code open source, my document tells you as much as the source code would. s1axter proved this by writing a parser without spending the many hours of effort it takes to figure things out from scratch. I think that gives considerable freedom to others interested in parsing the data.

    Also, both Scott and I provide Mac builds of our parsers.

  • By Rob, November 9, 2010 @ 10:13 am

    Hey can you upload a sample(even fake) test log file? I would love to investigate this but with no data to work with the python script is simply useless.

  • By Jake Wharton, November 9, 2010 @ 12:58 pm

    I too think a formal python package and a GitHub project are in order.

    It would also be cool to include sample data so people can try it for themselves (and maybe resolve the unknowns).

  • By mark13, November 10, 2010 @ 9:16 am

    and we will miss the day the cars weren’t be vulnerable by software virus…

  • By Bruno, September 13, 2015 @ 12:28 am

    Where has the script been gone, not available anymore?

  • By s1axter, September 18, 2015 @ 10:46 am

    The script was somehow removed from my server. Maybe on an update. It is back up now

Other Links to this Post

  1. Tesla Roadster Hacking | myBitBox — November 3, 2010 @ 5:47 pm

  2. Tesla Roadster Logs and Python | myBitBox — November 4, 2010 @ 2:20 pm

  3. Tesla Roadster Data Logging Format Reverse Engineered | JetLib News — November 4, 2010 @ 4:14 pm

  4. Android OS news » Tesla Roadster Data Logging Format Reverse Engineered — November 4, 2010 @ 7:23 pm

  5. RE de voiture Tesla — November 5, 2010 @ 7:17 am

  6. How a Savvy Coder Hacked His Tesla I Feel Gassy | The Nerd Insurance — November 9, 2010 @ 12:26 pm

WordPress Themes