如何通过蓝牙连接树莓派和OBD2?

问题描述 投票:0回答:1

我尝试通过蓝牙将我的 pi 0 W 连接到 OBD2 模块。我的 pi 连接到我的 4G iphone wifi,我通过 ssh 与其通信。

我使用了bluetoothctl,运行时无法连接

connect 01:23:45:67:89:BA
。 我收到以下错误消息:
Failed to connect: org.bluez.Error.NotAvailable

也运行时

connection = obd.OBD('/dev/rfcomm1')
我得到了

Traceback (most recent call last):


File "<stdin>", line 1, in <module>
  File "/home/coco/.local/lib/python3.9/site-packages/obd/obd.py", line 63, in __init__
    self.__connect(portstr, baudrate, protocol,
  File "/home/coco/.local/lib/python3.9/site-packages/obd/obd.py", line 85, in __connect
    self.interface = ELM327(port, baudrate, protocol,
  File "/home/coco/.local/lib/python3.9/site-packages/obd/elm327.py", line 146, in __init__
    if not self.set_baudrate(baudrate):
  File "/home/coco/.local/lib/python3.9/site-packages/obd/elm327.py", line 294, in set_baudrate
    return self.auto_baudrate()
  File "/home/coco/.local/lib/python3.9/site-packages/obd/elm327.py", line 324, in auto_baudrate
    response = self.__port.read(1024)
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 577, in read
    raise SerialException(
serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected or multiple access on port?)

预先感谢您的帮助,

我尝试了

sudo rfcomm bind rfcomm1 98:D3:31:FB:6F:F1
,如下所示: https://raspberrypi.stackexchange.com/questions/82173/failed-to-connect-org-bluez-error-notavailable-error/82184

PS:屏幕命令不起作用,启动命令时我的屏幕在闪烁

raspberry-pi bluetooth screen bluez obd-ii
1个回答
0
投票

确保您已将蓝牙模块加载到内核中: $modprobe蓝牙 $modprobe hci_uart $hciattach /dev/ttyS5 bcm43xx 3000000 (不确定它是否能在您的主板上工作,请查看此命令) $hciconfig hci0 up(如果不是hci0,尝试hci1)

完成后,尝试:

  1. sudo hciconfig hci0 piscan
  2. sudo sdptool add --channel=22 SP 3.sudo rfcomm 监听 /dev/rfcomm0 22

如果一切顺利,您应该会收到“正在等待频道 22 上的连接” 完成后,尝试通过串行蓝牙应用程序将其与您的 iPhone 连接。 让我知道进展如何

© www.soinside.com 2019 - 2024. All rights reserved.