brendan-w / python-OBD

OBD-II serial module for reading engine data
GNU General Public License v2.0
1.02k stars 360 forks source link

Cant Connect Unless In Debug Mode #200

Open Vindomire opened 3 years ago

Vindomire commented 3 years ago

If i enable the full debug it will connect and read as expected but when disable the debug it wont connect.

I am using:

def new_rpm(r): print(r.value)

connection = obd.Async("\.\COM5") connection.watch(obd.commands.RPM, callback=new_rpm) connection.start()

Without obd.logger.setLevel(obd.logging.DEBUG): [obd.elm327] ATH1 did not return 'OK', or echoing is still ON [obd.obd] Cannot load commands: No connection to car [obd.obd] 'b'010C': Engine RPM' is not supported

With obd.logger.setLevel(obd.logging.DEBUG): [obd.obd] ======================= python-OBD (v0.7.1) ======================= [obd.obd] Explicit port defined [obd.elm327] Initializing ELM327: PORT=.\COM5 BAUD=auto PROTOCOL=auto [obd.elm327] Response from baud 38400: b'\r\rELM327 v1.5\r\r>\r>' [obd.elm327] Choosing baud 38400 [obd.elm327] write: b'ATZ\r' [obd.elm327] wait: 1 seconds [obd.elm327] read: b'\r\rELM327 v1.5\r\r>' [obd.elm327] write: b'ATE0\r' [obd.elm327] read: b'OK\r' [obd.elm327] write: b'ATH1\r' [obd.elm327] read: b'OK\r\r>' [obd.elm327] write: b'ATL0\r' [obd.elm327] read: b'OK\r\r>' [obd.elm327] write: b'AT RV\r' [obd.elm327] read: b'13.4V\r\r>' [obd.elm327] write: b'ATSP0\r' [obd.elm327] read: b'OK\r\r>' [obd.elm327] write: b'0100\r' [obd.elm327] read: b'SEARCHING...\r7EA 06 41 00 98 3A 80 13 \r7E8 06 41 00 BE 3F A8 13 \r\r>' [obd.elm327] write: b'ATDPN\r' [obd.elm327] read: b'A6\r\r>' [obd.protocols.protocol] map ECU 0 --> ENGINE [obd.protocols.protocol] map ECU 2 --> UNKNOWN [obd.elm327] Connected Successfully: PORT=.\COM5 BAUD=38400 PROTOCOL=6 [obd.obd] querying for supported commands [obd.obd] Sending command: b'0100': Supported PIDs [01-20] [obd.elm327] write: b'0100\r' [obd.elm327] read: b'7EA 06 41 00 98 3A 80 13 \r7E8 06 41 00 BE 3F A8 13 \r\r>' [obd.obd] Sending command: b'0120': Supported PIDs [21-40] [obd.elm327] write: b'0120\r' [obd.elm327] read: b'7EA 06 41 20 80 01 A0 01 \r7E8 06 41 20 90 15 B0 15 \r\r>' [obd.obd] Sending command: b'0140': Supported PIDs [41-60] [obd.elm327] write: b'0140\r' [obd.elm327] read: b'7EA 06 41 40 44 CC 00 21 \r7E8 06 41 40 7A 1C 80 00 \r\r>' [obd.obd] Sending command: b'0600': Supported MIDs [01-20] [obd.elm327] write: b'0600\r' [obd.elm327] read: b'7E8 06 46 00 C0 00 00 01 \r\r>' [obd.obd] Sending command: b'0620': Supported MIDs [21-40] [obd.elm327] write: b'0620\r' [obd.elm327] read: b'7E8 06 46 20 80 00 80 01 \r\r>' [obd.obd] Sending command: b'0640': Supported MIDs [41-60] [obd.elm327] write: b'0640\r' [obd.elm327] read: b'7E8 06 46 40 00 00 00 01 \r\r>' [obd.obd] Sending command: b'0660': Supported MIDs [61-80] [obd.elm327] write: b'0660\r' [obd.elm327] read: b'7E8 06 46 60 00 00 00 01 \r\r>' [obd.obd] Sending command: b'0680': Supported MIDs [81-A0] [obd.elm327] write: b'0680\r' [obd.elm327] read: b'7E8 06 46 80 00 00 00 01 \r\r>' [obd.obd] Sending command: b'06A0': Supported MIDs [A1-C0] [obd.elm327] write: b'06A0\r' [obd.elm327] read: b'7E8 06 46 A0 F8 00 00 00 \r\r>' [obd.obd] finished querying with 97 commands supported [obd.obd] =================================================================== [obd.asynchronous] Watching command: b'010C': Engine RPM [obd.asynchronous] subscribing callback for command: b'010C': Engine RPM [obd.asynchronous] Starting async thread [obd.obd] Sending command: b'010C': Engine RPM [obd.elm327] write: b'010C\r' [obd.elm327] read: b'1334\r\r>'

tpchuckles commented 3 years ago

I'm seeing the same thing. below is the relevant portion of my code (edited for brevity, let me know and i can share the rest). with line 3 commented, i get an error, uncommented it connects and works fine.

Raspberry Pi Zero W with Raspbian, using python3.7, python-OBD 0.7.1, connecting to a cheapo bluetooth ELM327 reader i got off ebay (which works flawlessly with my android phone with the CarBit app).

> 
def OBD2():
    import obd,os,time
    #obd.logger.setLevel(obd.logging.DEBUG)
    os.system("sudo sdptool add SP")                # set up serial port using linux's sdptool
    time.sleep(5)                           # sdptool returns before port fully set up? so wait a jiff
    os.system("sudo rfcomm connect hci0 AA:BB:CC:11:22:33 1 &") # connect using OBD2 unit's mac address. rfcomm locks, so detach(using "&")
    time.sleep(5)                           # since we detached, we again need to wait a jiff for it to connect

    connection=obd.OBD(fast=False,timeout=30)

the error i get is:

[obd.elm327] ATH1 did not return 'OK', or echoing is still ON [obd.obd] Cannot load commands: No connection to car

ps: if anyone has tips on getting rid of the (incredibly janky) os.system calls, i'd love to hear it

EDIT: is this a duplicate of https://github.com/brendan-w/python-OBD/issues/186 ?