Reputation: 322
I would like to log datas via OBD2 with ELM327, and I am new in Python.
I can send a command and get a response. But I cannot send more queries and get the responses, only for the first command, the rest of responses are "None".
My code:
import obd, time
connection = obd.OBD(baudrate=38400, fast=True) # auto-connects to USB or RF port
while True:
for i in commands_list:
cmd1 = obd.commands.RPM # select an OBD command (sensor)
response1 = connection.query(cmd1) # send the command, and parse the response
print(response1.value) # returns unit-bearing values thanks to Pint
# connection.close()
cmd2 = obd.commands.COOLANT_TEMP # select an OBD command (sensor)
response2 = connection.query(cmd2) # send the command, and parse the response
print(response2.value)
# connection.close()
time.sleep(0.5)
The output is: (with stopped engine, on ignition)
0.0 revolutions_per_minute
None
0.0 revolutions_per_minute
None
0.0 revolutions_per_minute
None
The expected output:
0.0 revolutions_per_minute
91 degC
0.0 revolutions_per_minute
91 degC
0.0 revolutions_per_minute
91 degC
It is work with closing connection after getting each responses, but it is really slow... I woule like to get responses after max. 1 sec. The optimal would be at least 0.5 s.
Has anyone idea or experience with this? Thanks in advance.
Upvotes: 0
Views: 4810
Reputation: 322
The solution was to set fast mode to false:
connection = obd.OBD(baudrate=38400, fast=False)
Function description:
fast: Allows commands to be optimized before being sent to the car. Python-OBD currently makes two such optimizations:
Sends carriage returns to repeat the previous command. Appends a response limit to the end of the command, telling the adapter to return after it receives N responses (rather than waiting and eventually timing out). This feature can be enabled and disabled for individual commands. Disabling fast mode will guarantee that python-OBD outputs the unaltered command for every request.
Source: LINK
Upvotes: 1