C / C ++ BLE读/写配合bluez例如 [英] C/C++ BLE read/write example with Bluez

查看:3207
本文介绍了C / C ++ BLE读/写配合bluez例如的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始建立一个简单的BLE网络与微控制器和覆盆子PI(TARDIS BLE加密狗)。作为一个起点,我要寻找一个简单的C或C ++的例子来读/写设备BLE,类似于什么我能够做的命令行了。到目前为止,我已经找到了例子是相当复杂的。作为一个初学者BLE我需要一些非常简单的例子,从一个更复杂的设计前进之前建立。我还好用硬编码的BLE设备名称,因为我有下面的gatttool例子。

I am starting to build up a simple BLE network with a microcontroller and a raspberry pi (tardis BLE dongle). As a starting point, I am looking for a simple C or C++ example to read/write a BLE device, similar to what I am able to do over the command line. The examples I have found so far are quite complicated. As a BLE beginner I need some very simple examples to build from before moving forward with a more complicated design. I am okay with hard-coding the BLE device name as I have in the gatttool example below.

下面是如何我目前使用的命令行选项从配合bluez。

Here is how I currently use the command line options from Bluez.

在命令行中我可以使用:

From the command line I am able to use:

$ sudo hcitool lescan
LE Scan ...
BB:A0:50:02:18:07 MyDevice

接下来我能够连接到设备与gatttool在命令行:

Next I am able to connect to the device on the command line with gatttool:

$ sudo gatttol -b BB:A0:50:02:18:07 -I
[BB:A0:50:02:18:07][LE]> connect
Attempting to connect to BB:A0:50:02:18:07
Connection successful

最后我能够阅读和使用适当的手柄写

Finally I am able to read and write using the appropriate handles

[BB:A0:50:02:18:07][LE]> char-write-req 000f 0100
Characteristic value was written successfully
[BB:A0:50:02:18:07][LE]> char-write-cmd 0011 4C467A

我已经使用了初步研究,并开始有些网站:结果的 http://people.csail.mit.edu/albert/bluez-intro/c404.html
结果的https://github.com/carsonmcdonald/bluez-experiments/blob/master/experiments/scantest.c

推荐答案

东西简单吗?如何短是一条绳子?我个人认为gatttool code本身是很简单的跟随,并提取自己的目的(我最近做了)。但如果这真的不适合你那么另一个选择是 libgatt 。它本质上是相同的code,它gatttool用途,但已经被更方便地捆绑成一个公共图书馆的API。看看 gatt.h 已连接/读/写等希望这应该是不言自明如何使用它。

Something simple? How short is a piece of string? I personally think that the gatttool code itself is simple enough to follow and extract for your own purposes (I've done it recently). But if that's really not suitable for you then another option is libgatt. It's essentially the same code that gatttool uses but has been bundled more conveniently into a public library API. Have a look at gatt.h which has connect/read/write etc. Hopefully it should be self evident how to use that.

这篇关于C / C ++ BLE读/写配合bluez例如的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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