· CCC descriptor – CCC descriptor has the UUID 0x2902, but Android doesn’t support 16-bit UUID, so it needs to be change to 128-bit UUID - 00002902-0000-1000-8000-00805f9b34fb. The API gecko_cmd_gatt_set_characteristic_notification will return error that it can’t find CCC descriptor with UUID 0x2902 in the characteristic. So, I write the next handle of NOTIFY_CHAR which is the location of CCC descriptor of this characteristic on the server side as workaround. This problem didn’t happen when I tested with Android 7.0 devices.
BLE主设备以及GATT客户端例程(连接安卓手机)
简介
这篇文章是针对只拥有一块开发板同时想实现BLE主设备的人群。如果你有两块或以上的开发板,你可以参考SPP-over-BLE例程,其实现了主从设备两个角色,下面是链接:
如果你只有一块WSTK,你可以使用智能手机作为BLE从设备,然后在WSTK端实现主设备以及GATT客户端相关功能。
典型的连接过程以及连接后GATT相关操作如下:
如上步骤和操作是连接以及连接后的典型动作,但并非所有都是必须的。
如何使用这个例程
你需要如下设备
我加入了一个叫做“Demo service”的服务到GATT服务器,其包含了2个特征值,分别叫“NOTIFY_CHAR”和“RW_CHAR”,具体信息如下:
UUID 属性
Demo Service df6a8b89-32d1-486d-943a-1a1f6b0b52ed
NOTIFY_CHAR 0ced7930-b31f-457d-a6a2-b3db9b03e39a 通知
RW_CAHR fb958909-f26e-43a9-927c-7e17d8fb2d8d 读、写
我将源代码附在了文件末尾,其基于BRD4104A Rev A00(EFR32BG12 radio board)和Bluetooth SDK 2.7.0开发的,同时安卓的APP安装文件也附上了。遵循如下步骤来让例程跑起来。
下面是手机以及串口工具的截图:
图1. 串口打印信息
图2. 手机app截屏
安卓APP
我的专长并不是安卓开发,所以写这个app仅仅是为了配合WSTK主设备例程来进行演示。我并没有花很多时间来测试这个app的稳定性以及兼容性等,如果你有任何APP相关疑问,你需要找安卓开发工程师来寻求帮助。
测试过的设备:
型号 安卓版本
三星 Galaxy Tab S3 7.0
魅族 MX_4 5.1
一个已知的问题:
· CCC descriptor – CCC descriptor has the UUID 0x2902, but Android doesn’t support 16-bit UUID, so it needs to be change to 128-bit UUID - 00002902-0000-1000-8000-00805f9b34fb. The API gecko_cmd_gatt_set_characteristic_notification will return error that it can’t find CCC descriptor with UUID 0x2902 in the characteristic. So, I write the next handle of NOTIFY_CHAR which is the location of CCC descriptor of this characteristic on the server side as workaround. This problem didn’t happen when I tested with Android 7.0 devices.
安卓APP的源代码可以在这里下载 - https://github.com/fuzhen011/Android-Peripheral