首页 文章

Bluez BLE连接Linux

提问于
浏览
3

我'm very new to Linux and Bluetooth development, and I' m不确定 sudo hcitool lecc <bdaddr>sudo gatttool -b <dbaddr> -I 之间的区别?我不要求任何关贸总协定的服务;我只想要两个设备之间的连接 .

我正在模糊地关注this widely referred to tutorial,我正在考虑在Bluez /tools/hcitool.c中调整 cmd_lecc 方法,但我无法使用 hcitool lecc 连接到我的BLE设备 .

当我使用 gatttool 连接时,我能够成功连接,但是使用 hcitool lecc 会返回错误'Could not create connection: Connection timed out',并且没有连接到BLE设备 . 但是,运行 sudo hcitool con 以显示活动连接会显示有一个:'Unknown handle 0 state 2 lm SLAVE' . 如果它没有 Build 连接,为什么它会在 hcitool 中将连接注册为活动状态?

因此,我的问题有三个:

  • 这两个命令有什么区别?

  • gatttool 是否适合我的目的,或者我应该找出与 hcitool 无关的内容(如this之后?

  • 为什么 sudo hcitool lecc <bdaddr> 部分连接,即使它超时?

非常感谢 .

1 回答

  • 1

    hcitool lecc <bdaddr> 创建一个连接并返回一个句柄,而 gatttool -b <bdaddr> -I 只打开一个交互式终端,其接口绑定到该地址但尚未连接 . 要使用 gatttool 命令进行连接,必须输入 connect ,这很可能也会失败 .

    我建议查看 hcitool 如何连接编写自己的代码,因为所有 gatttool 只是围绕 hcitool 使用的相同进程的包装器,但除非您复制其代码,否则它的包装器不可用 .

    最后, hcitool 报告的句柄0是尝试连接时留下的无效句柄,因为据我所见,所有有效句柄都大于0 .

相关问题