Broken Pipe Py-OBD

Subject of the issue

I am trying to retrieve OBD variables through python script running on a Autopi Dongle. I imported and installed the py-obd library, but unfortunately a broken pipe message is showing.
I’ve found on the community that someone else had the same problem but they couldn’t found a solution so i’m trying to propose again the question.

Steps to reproduce

I’m trying to use the following code in order to obtain data from the OBD port:

#!/usr/bin/python

import obd

connection = obd.OBD() # auto-connects to USB or RF port

cmd = obd.commands.SPEED # select an OBD command (sensor)

response = connection.query(cmd) # send the command, and parse the response

print(response.value) # returns unit-bearing values thanks to Pint
print(response.value.to(“mph”)) # user-friendly unit conversions

Expected behaviour

Print on the terminal the SPEED value in mph

Actual behaviour

Traceback (most recent call last):
File “test.py”, line 5, in
connection = obd.OBD() # auto-connects to USB or RF port
File “/usr/local/lib/python2.7/dist-packages/obd/obd.py”, line 62, in init
self.__connect(interface_cls, portstr, baudrate, timeout=timeout, protocol=protocol, status_callback=status_callback)
File “/usr/local/lib/python2.7/dist-packages/obd/obd.py”, line 82, in __connect
portnames = scan_serial()
File “/usr/local/lib/python2.7/dist-packages/obd/utils.py”, line 191, in scan_serial
if try_port(port):
File “/usr/local/lib/python2.7/dist-packages/obd/utils.py”, line 155, in try_port
s = serial.Serial(portStr)
File “/usr/local/lib/python2.7/dist-packages/serial/serialutil.py”, line 240, in init
self.open()
File “/usr/local/lib/python2.7/dist-packages/serial/serialposix.py”, line 286, in open
self._update_dtr_state()
File “/usr/local/lib/python2.7/dist-packages/serial/serialposix.py”, line 634, in _update_dtr_state
fcntl.ioctl(self.fd, TIOCMBIS, TIOCM_DTR_str)
IOError: [Errno 32] Broken pipe

I’ve solved the problem.
In the following I write the solution in order to help anyone who could have these problem:

You need to add the SP profile editing this:

sudo nano /etc/systemd/system/dbus-org.bluez.service

Then add the compatibility flag -C for adding the SP to sdptool. Modify the lines from the file above to:

ExecStart=/usr/lib/bluetooth/bluetoothd -C
ExecStartPost=/usr/bin/sdptool add SP

Save and reboot, then I created the serial port this way (little bit different from the link I posted):

sudo rfcomm bind rfcomm1 AA:BB:CC:DD:EE:FF

Then, on python:

connection = obd.OBD('/dev/rfcomm1')

Try also different rfcomm (rfcomm0, rfcomm1, rfcomm2…) and be sure to release all before binding:

sudo rfcomm release all

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.