Using the CAN bus commands

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.

Sending PID’s

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:

obd.protocol

This will give you a list of all the protocols you can set. Changing the protocol can be done with this command:

obd.protocol set=<num>

Where <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:

obd.dump

Optional parameters:

  • duration=<seconds>: How many seconds to record data. Default is 2 seconds.
  • 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 duration=<seconds> parameter.

Playback of a recorded file

A file recorded with the obd.dump command can be played/replayed to the vehicle using this command:

obd.play file=<path>

The will playback the entire file on the CAN bus.

Optional parameters:

  • 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 id.
  • test=<true|false>: Run command in test-only (dry-run) mode. No data will be sent on CAN bus. Default is false.

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

The 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:

CAN_analyzer

The CAN Analyzer makes working with your car much simpler. To find your specific command follow these steps:

  1. 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.

  2. 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)

  3. 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.

  4. 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.

  5. 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.

  6. When you have found your command you can always resend it by using the obd.send command described above.

4 Likes

With the suggested command, I see :

peter26@Volvol V50 $ obd.query mode=01 pid=0C

>-

  Passed invalid arguments to obd.query: query() takes at least 1 argument (2

  given)

      Queries a given OBD command.

Error message doesn’t appear to make any sense.

Hi @plord

It does seem like there is an error with this function. Its been noted and will be fixed for the next release coming shortly.

best
Peter

Ah, thanks for the confirmation. I’ll re-try after the next update :slight_smile:

How can I understood what Protocol ID i need to use with my Mazda CX-5?
AutoPI are not able to automatically detect, how I can detect it?

Thanks

Hi Matteo

What is the output of

obd.protocol

in the web terminal?

If it is unable to detect the protocol, you will have to look up the protocol for your car yourself, but even if it can detect which one it is, you may still need to look up the other busses yourself, as the auto detect will only detect the first available bus - and you probably have access to more than one.

A quick google search found this: http://www.madox.net/blog/projects/mazda-can-bus/

Which suggests that it may be HS (31-36) and MS (51-54) - but this is just a quick guess.

Best regards
/Malte

1 Like

I’m still struggling how this command works. Relating your example to the wikipedia page I presume this is requesting service 01 pid 0C - ie engine RPM ?

Can you also give an example of using the obd.query (or other) command to query a non-standard PID ?

Guessing a lot, I tried :

$  obd.query test pid=2101 force=True
_type: test
_stamp: '2018-11-29T20:01:29.786962'
value: |-
  7EA03410100
  7EB054121000100
  7EC0541210B01A5
  7ED1009412100000100
  7ED2104000000000000

Is this a reasonable request ? How to decode the responses ?

Also, is there some advice how to initially explore the car - obd.dump returns nothing in my Kona Electric, but can we query a range of non-standard PID’s or at least find what non-standard PID’s are available ?

Many thanks.

Hi Malte
I did a google search but I couldn’t find anything for my Volvo V60 2015!!
What do you suggest?!
Thanks

Hi
I have a problem with CAN analyzer. The recording time is too short I meat the time between 2 beeps!! I have increased the recording time from 2 sec to 30 sec but it is still too short🤭. It’s a little bit hard to perform that action I need between 2 beeps!! Is there something which can help me??
Thanks

Hey Alex

When you say the recording time is too short, you mean that you’d like the be able to increase the recording time? - Or do you mean that the time between the beeps is shorter than the configured duration?

If the issue is that you’d like to record for more than 30 seconds, which is the current max in the UI, then you can do the following.

The Can Analyzer section on my.autopi.io uses the following commands behind the scenes.
And you can execute the same commands via the terminal on my.autopi.io, where you can set the duration to whatever you like.

obd.dump will do the actual recording and dump the file to a default directory.
http://docs.autopi.io/commands/obd/#obd-dump

obd.recordings will list the recordings in the default directory
http://docs.autopi.io/commands/obd/#obd-recordings

Best regards
/Malte

I ment time between 2 beeps are too short maybe half a second. I can not perform that command which I need to record it.

Hi Alex

Ah okay - It sounds like an error is occurring causing it to stop recording.
Do you see any errors in the UI when this happens?

Also, can you take a look in the log of the device? specifically the last_errors might be interesting.

You can send the log to support@autopi.io they should be able to tell you the cause, when looking into the log.

Best regards
/Malte

I have now tryed repeadely to use CAN Analyzer.
Recording :+1: seems to be working.
But when i try to play it, i se no action.

i hav tryed to use some of thes commands you are talking about in the therminal,
but still no respond.

Is ther a simple way to send commands?

I am trying out with a lock the car.
i an searching for a way “just” to make the light blink, like when i lock it.

1 Like

I have the same problem!!

1 Like

Hi,

What type of issue do you see?

The Cloud basically just runs the AutoPi core commands for you, so you always have the possiblity to do it manually.

To list the current recordings, use the obd.recordings command:
http://docs.autopi.io/commands/obd/#obd-recordings

To replay an entire recording, use the obd.play command:
http://docs.autopi.io/commands/obd/#obd-play

To replay a single command, use the obd.send command:
http://docs.autopi.io/commands/obd/#obd-send

best
Peter

Hi,
What was your progress in locking and unlocking your doors with AutoPi?

Still no luch getting the communication working!

1 Like

I also tried to record some commands on my 2015 BMW F10. Although I can read the RPM and SPEED and other parameters using protocol=6 and baudrate=500000, whenever I try obd.dump I get “CAN sending or receiving failed”.

Looking into the syslog I see there is an exception in elm327.py in line 610 which at first glance leads me to believe either there is an issue with the protocol and baudrate mentioned above or I am seriously missing something!

Also tried from the cloud GUI. All I get is toasters that the recording has started and immediately stopped. My guess is the issue is the same, just that the actual exception is not being propagated to the UI.

Any clues? :slight_smile:

I have exactly the same problem. With an BMW F11.