Linux API上的低功耗蓝牙 [英] Bluetooth Low-Energy on Linux API

查看:211
本文介绍了Linux API上的低功耗蓝牙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台带有一些自定义GATT服务的设备,我想编写一个Linux程序与之交互.经过一番搜索,我发现Linux正在使用BlueZ处理Bluetooth LE协议.我正在将Ubuntu 15.10与BlueZ 5.35结合使用,但无法从用户空间程序中了解如何使用此BlueZ.我在任何地方都找不到API文档,没有教程,示例,也没有.除了仅连接到具有默认服务的蓝牙设备之外,甚至还可以使用此BlueZ堆栈来执行其他操作吗?如果是这样,文档在哪里? (最好是C/C ++ API,但此时一切正常)

I have a device with a few custom GATT services, and I would like to write a Linux program to interact with it. After some searching I found out that Linux is using BlueZ to handle the Bluetooth LE protocol. I'm using Ubuntu 15.10 with BlueZ 5.35, but I cannot figure out how use this BlueZ from a user-space program. I cannot find an API documentation anywhere, no tutorials, examples, nothing. Is it even possible to use this BlueZ stack to do anything other than just connecting to Bluetooth devices with default services? And if so, where is the documentation? (Preferably C/C++ API but at this point anything goes)

推荐答案

看看bluez来源[1]中的attrib/gatttool.c. Gatttool是一个命令行实用程序,用于使用C"API"连接到BTLE设备.但是,GATT接口未在libbluetooth中公开. btgatt-client是gatttool的较新替代品,因此也是另一个值得学习的示例,您可以在tools/btgatt-client.c中找到该btgatt-client(以启用编译功能,并使用--enable-experimental配置bluez).除了C接口外,bluez还集成了DBUS接口. bluetoothctl是使用DBUS接口的示例工具.蓝牙ctl的代码可以在client/ [2]中找到.使用bluez的C接口的另一个示例程序是Anki Drive SDK [3].它将bluez GATT C接口打包在其自己的库libbzle [4]中.使用C接口时,必须在建立BTLE连接时连接套接字. gatttool通过GATT接口执行此操作,而GATT接口又使用glib iirc.但是你也可以使用syscalls(socket,connect,...)来做到这一点,例如这里[5].该文档还说明:

Have a look at attrib/gatttool.c in the bluez sources [1]. Gatttool is a command line utility for connecting to BTLE devices using the C "API". The GATT interface is not exposed in libbluetooth though. A newer alternative to gatttool and thus another example to learn from is the btgatt-client, which you can find in tools/btgatt-client.c (to enable compilation configure bluez with --enable-experimental). Besides the C interface bluez integrated a DBUS interface. bluetoothctl is an example tool using the DBUS interface. The code of bluetoothctl can be found in client/ [2]. Another example program using the C interface of bluez is the Anki Drive SDK [3]. It packaged the bluez GATT C interface in its own library libbzle [4]. When using the C interface you have to connect a socket when establishing a BTLE connection. The gatttool does this via the GATT interface, which in turn uses glib iirc. But you can also do this using syscalls (socket, connect, ...) as explained e.g. here [5]. This document also explains:

不幸的是,到目前为止,还没有正式的API参考可以引用,因此建议更多好奇的读者下载并查看BlueZ源代码.

Unfortunately, as of now there is no official API reference to refer to, so more curious readers are advised to download and examine the BlueZ source code.

吉尔伯特·布劳特(Gilbert Brault)还从bluez [6]中提取了GATT接口,并使用以下免责声明链接至GATT接口[7]的基本doxygen文档:

Gilbert Brault also extracted the GATT interface from bluez [6] and links to a rudimentary doxygen documentation of the GATT interface [7] with the following disclaimer:

这是一项正在进行的工作,旨在记录所有重要功能和数据结构

This is a work in progress with the intent of documenting all important functions and data structures

Szymon Janc在2016年嵌入式Linux大会上的演讲现代Linux上的蓝牙"中也做了很好的概述[8].在42:00休息时,他谈论了未公开的C接口.但总的来说,他似乎建议使用DBUS API(请参见45:30的提示"幻灯片).在doc/gatt-api.txt [9]中可以找到一些DBUS文档,在test/中可以找到使用DBUS接口的Python示例.

Also Szymon Janc gave a nice overview in his talk "Bluetooth on Modern Linux" at the Embedded Linux Conference 2016 [8]. As off 42:00 he talks about the unexposed C interface. But in general he seems to recommend the DBUS API (see "Tips" slide at 45:30). Some DBUS documentation can be found in doc/gatt-api.txt [9] and Python examples using the DBUS interface can be found in test/.

希望这会有所帮助.

[1] http://git.kernel .org/cgit/bluetooth/bluez.git/tree/attrib/gatttool.c
[2] http://git.kernel.org/cgit/bluetooth/bluez.git/tree/client/
[3] https://github.com/anki/drive-sdk/
[4] https://github.com/anki/drive-sdk/tree/master/deps/bzle/
[5] https://people.csail.mit.edu/albert/bluez-intro/c404.html
[6] https://github.com/gbrault/gattclient
[7] http://gbrault.github.io/gattclient/index.html
[8] https://www.youtube.com/watch?v=tclS9arLFzk
[9] http://git.kernel. org/cgit/bluetooth/bluez.git/tree/doc/gatt-api.txt

[1] http://git.kernel.org/cgit/bluetooth/bluez.git/tree/attrib/gatttool.c
[2] http://git.kernel.org/cgit/bluetooth/bluez.git/tree/client/
[3] https://github.com/anki/drive-sdk/
[4] https://github.com/anki/drive-sdk/tree/master/deps/bzle/
[5] https://people.csail.mit.edu/albert/bluez-intro/c404.html
[6] https://github.com/gbrault/gattclient
[7] http://gbrault.github.io/gattclient/index.html
[8] https://www.youtube.com/watch?v=tclS9arLFzk
[9] http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/gatt-api.txt

这篇关于Linux API上的低功耗蓝牙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆