如何使用Android订阅多个BluetoothLE特性 [英] How to subscribe to multiple BluetoothLE Characteristics with Android

查看:107
本文介绍了如何使用Android订阅多个BluetoothLE特性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Android应用程序,该应用程序应具有多个BLE特征.

I am developing an Android app which should subscribe to multiple BLE characteristics.

但是无论我做什么,我只会从一个特征中接收更新的值.

But whatever I do, I receive only the updated values from one characteristic.

这是代码:

BluetoothGattCharacteristic characteristicVel = gatt.getService(BleDefinedUUIDs.Service.KOMMMODUL_SERVICE).getCharacteristic(BleDefinedUUIDs.Characteristic.VELOCITY);
                gatt.setCharacteristicNotification(characteristicVel, true);
                BluetoothGattDescriptor descriptorVel = characteristicVel.getDescriptor(
                        BleDefinedUUIDs.Descriptor.CHAR_CLIENT_CONFIG);
                descriptorVel.setValue(BleDefinedUUIDs.Descriptor.ENABLE_NOTIFICATION_VALUE);
                gatt.writeDescriptor(descriptorVel);

            BluetoothGattCharacteristic characteristicAcc = gatt.getService(BleDefinedUUIDs.Service.KOMMMODUL_SERVICE).getCharacteristic(BleDefinedUUIDs.Characteristic.ACCELERATION);
            gatt.setCharacteristicNotification(characteristicAcc, true);
            BluetoothGattDescriptor descriptorAcc = characteristicAcc.getDescriptor(
                    BleDefinedUUIDs.Descriptor.CHAR_CLIENT_CONFIG);
            descriptorAcc.setValue(BleDefinedUUIDs.Descriptor.ENABLE_NOTIFICATION_VALUE);
            gatt.writeDescriptor(descriptorAcc);

无论我做什么,我都只会得到速度数据.如果更改两个块的顺序,则只会得到加速度,而没有速度数据.

Whatever I do I get only the velocity data. If I change the order of the two blocks I get acceleration only but no more velocity data.

要同时订阅许多特征,我该怎么做?

What have I to do in order to subscribe to many characteristics at once?

预先感谢

还原

推荐答案

要使描述符一个接一个地编写,请在启动下一个描述符之前,等待描述符写入的回调.

To get descriptors to write one after another, please wait for the callback from a descriptor write before starting the next one.

这篇关于如何使用Android订阅多个BluetoothLE特性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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