且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

订阅通知后未调用BLE GATT onCharacteristicChanged

更新时间:2023-01-24 10:26:40

所以,我终于弄清楚了我的错误:) 正如您在上面看到的,我正在使用一个UUID,该UUID具有与我的特征相同的描述符基础(以3f54XXXX-....开头)

So, I finnally figured out my mistake :) As you can see above, I'm usinng a UUID with the same base for my descriptor as my characteristics (starting with 3f54XXXX-....)

我将其更改为public static final UUID X_ACCEL_DESCRIPTOR_UUID = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");,现在一切正常.

I changed it to public static final UUID X_ACCEL_DESCRIPTOR_UUID = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"); and now everything is working as expected.

我以前没有这样做,因为我认为每个特性都应该有一个描述符.但实际上,根据

I did not do this before as i thought that there should be a descriptor for each characteristic. But in fact, according to the Client Characteristic Configuration the ...

[...]描述符应在绑定设备的连接之间保持不变.客户端特征配置描述符对于每个客户端都是唯一的.

[...] descriptor shall be persistent across connections for bonded devices. The Client Characteristic Configuration descriptor is unique for each client.

因此,我检查了RedBearLab Android应用程序示例,发现描述符的UUID等于发布在其他SO答案上的UUID.

So I checked the RedBearLab Android App example and saw that the descriptor's UUID equals the ones posted on other SO answers.

这也解释了为什么我的应用程序在BLE扫描仪应用程序中启用后收到通知的原因:由于描述符应在绑定设备的连接之间持久存在,因此BLE扫描仪应用程序也使用此UUID作为描述符,从而为该通知启用了通知客户(=我的电话).

This also explains why my App received Notifications after I enabled them in the BLE Scanner App: As the descriptor shall be persistent across connections for bonded devices, the BLE Scanner App used also this UUID for the descriptor and thus enabled notifications for the client (= my phone).