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

Fix send delay for bluetooth/Raspberry Pi #162

Closed zaneclaes closed 4 years ago

zaneclaes commented 4 years ago

This corrects the following issue, detected on a Raspberry Pi connecting via Bluetooth (though it may not be exclusive to this case): https://github.com/brendan-w/python-OBD/issues/160

The root cause was that the send command was attempting to retrieve responses from the OBD adapter before they were available for the startup commands (likely due to latency over Bluetooth or some slowness with the dongle itself). I verified that each of ATH1, ATL0, and AT RV would not work on my Raspberry Pi 4 with bluetooth without using at least a 0.1 second delay.

My first thought was to use the fast=False configuration value to add a delay to __send(), but on experimentation I discovered that this created an artificial delay which was unnecessary for retrieving values later (such as SPEED). Instead, I modified the __send() function to retry the read() if the response was empty for up to one second. AFAIK, this should not be problematic in that a response is always expected by any monitoring commands sent to the OBDII adapter.

... but I defer to the maintainers, as I only just started reading about the OBDII/ELM327 protocol specifics today.

// fyi @alistair23 @ajalberd

ajalberd commented 4 years ago

It works now with fast=false, and a no voltage check. Thank you!

zaneclaes commented 4 years ago

@ajalberd glad to hear it! I also packaged it up as a Docker container to run on my Raspberry Pi Kubernetes cluster, along with Prometheus exporting, if you're curious: https://github.com/zaneclaes/node-pi-obd-monitor

alistair23 commented 4 years ago

This looks fine to me. It won't interfere with already working systems but should help fix the RaspberryPi Bluetooth issue.

pasipiya commented 3 years ago

Can anyone please guide me ho to change "fast=False" I am using raspberry pi 4. But still I can't connect my bluetooth OBD adaper using python-obd connector. Thank You