在Ubuntu上无法与蓝牙OBDII设备配对

5
我正在尝试从运行Ubuntu Linux的Beaglebone Black与汽车OBDII蓝牙设备配对,但并不成功。最初,我能够使用bluez-simple-agent设置hci0,尽管它从未要求我输入PIN码。该设备的PIN码应为“1234”。现在,当我运行bluez-simple-agent时,会出现以下情况:
ubuntu@ubuntu-armhf:/etc/bluetooth$ sudo bluez-simple-agent hci0 00:0D:18:A0:4E:35
Creating device failed: org.bluez.Error.AlreadyExists: Already Exists

如果它能正常工作就好了,但是当我尝试使用rfcomm进行绑定时,我反复收到“无法连接RFCOMM套接字:无效的交换”(在重新启动设备后第一次)和“无法连接RFCOMM套接字:每次都会拒绝连接”。

这是我的/etc/bluetooth/rfcomm.conf文件:

rfcomm0 {
    # Automatically bind the device at startup
    bind no;

    # Bluetooth address of the device
    device 00:0D:18:A0:4E:35;

    # RFCOMM channel for the connection
    channel 16;

    # Description of the connection
    comment "OBDII";
}

运行"rfcomm bind 0"会成功地在/dev/rfcomm0创建一个设备:

rfcomm0: 00:0D:18:A0:4E:35 channel 16 clean 

然而,尝试从 /dev/rfcomm0 读取数据时,出现了以下情况:

ubuntu@ubuntu-armhf:/etc/bluetooth$ sudo cat /dev/rfcomm0
cat: /dev/rfcomm0: Invalid exchange
ubuntu@ubuntu-armhf:/etc/bluetooth$ sudo cat /dev/rfcomm0
cat: /dev/rfcomm0: Connection refused
ubuntu@ubuntu-armhf:/etc/bluetooth$ 

之后,rfcomm 返回如下结果:

ubuntu@ubuntu-armhf:/etc/bluetooth$ rfcomm
rfcomm0: 00:0D:18:A0:4E:35 channel 16 closed 

根据"sdptool records"的结果,我认为我正在使用正确的通道(16)。

ubuntu@ubuntu-armhf:/etc/bluetooth$ sudo sdptool records 00:0D:18:A0:4E:35 
...
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 16
Profile Descriptor List:
  "Serial Port" (0x1101)
    Version: 0x0100

任何帮助都将不胜感激,因为我已经没有更多的想法了。
参考资料:
- rfcomm - 手动使用蓝牙 RFCOMM - 如何设置蓝牙 通过蓝牙进行串行连接 - 设备

关于错误信息“Creating device failed: org.bluez.Error.AlreadyExists: Already Exists”,这是因为设备已经被创建了。请尝试使用以下dbus命令来删除该设备:1. dbus-send --system --type=method_call --print-reply --dest=org.bluez "/org/bluez/bluetooth_PID/hci0"org.bluez.Adapter.GetProperties 2. dbus-send --system --type=method_call --print-reply --dest=org.bluez "/org/bluez/3858/hci0" org.bluez.Adapter.RemoveDevice objpath:"/org/bluez/3858/hci0/dev_00_0D_18_A0_4E_35",然后再使用代理工具进行配对。 - ashish
2个回答

4

从蓝牙设置中删除已配对的设备,然后重新添加它。


1
我知道这有点晚了,但既然我来了,可能还有其他人在努力解决这个问题,所以我会发布对我有效的方法,使用我认为是相同设备(OBDII ELM327蓝色连接器)。

[使用Debian Wheezy的BBB]

  1. 我在/etc/bluetooth/下有以下rfcomm.conf文件。
rfcomm0 {
    bind yes;
    device AA:BB:CC:DD:EE:FF; # Remote device's MAC
    channel 16;
    comment "OBDII";
}
  1. # rfcomm connect rfcomm0

每次BBB连接到设备时,似乎都会将其配置保存在/var/lib/bluetooth/XX:XX:XX:XX:XX:XX下(使用hcitool dev获取的蓝牙适配器的MAC地址)。

  1. 为了确保下次能够连接成功,我在启动时使用cron作业删除/var/lib/bluetooth/XX:XX:XX:XX:XX:XX文件夹中的所有内容,并添加以下行到cron中,使用控制台上的"crontrab -e"命令:

$ @reboot rm /var/lib/bluetooth/*

因此,每次重新启动后,我都可以使用Linux命令在必要时重新建立连接。

我知道这有点棘手,而且我不知道删除蓝牙文件夹是否好或坏,但对我来说它很有效,如果您有任何其他评论或建议,请让我知道。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接