Broken Pipe Py-OBD (Impossible to retrieve obd commands)

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.

Steps to reproduce

I am using this python code
#!/usr/bin/python

-- encoding: utf-8 --

import obd
import sys
import serial
import time

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

cmd = obd.commands.SPEED
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

Retrieve the obd commands from python script

Actual behaviour

It is showing this message:
File “./test.py”, line 9, in
connection = obd.OBD() # auto-connects to USB or RF port
File “/usr/local/lib/python2.7/dist-packages/obd/obd.py”, line 61, 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 81, in __connect
portnames = scan_serial()
File “/usr/local/lib/python2.7/dist-packages/obd/utils.py”, line 190, in scan_serial
if try_port(port):
File “/usr/local/lib/python2.7/dist-packages/obd/utils.py”, line 154, 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)

I have read some forums about this issue and some of them tell to set up “rtscts” and “dsrdtr” variables to true, but it is only possible through serial command, not with obd one. Could someone help me?

Hello,
I’m having the exact same problem, did you find any solution?, if so could you please let me know.
Thanks,
Alejandro

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