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.