Giter Club home page Giter Club logo

python-obd's Introduction

python-OBD

A python module for handling realtime sensor data from OBD-II vehicle ports. Works with ELM327 OBD-II adapters, and is fit for the Raspberry Pi.

Installation

$ pip install obd

Basic Usage

import obd

connection = obd.OBD() # auto-connects to USB or RF port

cmd = obd.commands.SPEED # select an OBD command (sensor)

response = connection.query(cmd) # send the command, and parse the response

print(response.value) # returns unit-bearing values thanks to Pint
print(response.value.to("mph")) # user-friendly unit conversions

Documentation

Available at python-obd.readthedocs.org

Commands

Here are a handful of the supported commands (sensors). For a full list, see the docs

note: support for these commands will vary from car to car

  • Calculated Engine Load
  • Engine Coolant Temperature
  • Fuel Pressure
  • Intake Manifold Pressure
  • Engine RPM
  • Vehicle Speed
  • Timing Advance
  • Intake Air Temp
  • Air Flow Rate (MAF)
  • Throttle Position
  • Engine Run Time
  • Fuel Level Input
  • Number of warm-ups since codes cleared
  • Barometric Pressure
  • Ambient air temperature
  • Commanded throttle actuator
  • Time run with MIL on
  • Time since trouble codes cleared
  • Hybrid battery pack remaining life
  • Engine fuel rate
  • Vehicle Identification Number (VIN)

Common Issues

Bluetooth OBD-II Adapters

There are sometimes connection issues when using a Bluetooth OBD-II adapter with some devices (the Raspberry Pi is a common problem). This can be fixed by setting the following arguments when setting up the connection:

fast=False, timeout=30

License

GNU GPL v2

This library is forked from:

Enjoy and drive safe!

python-obd's People

Contributors

adamnovak avatar ajman1101 avatar alistair23 avatar apecone avatar cyrax6 avatar gmaniak avatar green-green-avk avatar hawtdogflvrwtr avatar interfect avatar ion-mironov avatar ircama avatar jlmcgehee21 avatar lightsoar avatar mario2407 avatar msholsve avatar nyukhalov avatar pbartek avatar peterh avatar sapkra avatar soulseekah avatar studioj avatar zaneclaes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-obd's Issues

basic usage code need to run twice to get it work

Hello Brendan

I just want to test the basic usage code for my car.
code is here

import obd

connection = obd.OBD("/dev/rfcomm0")
cmd = obd.commands.RPM # select an OBD command (sensor)

response = connection.query(cmd) # send the command, and parse the response

print(response.value)
print(response.unit)
obd.debug.console = True

every time I run this code, I need to run it twice
The first time run, I got

[obd] '010E: RPM is not supported '

after that I close the program and run again
It work prefect,I could read rpm in the python shell
Any idea on how to fix that ?
Thanks

0.4.0 with async causes traction control and flat tire warning to trigger randomly

This didn't happen in 0.2.0, but with 0.3.0+, it triggers a few vehicle warning randomly. After looking at the changes, I think it's the async sleep being changed from 1.0 to 0.25. I believe it's attempting to push multiple commands at once and tripping over each and actually sending false signals to the vehicle that it interprets as an issue.

Decoding bad Air/Fuel status data

currently, the decoders for air_status and fuel_status use math.log(v,2) to determine which bit is set. This explodes when 'v' is zero, and will give false positive decodings when more than one bit is set. This should be more robust, and return failure upon receiving bad data.

Convert Units

I'm currently getting responses as follows:

obd_response = self.obd_connection.query(obd.commands.INTAKE_PRESSURE)

if not obd_response.is_null():
    return str(obd_response.value) + " " + str(obd_response.unit)
else:
    return "Empty OBD response"

The result is being output in kPa, but I'm wanting to convert it to PSI.

Looking at the docs, the Units section outlines the string enum, but I'm wondering if there's an existing function to do this conversion?

Set support for Mode 02 commands

Well, this is embarrassing... When mode 01 commands are marked as supported, we also need to mark their mode 02 counterparts. Currently, all mode 02 commands are left as unsupported by the vehicle.

feature request: non-OBD backends

Hi mate, nice library - have used it to prototype up a basic car dashboard.

I'm working on a project that will require me talking to different non-OBD but OBD like backends; ECU's like MegaSquirt, Mitsubishi MUT, etc. I'd like a standardised interface to talk to all of them so I ask the question; do you consider it within the scope of this project to support non-OBD2 protocols or not?

Not asking for you to implement this, moreso will you accept pull requests for such things? :)

obdsim no longer works (ELM responded with unknown protocol)

A change between version 0.3.0 and the current commit (5ba24a3) broke the ability to use obdsim as an OBD simulator.

Here's a log with version 0.3.0:

Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import obd
>>> obd.debug.console = True
>>> connection = obd.OBD("/dev/pts/7")
[obd] ========================== Starting python-OBD ==========================
[obd] Explicit port defined
[obd] Opening serial port '/dev/pts/7'
[obd] Serial port successfully opened on /dev/pts/7
[obd] write: 'atz\r\n'
[obd] read: 'atz\r\n\r\nELM327 v1.3a OBDGPSLogger\r\n'
[obd] write: 'ate0\r\n'
[obd] read: 'ate0\r\n\r\nOK\r\n'
[obd] write: 'ath1\r\n'
[obd] read: '\r\nOK\r\n'
[obd] Connection successful
[obd] querying for supported PIDs (commands)...
[obd] Sending command: 0100: Supported PIDs [01-20]
[obd] write: '0100\r\n'
[obd] read: '\r\n7E8 06 41 00 FF FF FF FF FC\r\n'
[obd] Receieved less data than expected, trying to parse anyways...
[obd] finished querying with 24 commands supported
[obd] =========================================================================

Output from obdsim in this case:

SimPort name: /dev/pts/7                                   
Successfully initialised obdsim, entering main loop        
10.000261 seconds. 0 samples, 0 queries. 0.00 s/s, 0.00 q/s
Reset                                                      
Echo disabled                                              
Headers enabled                                            
10.001805 seconds. 1 samples, 4 queries. 0.10 s/s, 0.40 q/s

and here's the output with the latest commit (5ba24a3):

Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import obd
>>> obd.debug.console = True
>>> connection = obd.OBD("/dev/pts/7")
[obd] ========================== Starting python-OBD ==========================
[obd] Explicit port defined
[obd] Opening serial port '/dev/pts/7'
[obd] Serial port successfully opened on /dev/pts/4
[obd] write: 'ATZ\r\n'
[obd] read: 'ATZ\r\n\r\nELM327 v1.3a OBDGPSLogger\r\n'
[obd] write: 'ATE0\r\n'
[obd] read: 'ATE0\r\n\r\nOK\r\n'
[obd] write: 'ATH1\r\n'
[obd] read: '\r\nOK\r\n'
[obd] write: 'ATSP0\r\n'
[obd] read: '\r\nOK\r\n'
[obd] write: '0100\r\n'
[obd] read: '\r\n41 00 FF FF FF FF FC\r\n'
[obd] write: 'ATDPN\r\n'
[obd] read: '\r\n0\r\n'
[obd] Connection Error:
[obd]     ELM responded with unknown protocol
[obd] Failed to connect
[obd] =========================================================================

obdsim:

SimPort name: /dev/pts/7                                         
Successfully initialised obdsim, entering main loop   
10.000231 seconds. 0 samples, 0 queries. 0.00 s/s, 0.00 q/s           
Reset                                                            
Echo disabled                                                    
Headers enabled                                                  
New Protocol: Automatic                                          
10.000597 seconds. 1 samples, 5 queries. 0.10 s/s, 0.50 q/s      
10.000915 seconds. 0 samples, 1 queries. 0.00 s/s, 0.10 q/s 

In both cases obdsim was run just as obdsim. The version I'm using is 0.16.

I read the man pages for obdsim, and found that it can be told to emulate a specific ELM protocol (using -p 4 for 'ISO 14230-4 (KWP 5BAUD)' for example), and these protocol versions appear to match with those defined in elm327.py. However, this seems to have no effect (I think this may be being changed while obdsim is executing, as pointed out by 'New Protocol: Automatic' in its output).

Let me know if I can provide any more information to help with troubleshooting!

Does v0.6.0 not work in python 2.7.11?

C:\Python27\python.exe "D:/Documents/Python Projects/Tkinter/version2.py"
Traceback (most recent call last):
File "D:/Documents/Python Projects/Tkinter/version2.py", line 4, in
import obd
File "C:\Python27\lib\site-packages\obd__init__.py", line 40, in
from .obd import OBD
File "C:\Python27\lib\site-packages\obd\obd.py", line 37, in
from .commands import commands
File "C:\Python27\lib\site-packages\obd\commands.py", line 34, in
from .decoders import *
File "C:\Python27\lib\site-packages\obd\decoders.py", line 255
SyntaxError: Non-ASCII character '\xe2' in file C:\Python27\lib\site-packages\obd\decoders.py on line 255, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Process finished with exit code 1

It works fine in python 3.4.4 but I have a previous tkinter project and don't want to convert it to python 3

Unable to Connect via Bluetooth - No Valid Ports Found

I'm having trouble accessing my ELM327 Bluetooth Adapter from python-OBD on Yosemite. I'm able to connect to it fine from third party programs like OBD Auto Doctor, but when using Scantool to find the correct port it returns an empty array. I've also tried manually passing in some ports I found by running ls /dev/tty.* with no luck. I've been trying various suggestions I found through Google, as well typical troubleshooting steps like restarting and reinstalling for the past couple of days, but I'm out of ideas as to what I could be doing wrong.

ELM responded with unknown protocol with version 0.4.0

Hello everybody,

I am trying to use python-obd to get data from the ELM327 but I have the following issue:

import obd
ports = obd.scanSerial()
print ports
['/dev/rfcomm0']
connection = obd.OBD(ports[0])
[obd] Connection Error:
[obd]     ELM responded with unknown protocol

Could you please help me fixing this issue ?
Let me know if you need information and/or performing tests.

Thank you,

Bertrand

Autodetect baudrate

Currently calling:
connection = obd.OBD()
Errors on my device, with some kind of decoding error. Setting the baudrate allows a connection. However I believe it should be possible to autodetect the baudrate, by cycling through the possible baudrates.

I hope to implement this and create a pull request in the near future.

Unable to connect OBD to mac

I am trying to connect my mac to ODB which is connected to "Maruti Swift VDI".

import obd
obd.debug.console = True
import obd
connection = obd.OBD("/dev/tty.OBDII-SPP")
cmd = obd.commands.RPM
response = connection.query(cmd)
print(response.value)
print(response.unit)
[obd] ========================== python-OBD (v0.4.0) ==========================
[obd] Explicit port defined
[obd] Opening serial port '/dev/tty.OBDII-SPP'
[obd] Serial port successfully opened on /dev/tty.OBDII-SPP
[obd] write: 'ATZ\r\n'
[obd] wait: 1 seconds
[obd] __read() found nothing
[obd] __read() found nothing
[obd] __read() never recieved prompt character
[obd] read: ''
[obd] write: 'ATE0\r\n'
[obd] __read() found nothing
[obd] __read() found nothing
[obd] __read() never recieved prompt character
[obd] read: ''
[obd] Connection Error:
[obd]     ATE0 did not return 'OK'
[obd] Failed to connect
[obd] =========================================================================
[obd] '010C: Engine RPM' is not supported
None
None

But i was able to successfully connect it via Torque mobile app. The protocol that Torque app used was "iso14230-4 KWP fast". Can you please let me know if this is supported?

Cannot connect to OBD dongle on devel branch

I try to read the battery voltage (AT RV) from an ELM327 USB OBD dongle using python-OBD on Ubuntu 14.04. As far as I understand it, reading the battery voltage is currently only supported on the devel branch. However, when I try to connect to the dongle using

import obd
obd.debug.console = True
connection = obd.OBD("/dev/ttyUSB0")

I get the following result

[obd] ========================== python-OBD (v0.4.1) ==========================
[obd] Explicit port defined
[obd] Opening serial port '/dev/ttyUSB0'
[obd] Serial port successfully opened on /dev/ttyUSB0
[obd] write: 'ATZ\r\n'
[obd] wait: 1 seconds
[obd] read: '\r\rELM327 v1.5\r\r'
[obd] write: 'ATE0\r\n'
[obd] read: 'ATE0\rOK\r\r'
[obd] write: 'ATH1\r\n'
[obd] read: 'OK\r\r'
[obd] write: 'ATL0\r\n'
[obd] read: 'OK\r\r'
[obd] write: 'ATSP0\r\n'
[obd] read: 'OK\r\r'
[obd] write: '0100\r\n'
[obd] read: 'SEARCHING...\r7E8 06 41 00 98 3B A0 13 \r\r'
[obd] write: 'ATDPN\r\n'
[obd] read: 'A6\r\r'
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-12e6daef3864> in <module>()
      3 
      4 # --- USB ---
----> 5 connection = obd.OBD("/dev/ttyUSB0")
      6 
      7 

/home/eric/anaconda/lib/python2.7/site-packages/obd/obd.pyc in __init__(self, portstr, baudrate, protocol, fast)
     54 
     55         debug("========================== python-OBD (v%s) ==========================" % __version__)
---> 56         self.__connect(portstr, baudrate, protocol) # initialize by connecting and loading sensors
     57         self.__load_commands()            # try to load the car's supported commands
     58         debug("=========================================================================")

/home/eric/anaconda/lib/python2.7/site-packages/obd/obd.pyc in __connect(self, portstr, baudrate, protocol)
     81         else:
     82             debug("Explicit port defined")
---> 83             self.port = ELM327(portstr, baudrate, protocol)
     84 
     85         # if the connection failed, close it

/home/eric/anaconda/lib/python2.7/site-packages/obd/elm327.pyc in __init__(self, portname, baudrate, protocol)
    142 
    143         # try to communicate with the car, and load the correct protocol parser
--> 144         if self.load_protocol():
    145             self.__status = OBDStatus.CAR_CONNECTED
    146             debug("Connection successful")

/home/eric/anaconda/lib/python2.7/site-packages/obd/elm327.pyc in load_protocol(self)
    180         if p in self._SUPPORTED_PROTOCOLS:
    181             # jackpot, instantiate the corresponding protocol handler
--> 182             self.__protocol = self._SUPPORTED_PROTOCOLS[p](r0100)
    183             return True
    184         else:

/home/eric/anaconda/lib/python2.7/site-packages/obd/protocols/protocol_can.pyc in __init__(self, lines_0100)
    280     ELM_ID = "6"
    281     def __init__(self, lines_0100):
--> 282         CANProtocol.__init__(self, lines_0100, id_bits=11)
    283 
    284 

/home/eric/anaconda/lib/python2.7/site-packages/obd/protocols/protocol_can.pyc in __init__(self, lines_0100, id_bits)
     48         # Protocol __init__ uses the parsing system.
     49         self.id_bits = id_bits
---> 50         Protocol.__init__(self, lines_0100)
     51 
     52 

/home/eric/anaconda/lib/python2.7/site-packages/obd/protocols/protocol.pyc in __init__(self, lines_0100)
    137         # parse the 0100 data into messages
    138         # NOTE: at this point, their "ecu" property will be UNKNOWN
--> 139         messages = self(lines_0100)
    140 
    141         # read the messages and assemble the map

/home/eric/anaconda/lib/python2.7/site-packages/obd/protocols/protocol.pyc in __call__(self, lines)
    178             # subclass function to parse the lines into Frames
    179             # drop frames that couldn't be parsed
--> 180             if self.parse_frame(frame):
    181                 frames.append(frame)
    182 

/home/eric/anaconda/lib/python2.7/site-packages/obd/protocols/protocol_can.pyc in parse_frame(self, frame)
     86             # 00 00 07 E8 06 41 00 BE 7F B8 13
     87 
---> 88             frame.priority = raw_bytes[2] & 0x0F  # always 7
     89             frame.addr_mode = raw_bytes[3] & 0xF0  # 0xD0 = functional, 0xE0 = physical
     90 

TypeError: unsupported operand type(s) for &: 'str' and 'int'

Any ideas what going on here? I tried it with a Bluetooth dongle as well - the problem is there too.

Error - "Failed to choose primary ECU"

After utilizing 'bluetoothctl' to pair and 'rfcomm bind 0' to bind my bluetooth OBD adapter to '/dev/rfcomm0', I get the following error when attempting to initialize an OBD connection:

Connection Error
Failed to choose primary ECU

I've followed the steps outlined in the documentation with no luck. I'm running Raspbian Jessie Lite, which seems to utilize a different pairing process than typical, but I don't believe that's causing the issue.

Here's the error output from the debug log:

[obd] write: '0100\r\n'
[obd] __read() found nothing
[obd] read: 'SEARCHING...\rUNABLE TO CONNECT\r\r'
[obd] write: 'ATDPN\r\n'
[obd] read: 'A8\r\r'
[obd] Connection Error:
[obd]      Failed to choose primary ECU
[obd] Failed to connect

Async TypeError: Odd-length string

When I use async i get the following thread exception when I turn off my car after running a track session (20+ mins)
during my development period, when I drive around the block i don't get this exception when i turn off my car.

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/local/lib/python2.7/dist-packages/obd/async.py", line 214, in run
    r = super(Async, self).query(c, force=True)
  File "/usr/local/lib/python2.7/dist-packages/obd/obd.py", line 240, in query
    messages = self.port.send_and_parse(cmd_string)
  File "/usr/local/lib/python2.7/dist-packages/obd/elm327.py", line 312, in send_and_parse
    messages = self.__protocol(lines)
  File "/usr/local/lib/python2.7/dist-packages/obd/protocols/protocol.py", line 184, in __call__
    if self.parse_frame(frame):
  File "/usr/local/lib/python2.7/dist-packages/obd/protocols/protocol_legacy.py", line 50, in parse_frame
    raw_bytes = bytearray(unhexlify(raw))
TypeError: Odd-length string

Changing ELM Protocol Detect Command

Hello,

I used this library to develop ECU Data Logger.

I am using ELM327 v2.1 Bluetooth Module and my car is Honda CR-V 2008.

First I am try to connect ECU with this library, It is failed likes this issue(#22).

To find reason to fail connect, I turned on debug console in python-OBD.

img

The error occurred at 'ATSPA8' command.
After this command, '0100' failed cause of 'ATSPA8' command.
The failed message at 'ATSPA8' means, Protocol handshake failed.
I searched about 'ATSPA8', but I can't find document about this command.
So I changed this command to 'ATSP0'.
'ATSP0' means automatic Protocol handshake. It works with my ECU.
If 'ATSP0' works in other ECU, It is better to change 'ATSPA8' to 'ATSP0' in [https://github.com/brendanwhitfield/python-OBD/blob/master/obd/elm327.py].

img

Using bluetooth on MAC

Question: How can I use python-OBD on Mac OS?

In the wiki it says:
sudo apt-get install bluetooth bluez-utils blueman

What are the MAC equivalent?

Multiple ECU support

This library filters incoming messages for those sent by the engine ECU only (called the primary_ecu in code). This wasn't a problem until DTC support was added, and DTCs from other ECUs were dropped.

To fix:
The send_and_parse() function should return a list of tagged Message objects (rather than just one). Message.tx_id should probably be changed to a more abstract, enum style property (marking things as engine, transmission, unknown, etc). Commands and decoders should be tooled to accept lists of messages as inputs, where parsing decisions can be made in the individual decoders. Commands could also have special flags, indicating which ECU they are designed to handle.

Once this is added, it might be nice to provide an API for listing the ECUs in the car.

Decode DTCs

I'd like to cleanup the old pyobd DTC decoders, and see if the bit-shifting madness can be quelled. There are untested decoders for DTCs in decoders.py. These need to be tested on a car that throws a code (something I don't have at the moment (oh darn...)). For reference, the old pyobd decoder is still in port.py (commented out).

Request PID of commands ELM_VOLTAGE and ELM_VERSION result in ValueError

The following code raises an ValueError:

>>> from obd import commands
>>> commands.ELM_VERSION.pid
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/auke/projects/Ted/.env/lib/python3.5/site-packages/obd/OBDCommand.py", line 78, in pid
    return int(self.command[2:], 16)
ValueError: invalid literal for int() with base 16: b'I'

The PIDs of the commands ELM_VERSION and ELM_VOLTAGE are respectively ATI and ATRV. These values can't be casted to integers.

.Magnitude , typecasting of objects (pint example) , and raw data access

I have an unmodified library directly cloned from the git and followed directions to a T. Issue is, when using code examples, the .value.to("mph") will not function. Constantly says that:

Traceback (most recent call last):
  <module>
    in_RPM.value.magnitude AttributeError: 'NoneType' object has no attribute 'magnitude'

Additionally for the .magnitude referenced in the docs there is this error:

 Traceback (most recent call last):
  <module>
    in_RPM.value.to("mph") AttributeError: 'NoneType' object has no attribute 'to'

So a this moment, there is no way to get the "raw" data that is just the object's data value, and able to manipulate the object's data as it is a protected instance variable. I have traced through the code, and have been unable to find a sane answer as to why the object's data is not able to be manipulated.

Basically, issue is access to raw data as a int, float, str, etc. I am more than happy to contribute any of my commits I change in the process of fixes.

Thanks.

Can't understand why value is 'None'

Hi,

Often, some messages have 'None' value.

[obd] Sending command: 014E: Time since trouble codes cleared
[obd] write: '014E1\r\n'
[obd] read: '7E8 04 41 4E 44 D8 \r\r'
r.time: 1466358933.57
r.name: TIME_SINCE_DTC_CLEARED
r.value: None

But sometimes it works:

[obd] Sending command: 014E: Time since trouble codes cleared
[obd] write: '014E1\r\n'
[obd] read: '7E9 04 41 4E 4B 9D \r\r'
r.time: 1466358933.7
r.name: TIME_SINCE_DTC_CLEARED
r.value: 19357

I tried to reverse the code to understand, but I failed. Could you please help me if you have some time?

Regards,
jml

Better ELM error handling

currently, elm327.py only looks for the UNABLE TO CONNECT string. I'd like it to be a little smarter, and know about the other error strings, such as:

  • NO DATA <--- this one currently gets handled by filtering for hex-only values (a little ugly)
  • CAN ERROR
  • BUS ERROR
  • BUFFER FULL
  • etc, see pdf pg. 87 of the spec

Communicate using pybluez rfcomm_client

How do I send commands using a simple rfcomm client socket.
I'm using pybluez and this is my code:

from bluetooth import *
sock=BluetoothSocket( RFCOMM )
sock.connect((host, port))
sock.send(???)         #what do i need to send here?
sock.recv(???)         #best way to receive
sock.close()

is_connected() is false even though we're connected to the ELM

in previous versions, is_connected was true if we were connected to the elm device. Now it appears that is_connected only returns true if 0100 returns successfully. This allowed me to determine if we were successfully connected to the bluetooth/serial device, at which point a quick check for RPM determined if the vehicle was actually running or not.

battery voltage

The handy AT RV command will have the ELM report the current voltage it sees. Since the send_and_parse() function prohibits sending AT commands, some special tooling will need to be done to allow certain commands. The responses from this command will also need to bypass the protocol parsing system, since it returns plain text numerals, which are currently considered invalid.

Debug output is super not helpful

Lots of details, but it never tells people what the general problem is (see #38). There should be some friendlier text in there to help people diagnose where the problem is (ie, computer to adapter vs. adapter to car).

I intended to rewrite python-OBD's logging to use builtin python logging services, so I'll probably roll it into those changes.

KODI addon

Hey ....

i'm trying to fold python-OBD into a KODI addon.
But i cant make it work in a KODI plugin.
it works in when i run it outside the KODI folder:

My code:
http://paste.ubuntu.com/11941826/

Log error:
http://paste.ubuntu.com/11941812/

Any idea howto get rid of this and make python OBD work in as a KODI addon?

I'm new to python, maybe i missed something.

Thanks!

No data from python-OBD - '010C: Engine RPM' is not supported

I'm currently having problems to get any readings from python-OBD on Ubuntu 14.04 using an ELM327 Bluetooth OBD dongle. With Torque this dongle works fine. I tried the following script:

import obd
obd.debug.console = True
connection = obd.OBD("/dev/rfcomm0")
cmd = obd.commands.RPM
response = connection.query(cmd)
print(response.value)
print(response.unit)
[obd] ========================== python-OBD (v0.4.1) ==========================
[obd] Explicit port defined
[obd] Opening serial port '/dev/rfcomm0'
[obd] Serial port successfully opened on /dev/rfcomm0
[obd] write: 'ATZ\r\n'
[obd] wait: 1 seconds
[obd] read: '\r\rELM327 v2.1\r\r'
[obd] write: 'ATE0\r\n'
[obd] read: 'ATE0\rOK\r\r'
[obd] write: 'ATH1\r\n'
[obd] read: 'OK\r\r'
[obd] write: 'ATL0\r\n'
[obd] read: 'OK\r\r'
[obd] write: 'ATSP0\r\n'
[obd] read: 'OK\r\r'
[obd] write: '0100\r\n'
[obd] read: 'SEARCHING...\rUNABLE TO CONNECT\r\r'
[obd] write: 'ATDPN\r\n'
[obd] read: 'A0\r\r'
[obd] ELM responded with unknown protocol. Trying them one-by-one
[obd] write: 'ATTP6\r\n'
[obd] read: 'OK\r\r'
[obd] write: '0100\r\n'
[obd] read: 'NO DATA\r\r'
[obd] Connection successful
[obd] querying for supported PIDs (commands)...
[obd] Sending command: 0100: Supported PIDs [01-20]
[obd] write: '01000\r\n'
[obd] read: 'NO DATA\r\r'
[obd] Sending command: 0200: DTC Supported PIDs [01-20]
[obd] write: '02000\r\n'
[obd] read: 'NO DATA\r\r'
[obd] finished querying with 0 commands supported
[obd] =========================================================================
[obd] '010C: Engine RPM' is not supported
None
None

I also tried it with a USB dongle - the problem is the same. Switching to the devel branch of python-OBD also did not solve the issue. I also tried to set the baudrate explicity:

connection = obd.OBD("/dev/rfcomm0", baudrate=10400)

Still no luck. Any ideas?

Fast Refresh Command

Hello,

I found increase refresh rate of OBD command.

According to this article, If I append '1' tail of the command, can reduce response delay of query.
(http://stackoverflow.com/questions/21334147/send-multiple-obd-commands-together-and-get-response-simultaneously)

I tested this command with python-OBD custom query with Async force send, I saw querying time is reduced.

def rpm(_hex):
    v = unhex(_hex) # helper function to convert hex to int
    v = v / 4.0
    return (v, obd.Unit.RPM)

def speed(_hex):
    v = unhex(_hex)
    return (v, obd.Unit.KPH)

commFastRPM = OBDCommand("RPM", "Engine RPM", "01", "0C1", 2, rpm)
commFastSpeed = OBDCommand("SPEED", "Speed", "01", "0D1", 1, speed)

connection = obd.Async('/dev/rfcomm0')
connection.watch(commFastSpeed, force=True)
connection.watch(commFastRPM, force=True)
connection.start()

while(True):
    speeddata = connection.query(commFastSpeed).value
    rpmdata = connection.query(commFastRPM).value
    print 'Speed : ' + str(speeddata) + '\nRPM : ' + str(rpmdata) + '\n'

But It is still slow to use fast refresh application.

Here is analysis data I tested.
Async watching two command(RPM, SPEED)
First number is Timer time ( 0 second ~ unlimited )
Second number is actually updated data in that second
(62 - 7 is means 7 response received in 1 second).
In 1 second, OBD data refresh rate is 513 response/s (Before change to fast refresh command : 13 response/s).

62 - 7 =======
63 - 8 ========
64 - 6 ======
65 - 11 ===========
66 - 4 ====
67 - 7 =======
68 - 7 =======
69 - 9 =========
70 - 5 =====
71 - 5 =====
72 - 5 =====
73 - 8 ========
74 - 9 =========
75 - 9 =========
76 - 6 ======
77 - 5 =====
78 - 5 =====
79 - 5 =====
80 - 7 =======
81 - 9 =========

I want to get more fast refreshed data. Is there any way to get fast refreshed data?

Code Example from here:
https://gist.github.com/taylor224/f69b895f7fe01fe3f354

Serial port successfully opened, but then hangs

Thanks – I couldn’t wait for 0.5.0…lol. So, I did the uninstall and git clone / fetch / checkout. Python 2.7 (more libraries) on Win7 Pro:

import obd # works – says it’s v0.4.1
obd.debug.console = True # works
connection = obd.OBD('.\COM9') # says Serial port successfully opened, but then \n without giving the [obd] or python ">>>" command line prompt and hangs (for at least two minutes before I Ctrl-Break)

Any suggestions?

STN11xx support

I'm just looking into if it is possible, or worthwhile, to support the STN11xx chip. From what I can see these are all ELM327 compatible, but using the STN protocol might allow for better performance or other features.

NB: This is intended as a low priority feature request/reminder to myself :)

handle length attribute for multi-frame messages

Currently, python-OBD does not truncate multi-frame messages based on the indicated length. This isn't an urgent problem, since python-OBD doesn't formally support any multi-frame commands (other than GET_DTC requests, but those are handled differently) I'd like the get this implemented eventually.

The infrastructure is already in place (see protocol_can.py, and protocol_legacy.py). It will stitch the various frames together, and record the length marking bits, but it will not truncate the data. Some research should be done to determine exactly how this needs to be implemented.

Steering wheel angle?

Looking at the original project, there are some references to the steering wheel angle. Is this not supported in this forked version? I cannot seem to find the command that can be invoked.

Byte Buffer Decode Error When Communicating at Wrong Baud Rate

The correct baud rate for my car appears to be 115200. When I attempt to connect using the default baud rate of 38400, I get the following error:

In [1]: import obd

In [2]: connection = obd.OBD('/dev/ttyUSB1')
[obd] ========================== python-OBD (v0.4.1) ==========================
[obd] Explicit port defined
[obd] Opening serial port '/dev/ttyUSB1'
[obd] Serial port successfully opened on /dev/ttyUSB1
[obd] write: 'ATZ\r\n'
[obd] wait: 1 seconds
[obd] __read() found nothing
[obd] __read() found nothing
[obd] __read() never recieved prompt character
[obd] read: '~f\xfa\x9e'
---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-2-ac2f7c876d8a> in <module>()
----> 1 connection = obd.OBD('/dev/ttyUSB1')

/usr/local/lib/python2.7/dist-packages/obd/obd.pyc in __init__(self, portstr, baudrate)
     50
>:q01 00 07 E5 00
     51         debug("========================== python-OBD (v%s) ==========================" % __version__)
---> 52         self.__connect(portstr, baudrate) # initialize by connecting and loading sensors
     53         debug("=========================================================================")
     54

/usr/local/lib/python2.7/dist-packages/obd/obd.pyc in __connect(self, portstr, baudrate)
     74         else:
     75             debug("Explicit port defined")
---> 76             self.port = ELM327(portstr, baudrate)
     77
     78         # if a connection was made, query for commands

/usr/local/lib/python2.7/dist-packages/obd/elm327.pyc in __init__(self, portname, baudrate)
     99         # ---------------------------- ATZ (reset) ----------------------------
    100         try:
--> 101             self.__send("ATZ", delay=1) # wait 1 second for ELM to initialize
    102             # return data can be junk, so don't bother checking
    103         except serial.SerialException as e:

/usr/local/lib/python2.7/dist-packages/obd/elm327.pyc in __send(self, cmd, delay)
    299             time.sleep(delay)
    300
--> 301         return self.__read()
    302
    303

/usr/local/lib/python2.7/dist-packages/obd/elm327.pyc in __read(self)
    364
    365         # convert bytes into a standard string
--> 366         raw = buffer.decode()
    367
    368         # splits into lines

UnicodeDecodeError: 'ascii' codec can't decode byte 0xfa in position 2: ordinal not in range(128)

In [3]: exit

When I manually specify 115200, I get:

In [2]: import obd

In [3]: connection = obd.OBD('/dev/ttyUSB1', 115200)
[obd] ========================== python-OBD (v0.4.1) ==========================
[obd] Explicit port defined
[obd] Opening serial port '/dev/ttyUSB1'
[obd] Serial port successfully opened on /dev/ttyUSB1
[obd] write: 'ATZ\r\n'
[obd] wait: 1 seconds
[obd] read: 'ATZ\r\r\rELM327 v1.3a\r\r'
'ATZ\r\r\rELM327 v1.3a\r\r'
[obd] write: 'ATE0\r\n'
[obd] read: 'ATE0\rOK\r\r'
'ATE0\rOK\r\r'
[obd] write: 'ATH1\r\n'
[obd] read: 'OK\r\r'
'OK\r\r'
[obd] write: 'ATL0\r\n'
[obd] read: 'OK\r\r'
'OK\r\r'
[obd] write: 'ATSPA8\r\n'
[obd] read: 'OK\r\r'
'OK\r\r'
[obd] write: '0100\r\n'
[obd] __read() found nothing
[obd] read: 'SEARCHING...\r7E8 06 41 00 FE 3F A8 13 00 \r7E9 06 41 00 98 1A 80 13 00 \r\r'
'SEARCHING...\r7E8 06 41 00 FE 3F A8 13 00 \r7E9 06 41 00 98 1A 80 13 00 \r\r'
[obd] write: 'ATDPN\r\n'
[obd] read: 'A6\r\r'
'A6\r\r'
[obd] Connection successful
[obd] querying for supported PIDs (commands)...
[obd] Sending command: 0100: Supported PIDs [01-20]
[obd] write: '0100\r\n'
[obd] read: '7E9 06 41 00 98 1A 80 13 00 \r7E8 06 41 00 FE 3F A8 13 00 \r\r'
'7E9 06 41 00 98 1A 80 13 00 \r7E8 06 41 00 FE 3F A8 13 00 \r\r'
[obd] Sending command: 0120: Supported PIDs [21-40]
[obd] write: '0120\r\n'
[obd] read: '7E8 06 41 20 80 07 F0 11 00 \r7E9 06 41 20 80 01 80 01 00 \r\r'
'7E8 06 41 20 80 07 F0 11 00 \r7E9 06 41 20 80 01 80 01 00 \r\r'
[obd] Sending command: 0140: Supported PIDs [41-60]
[obd] write: '0140\r\n'
[obd] read: '7E9 06 41 40 C0 80 00 00 00 \r7E8 06 41 40 FE D0 8C 81 00 \r\r'
'7E9 06 41 40 C0 80 00 00 00 \r7E8 06 41 40 FE D0 8C 81 00 \r\r'
[obd] finished querying with 41 commands supported
[obd] =========================================================================

In [4]:

There is connection to car, but I cannot obtain any data

Hi,
I am having troubles using sample code. I successfully connect to car, but I cannot obtain any data.
I was testing this on on Opel and Kia, same result.

>>>r = connection.query(cmd)
[obd.obd] '010D: Vehicle Speed' is not supported
>>>connection.protocol_name()
'ISO 15765-4 (CAN 11/500)'

Regards,
Michał

Developing a simple logger

Hi!

I'd been wondering how to develop a simple data logger (RPM, KPH) based on python-OBD functions.

How could I do ? Some Idea ?

Thanks in Advance!

Request multiple PIDs during Async connections

page 45. Up to 6 PIDs can be sampled with a single command. This would be much more efficient. The multiline protocol handlers will need to be fully working, and it can only be done with the CAN (ISO 15765-4) protocol.

Not working with Python 3

With Python 3.4.2 I only get this

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    obdhandler = CObdHandler.CObdHandler()
  File "/home/pi/CarPi/CObdHandler.py", line 12, in __init__
    self._connection = obd.OBD()
  File "/usr/local/lib/python3.4/dist-packages/obd/obd.py", line 55, in __init__
    self.__connect(portstr, baudrate, protocol) # initialize by connecting and loading sensors
  File "/usr/local/lib/python3.4/dist-packages/obd/obd.py", line 78, in __connect
    if self.port.status >= OBDStatus.ELM_CONNECTED:
TypeError: unorderable types: method() >= str()

When using python 2.7.9 it works.
But the Problem is I need python3 for all the other components to work .

Any Ideas?

Trying to connect and fails with: Failed to set baudrate

Hello,

I'm trying to make a bluetooth connection with ODBII support. I'm trying to use the sample code as below:

import obd
connection = obd.OBD() # auto-connects to USB or RF port
cmd = obd.commands.SPEED # select an OBD command (sensor)
response = connection.query(cmd) # send the command, and parse the response

When I try to make a auto connection with this line:

connection = obd.OBD() # auto-connects to USB or RF port

this error happens:

[obd.elm327] Failed to set baudrate
[obd.obd] Cannot load commands: No connection to car
[obd.obd] Query failed, no connection available

I'm using a Mac OSX 10.12.

Thanks !

Manual protocol selection

add an argument to the OBD constructor to force a particular protocol. If None is passed, the ussual auto-mode is used.

Connection to Car - but can't get data back

Hi,

I am trying to use Python-OBD but having a few difficulties getting started. I am using your example code

import obd
connection = obd.OBD() # auto-connects to USB or RF port
cmd = obd.commands.RPM # select an OBD command (sensor)
response = connection.query(cmd) # send the command, and parse the response
print(response.value) # returns unit-bearing values thanks to Pint

I get the following response back with the logger enabled. I noticed towards the end of the block that the write tries this [obd.elm327] write: '01001\r\n'
Is this correct operation for the code? Or is this where my problem lies?

Any help would be appreciated as I was trying to debug this but with no avail.

Cheers

[obd.obd] ======================= python-OBD (v0.6.1) =======================
[obd.obd] Explicit port defined
[obd.elm327] Initializing ELM327: PORT=/dev/ttyUSB0 BAUD=auto PROTOCOL=auto
[obd.elm327] Response from baud 38400: ''
[obd.elm327] Response from baud 9600: '?\r\r>'
[obd.elm327] Choosing baud 9600
[obd.elm327] write: 'ATZ\r\n'
[obd.elm327] wait: 1 seconds
[obd.elm327] read: b'\r\rELM327 v1.2a\r\r>'
[obd.elm327] write: 'ATE0\r\n'
[obd.elm327] read: b'ATE0\rOK\r\r>'
[obd.elm327] write: 'ATH1\r\n'
[obd.elm327] read: b'OK\r\r>'
[obd.elm327] write: 'ATL0\r\n'
[obd.elm327] read: b'OK\r\r>'
[obd.elm327] write: 'ATSP0\r\n'
[obd.elm327] read: b'OK\r\r>'
[obd.elm327] write: '0100\r\n'
[obd.elm327] read: b'SEARCHING...\r48 6B 11 41 00 BE 3E B8 11 CA \r\r>'
[obd.elm327] write: 'ATDPN\r\n'
[obd.elm327] read: b'A3\r\r>'
[obd.protocols.protocol] map ECU 17 --> ENGINE
[obd.elm327] Connected Successfully: PORT=/dev/ttyUSB0 BAUD=9600 PROTOCOL=3
[obd.obd] querying for supported commands
[obd.obd] Sending command: 0100: Supported PIDs [01-20]
[obd.elm327] write: '01001\r\n'
[obd.elm327] read: b'?\r\r>'
[obd.OBDCommand] 0100: Supported PIDs [01-20] did not recieve any acceptable messages
[obd.obd] No valid data for PID listing command: 0100: Supported PIDs [01-20]
[obd.obd] finished querying with 7 commands supported
[obd.obd] ===================================================================
[obd.obd] '010C: Engine RPM' is not supported

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.