首页 > c > 在英特尔爱迪生上使用C开发BLE外设

在英特尔爱迪生上使用C开发BLE外设 (develop BLE peripheral using C on intel edison)

问题


我正在尝试使用C库在intel-edison中开发蓝牙LE外设。该设备应该能够:

  1. 做广告(GAP)
  2. 接受连接(GAP)
  3. 支持自定义GATT服务,只需读/写特性值。

我尝试使用HCI和bluez来实现这一点。bluez-experimentsintel-edison-playground,演示如何进行广告和扫描,可以编译并在爱迪生上运行。BLE广告和扫描确实有效。

但我很难弄清楚如何接受连接并支持GATT服务。我尝试搜索关于HCI文档的goolge但没有运气。有人可以提供一段代码(c或伪或描述)吗?

非常感谢!
安德鲁

解决方法

如果您下载bluez源代码,您将在/doc/mgmt-api.txt中找到有关hci协议的文档。我自己并没有使用hci接口,我不确定开发人员是否打算让实现者使用这个接口来实现外围设备,所以我不确定它的效果如何。

我为我的项目使用了DBus API方法,该方法在/doc/gatt-api.txt和/doc/advertising-api.txt中列出。这种方法涉及编写一个程序,该程序创建支持特定org.bluez DBus接口的DBus对象(包含GattCharacteristic1和GattDescriptor1的GattService1)和用于将所有内容暴露给bluez的ObjectManager接口。然后使用LEAdvertisment1定义广告内容并使用适配器上的LEAdvertisingManger1接口注册广告。

我使用Qt来简化DBus通信部分。

Bluez上用于BLE的DBus API仍处于大量开发阶段,并不支持所有功能(例如,我还没有找到启动和停止广告的方法)。5.31包含许多已添加的支持和一些关于描述符的关键错误修复,但需要更新的内核。

问题


I am trying to develop a bluetooth LE peripheral in intel-edison, by using C library. The device should be able to :

  1. advertise (GAP)
  2. accept connection (GAP)
  3. support custom GATT service, simply read/write value of characteristic.

I try to use HCI and bluez to implement this. bluez-experiments, intel-edison-playground, which demonstrate how to advertise and scan, can be compiled and run on edison. BLE advertising and scanning do work.

But I have hard time to figure out how to accept connection and support GATT service. I try to search on goolge about the HCI document but have no luck. Can someone provide a snippet of code (c or pseudo or a description)?

Thank you so much!
Andrew

解决方法

If you download the bluez source you'll find documentation on the hci protocol in /doc/mgmt-api.txt. I'm not using the hci interface myself, and I'm not sure if the developers intend for implementors to use this interface to implement peripherals, so I'm not sure how well this will work.

I went with the DBus API approach for my project, which is outlined in /doc/gatt-api.txt and /doc/advertising-api.txt. This approach involves writing a program which creates DBus objects which support specific org.bluez DBus interfaces (GattService1 which contains GattCharacteristic1 and GattDescriptor1) and the ObjectManager interface to expose everything to bluez. You then use LEAdvertisment1 to define what is advertised and register the advertisement using the LEAdvertisingManger1 interface on the adapter.

I used Qt to simplify the DBus communication parts.

The DBus API for BLE on bluez is still in heavy development, and not all features are supported (I still haven't found a way to start and stop advertising, for example). 5.31 contains a lot of added supported and some critical bug fixes for descriptors, but requires a newer kernel.

相似信息