Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem connecting and querying a car with python-obd

Tags:

python

obd-ii

I'm trying to connect my linux with the car using an USB OBD-II device, it connects to the OBD-II device but not to the car. The software OBD Auto Doctor https://www.obdautodoctor.com/ connects just fine, look what the python-obd in DEBUG mode says when trying to connect and execute a query (RPM):

```
>>> connection = obd.OBD()
[obd.obd] ======================= python-OBD (v0.7.1) =======================
[obd.obd] Using scan_serial to select port
[obd.obd] Available ports: ['/dev/ttyUSB0']
[obd.obd] Attempting to use port: /dev/ttyUSB0
[obd.elm327] Initializing ELM327: PORT=/dev/ttyUSB0 BAUD=auto PROTOCOL=auto
[obd.elm327] Response from baud 38400: '?\r\r>'
[obd.elm327] Choosing baud 38400
[obd.elm327] write: 'ATZ\r'
[obd.elm327] wait: 1 seconds
[obd.elm327] read: b'\r\rELM327 v1.5\r\r>'
[obd.elm327] write: 'ATE0\r'
[obd.elm327] read: b'ATE0\rOK'
[obd.elm327] write: 'ATH1\r'
[obd.elm327] read: b'OK'
[obd.elm327] write: 'ATL0\r'
[obd.elm327] read: b'OK'
[obd.elm327] write: 'AT RV\r'
[obd.elm327] read: b'13.9V\r\r>'
[obd.elm327] write: 'ATSP0\r'
[obd.elm327] read: b'OK'
[obd.elm327] write: '0100\r'
[obd.elm327] read: b'\r\r>'
[obd.elm327] write: 'ATDPN\r'
[obd.elm327] Failed to read port
[obd.elm327] read: b''
[obd.elm327] Failed to retrieve current protocol
[obd.elm327] Adapter connected, but the ignition is off
[obd.obd] Cannot load commands: No connection to car
[obd.obd] ===================================================================
>>> connection.status()
'OBD Connected'
>>> response = connection.query(obd.commands.RPM, force=True)
[obd.obd] Sending command: 010C: Engine RPM
[obd.elm327] write: '010C\r'
[obd.elm327] read: b'010C\r41 0C 0D 4D \r\r>'
[obd.OBDCommand] 010C: Engine RPM did not receive any acceptable messages
>>>
```

Any help would be deeply appreciated. Thanks in advance

like image 326
aexposito Avatar asked Oct 15 '22 05:10

aexposito


2 Answers

Downgrade obd to v0.6.1, that worked for me

I had the same problem. I see you are using the v0.7.1

like image 103
Rodrigo Lozano Avatar answered Oct 23 '22 08:10

Rodrigo Lozano


I had the exact same problem when I tried to connect to my OBD adapter. I know this sounds dumb but is your ignition on? Because that was part of the reason why mine was having errors. I used a Raspberry Pi 4 to connect to the OBD adapter. When I turned on the ignition, I noticed that my pi would sometimes connect and sometimes wouldn't. To fix that, I made a while loop that keeps trying to initiate a connection until it started getting commands.

This was my code

while len(connection.supported_commands) < 100:
    connection = obd.Async("/dev/rfcomm99", protocol = "6", baudrate = "9600", fast = False, timeout = 30)
like image 32
Archan6el Avatar answered Oct 23 '22 08:10

Archan6el