Page 1 of 1

ELM327 Device Disconnecting Upon Turning Off Engine

Posted: Sat Apr 04, 2026 5:49 am
by wayland
Hi there,

I made a digital speedometer for my car using Hudiy's API, which requests the current speed and other parameters from the ELM327 device (over serial). My issue is that whenever I turn off my car (say I am stopping to get gas), the ELM327 device disconnects from Hudiy and, upon starting back up my car, does not automatically reconnect until I reboot the entire system. My question is, is it possible to have Hudiy automatically reconnect the ELM327 device upon turning off and on my car? Is this what the maxInvalidResponseCount is used for in the main_configuration.json? If so, would I just increase this value to some arbitrarily long number to avoid the device disconnection?

I appreciate the help :)

Re: ELM327 Device Disconnecting Upon Turning Off Engine

Posted: Sat Apr 04, 2026 10:17 am
by hudiy
Hello,
Hudiy does 'lazy' connect/reconnect and will automatically reconnect with every QueryObdDeviceRequest. The problem might be somewhere in your script logic - maybe you stop sending requests once the ELM327 has disconnected?

Re: ELM327 Device Disconnecting Upon Turning Off Engine

Posted: Sat Apr 04, 2026 3:03 pm
by wayland
Thanks for the quick response. It is quite possible that my script logic is off, seeing as I pretty much copy-pasted the example speedometer script contained in the Hudiy GitHub repository without fully understanding how the OBD requests work. I have attached a portion of the script here in case you might have an idea of what could be the issue with the logic (line 315 and beyond is where I start interfacing with the Hudiy API): https://pastebin.com/npuk9Yez.

Re: ELM327 Device Disconnecting Upon Turning Off Engine

Posted: Sat Apr 04, 2026 4:22 pm
by hudiy
It looks like the code makes sending the QueryObdDeviceRequest conditional on the QueryObdDeviceResponse.result. If a communication error occurs with the ELM327 (e.g., a disconnection), QueryObdDeviceResponse.result will be false. As a result, your script will stop sending further QueryObdDeviceRequests, which prevents Hudiy from being triggered to reconnect.

You should use QueryObdDeviceResponse.result only as a condition for parsing the data (QueryObdDeviceResponse.data). Another QueryObdDeviceRequest can be sent regardless of the QueryObdDeviceResponse.result value. For example:

Code: Select all

if (msg.requestCode === 0) {
    // get speed
    if(msg.result) {
        const bytes = msg.data[0]
            ?.match(/.{1,2}/g)
            ?.map((h) => parseInt(h, 16));
        targetSpeed = bytes ? bytes[2] / 1.609 : 0; // note that the output is divided by 1.609 to convert from kmh to mph
        startAnimation();
    }
    setTimeout(() => sendQueryObdRequest(["010D"], 0), 150);
}

Re: ELM327 Device Disconnecting Upon Turning Off Engine

Posted: Sat Apr 04, 2026 4:43 pm
by wayland
Thank you so much! That makes total sense as to why it was not automatically reconnecting. I'll definitely reach back out if I have any other issues.