【问题标题】:Can connect to BLE device with hcitool but not gatttool?可以使用 hcitool 而不是 gatttool 连接到 BLE 设备吗?
【发布时间】:2017-03-07 23:58:45
【问题描述】:

我正在尝试在 QT 应用程序中从我的 PC 和 Raspberry Pi3 连接到蓝牙低功耗设备,但尝试连接时出现此 QT 错误:

qt.bluetooth.bluez: Unknown l2cp socket error:  QBluetoothSocket::UnknownSocketError "Transport endpoint is not connected"
qt.bluetooth.bluez: void QBluetoothSocketPrivate::_q_readNotify() 14 error: -1 "Resource temporarily unavailable"
qt.bluetooth.bluez: Unknown l2cp socket error:  QBluetoothSocket::UnknownSocketError "Resource temporarily unavailable"

我不认为它的 QT,我怀疑 bluez 是问题所在。我发现 Linux 可以通过以下方式找到设备:

sudo hcitool lescan

并且可以通过以下方式连接:

sudo hcitool lecc <address>

所以这很好。问题是,一旦我尝试使用 gatttool(这一定是 QT 尝试做的事情),我得到以下信息:

pi@user:~$ sudo gatttool -I 
[                 ][LE]> connect <address>
Attempting to connect to <address>
Error: connect error: Transport endpoint is not connected (107)
[<address>][LE]> 

结果是 PC 和 Raspberry 上的一些结果。 PC 上的 bluez 版本是 5.37,而 raspberry 是 5.23。

有什么想法吗? :(

【问题讨论】:

  • 此链接将为您提供帮助:stackoverflow.com/questions/15657007/…。根据帖子,您需要使用 gatttool -b
    -I
  • 回复有点晚了......每次他们更新 bluez/bluetooth 内核时,他们都会破坏其他东西。我相信当您使用 gatttool 时,内核会参与连接并执行许多其他操作,但是当您使用 hcitool 时,它会执行 hci 命令。

标签: linux qt bluetooth raspberry-pi bluez


【解决方案1】:

使用 Gatttool:

尝试输入random,如果没有问题,它很可能会起作用。

sudo gatttool -I -t random

您可以在单个命令中绑定到蓝牙地址。

sudo gatttool -I -t random -b <mac address>

使用 Hcitool:

sudo hcitool lecc --random <mac address>

您可以在执行时在另一个终端中查看详细的 HCI 嗅探日志

sudo hcidump -X

【讨论】:

  • 感谢您的建议。但是您是否有理想的步骤来连接 ble 设备。所以我可以简单地按照这些步骤进行操作,如果遇到问题,我需要调试,但这些步骤是理想的,所以不应该在步骤中混淆。
猜你喜欢
  • 2014-09-11
  • 1970-01-01
  • 2023-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多