Get CAN data to your python script


We are trying understand if we can get all CAN data directly in a python scirpt in raspbian OS where we can write a python script directly on the raspberrypi?

We also want to understand how the signals are build? is it raw CAN messages which we really like to have and the we can have our own configuration file in our python script.

Which frequence do you update the signals? We would really like to have them in 50 Hz and the signals that we require is LateralAcceleration, LongitudinalAcceleration, YawRate annd all WheelSpeeds.

I am trying to get an understanding in all guides and it would be very helpful if you could add som links to useful guides.


Hi @dserakis,

You can definately get the CAN data directly, have you seen this guide:

All of the AutoPi Core is written in python, and you can hook into it in any way you want. Its open source.

The module in charge of getting the CAN messages (raw) can be found here:

Look for the dump_handler, which handles reading data from the bus.

You can write your own python code directly on the device, or you can even add it as a Cloud module and upload it to the device from the Cloud.


1 Like

Thank you.
We are only interested to listen on the CAN bus and not send request but thank you for the warning.

Hi @dserakis

You can use the read handler to listen on the CAN bus. This is part of our standard implementation.


Is it only OBD can that you listen to? Not main can which have the signals that we need like lateracceleration?

I don’t know if this was a missunderstanding. What We whant is to listen to your the CAN interface someway and in someway listen to your python code like a subscription or something like that and do our own standalone python code. But I can’t find any source code in our autopi so I guess that you have a compiled library or something? salt-minion? Should we build in our our python code with yours? or what can you recommend?

Hi @dserakis,

You can listen on any protocol available through the OBD connector. You just have to switch the protocol to the right one in the software. You can do that using this command:

obd.protocol set=xx

If know what you want to listen for, you can use this command:

obd.send 2101#280000000003E800 expect_response=True auto_format=True

The expect_response will make the software wait for a response on the bus (it wont wait forever, since this is something made on low level in the hardware).

If you dont know what to listen for, you can just dump all the data using this:


It will stream out all the CAN data flowing the the protocol you selected. You will have to make some python code that picks up the stream and filters it (its a lot of data) in relation to what data you are seeking. Unfortunately you cannot subscribe directly to patterns/codes in this stream. This can of course be added, if there is a huge demand for it.


can I do this from ssh? cause my obd request on the terminal dows not recognized obd example obd.protocol.
Do I need to run he commands from a certain place?

And where is the source code on the autopi?

found it, running now with “autopi” infront of the command
is the source code in /var/cache/salt/minion/files/ ?

Hi @dserakis,

Yes all Cloud terminal commands can be run from the SSH prompt using the autopi function infront of the command, as you have discovered. This helps a lot when you do local debugging/development.

And yes the AutoPi Core files are distributed into that folder, when fetched from GitHub:



1 Like