蓝牙低耗能:使用堆栈的BlueZ作为外设(定制服务和特色) [英] Bluetooth Low Energy: Use BlueZ stack as a peripheral (with custom services and characteristics)

查看:1497
本文介绍了蓝牙低耗能:使用堆栈的BlueZ作为外设(定制服务和特色)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用堆栈的BlueZ Linux机器上创建自定义的服务和特色的关贸总协定服务器。最终的目标是要在特色使用任何中央设备(例如iOS或Android设备)连接到服务器关贸总协定,发现服务和特点,以及操纵数据。

I am trying to use the BlueZ stack on a Linux machine to create a GATT server with custom services and characteristics. The final goal is to use any central device (e.g. iOS or Android device) to connect to the GATT server, discover the services and characteristics, and manipulate the data in the characteristics.

例如:


  • 周边与其中包含3个特征1服务。

  • 服务UUID = 0xFFFF的

  • 字符1 = UUID在0xAAAA,属性=可读

  • 字符2 UUID = 0xBBBB,属性=可读放大器;写

  • 字符3 UUID = 0xCCCC,属性=呈报

从中央设备,我应该看到的外围设备,连接到它,并发现一个服务(0xFFFF的),它有三个特点(加上0xAAAA,0xBBBB,0xCCCC)。那么我应该能够读取加上0xAAAA价值,读取和写入0xBBBB的价值,并在0xCCCC启用通知。

From the central device, I should see the the peripheral device, connect to it and discover one service (0xFFFF) which has three characteristics (0xAAAA, 0xBBBB, 0xCCCC). I should then be able to read the value of 0xAAAA, read and write to the value of 0xBBBB, and enable notifications on 0xCCCC.

请注意,我知道一<一href=\"http://stackoverflow.com/questions/16151360/use-bluez-stack-as-a-peripheral-advertiser?lq=1\">similar问题存在,但它只是解释了如何使用外设作为一个广告客户。 <一href=\"http://stackoverflow.com/questions/20682294/bluez-advertise-service-gatt-server-example\">Another解决问题说明如何创建一个GATT服务器,但没有解释如何使用的特点,性质(例如读取,呈报,等等)玩了,也许我失去了一些东西。

Please note that I am aware that a similar question exists, but it only explains how to use the peripheral as an advertiser. Another solved question explains how to create a GATT server, but does not explain how to play with the properties of the characteristics (e.g. readable, notifiable, etc.), or maybe I'm missing something.

感谢您提前。

推荐答案

您可以看到关贸总协定例如做法,或如警报/ server.c配置文件/目录下定义的配置文件。基本上,你只需要使用gatt_service_add()函数,继现有的code注册您的服务。例如:

You can see gatt-example practice, or defined profiles under profile/ directory such as alert/server.c. Basically, you just have to register your service using gatt_service_add() function, following the existing code. For example :

 gatt_service_add(adapter, GATT_PRIM_SVC_UUID, 0xFFFF,
    /* Char 1 */
    GATT_OPT_CHR_UUID16, 0xAAAA,
    GATT_OPT_CHR_PROPS, ATT_CHAR_PROPER_READ,
    GATT_OPT_CHR_VALUE_CB, ATTRIB_READ, read_func_callback,

    /* Char 2 Define here */
    ...
    /* Char 3 Define here */
    ...
    GATT_OPT_INVALID);
 }

另外,我忘了细节,但为了得到警报服务器的工作,您可以通过添加--enable-维护模式和--enable-experimental的配置过程中需要启用实验(和维护者模式?)

Also, I forgot the details but in order to get alert server working, you need to enable experimental (and maintainer mode?) during configuration by adding "--enable-maintainer-mode" and "--enable-experimental"

要运行,运行已编译的bluetoothd与-n和-d选项进行调试(也-E启用实验性服务)。您可能要运行bluetoothd后重设适配器。然后你就可以从远程设备使用gatttool(与远程设备上运行bluetoothd也)进行连接。

To run, run the compiled "bluetoothd" with -n and -d options to debug (also -E for enabling experimental services). You may want to reset your adapter again after running bluetoothd. And then you can connect from remote device using gatttool (also with bluetoothd running on remote device).

这篇关于蓝牙低耗能:使用堆栈的BlueZ作为外设(定制服务和特色)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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