Please note: Working with the CAN bus is on your own risk. Playback and sending commands to the vehicle can be used to control functions in the vehicle affecting the behavior of the vehicle. We recommend that you NEVER do testing on a vehicle in motion and that you have the parking brake enabled while you test
Using the CAN bus commands
With the latest release is a couple of new commands available, which opens up for direct communication with the CAN bus.
This guide will focus on helping you with the local CAN bus commands.
The first command I want to highlight is actually not new, but it is used to send standard PID’s to the vehicle:
obd.query test mode=01 pid=0C
You may need to add the
force=True parameter to make sure the ECU in the vehicle accepts the command. You can see a full list of PID’s here:
Your vehicle may be able to support more or less PID’s than shown on Wikipedia.
The CAN interface
The CAN interface is somewhat different than just sending standard PID’s. It relies more on parcing the full data stream on the bus. This is far more advanced, but it also opens up to a whole new level of fun.
Setting the protocol
The AutoPi is able to support a wide range of protocols. Actually, its one of the most versatile devices on the market, with support for the most protocol. When you insert it into your vehicle it will try to autodetect the protocol to be used. This is not necessarily the same protocol used for all CAN traffic. In fact, CAN traffic may flow on more than one protocol in your vehicle. And switching the protocol sometimes makes the AutoPi listen on traffic on different electrical pins. You can check the current protocol settings using this command:
This will give you a list of all the protocols you can set. Changing the protocol can be done with this command:
<num> is the protocol number.
Dumping/reading data from the CAN bus
The new interface opens up for dumping data from the CAN bus on the protocol selected. This can be done using this command:
duration=<seconds>: How many seconds to record data. Default is
file=<path>: Write data to a file.
This command can dump data to the screen by default, but adding the
file=<path> command dumps everything to a specific file. The default duration is 2 seconds, but this can be controlled with the
Playback of a recorded file
A file recorded with the
obd.dump command can be played/replayed to the vehicle using this command:
The will playback the entire file on the CAN bus.
slice=<T|B>: Slice the list of messages before sending on the CAN bus. Based one the divide and conquer algorithm. Multiple slice characters can be specified in continuation of each other.
T: Top half of remaining result.
B: Bottom half of remaining result.
filter=<expression>: Filter out messages before sending on the CAN bus. Multiple filters can be specified if separated using comma characters.
+[id][#][data]: Include only messages matching string.
-[id][#][data]: Exclude messages matching string.
+duplicate: Include only messages where duplicates exist.
-duplicate: Exclude messages where duplicates exist.
+mutate: Include only messages where data mutates.
-mutate: Exclude messages where data mutates.
group=<id|msg>: How to group the result of sent messages. This only affects the display values returned from this command. Default is
test=<true|false>: Run command in test-only (dry-run) mode. No data will be sent on CAN bus. Default is
All the filter parameters can be used to find the specific commands that you are seeking. With filters you can remove data that you know is not relevant for finding your specific command (like data that appears a lot). With the slice parameter you can use the “divide and conquer” technique to find the specific command.
Sending a single message
obd.dump and the
obd.play commands is typically used for finding a single specific command you want to send to the car. This can be lock/unlock or something else controlling your vehicle.
When you have the specific command, you can send it directly using this command:
obd.send 2101#280000000003E800 expect_response=True auto_format=True
The first part before the # is the ECU number and the last part is the data payload. You may need to remove the
expect_response if the ECU doesn’t respond on the message you’ve send.
Using the Cloud CAN Analyzer
All the above commands are how the interface to the vehicle works. We have combined all of this in an interactive CAN Analyzer, which is accessible from the AutoPi Cloud:
The CAN Analyzer makes working with your car much simpler. To find your specific command follow these steps:
Configure your CAN Bus interface. On the settings page under "vehicle" you can autodetect the most common CAN Bus. If you need to work with a special CAN bus, make sure you have the right baud rate configured.
Select the Bus you want to use and press record. The device will make a "beep" sound when the recording begins and another one when the recording ends. Make sure that the CAN command you want to record is happening between the two sounds (like door unlock or window control)
The recording is now stored on the device and you can play it back immediately using the CAN player on the right-hand side of the screen.
You will see that a lot of data is returned from the bus, so to find the specific command for your function, we recommend using the filters on the right-hand side. Typically, a lot of the data is repetitions, so you can start out by removing all the duplicates.
With the filters, narrow down the results to as few as possible. Then you can reply the commands one by one and see if you can find the command controlling the function you are looking for.
When you have found your command you can always resend it by using the
obd.sendcommand described above.