【发布时间】:2016-12-02 05:33:34
【问题描述】:
问题
我正在尝试将多个蓝牙 LE 设备(心率监测器)连接到我的 Android 设备。我能够扫描并连接到他们。它们流式传输很好,只是当我输出通知时,它会在一个传感器的数据之间跳转到另一个。
我基本上使用this GitHub 源代码来完成这个项目的大部分工作。在项目中,他们使用 ONE 服务(称为 BluetoothLeService)。在我的项目中,我创建了两个服务,除了一个处理一个用户的调用,另一个处理另一个用户的调用之外,它们几乎是重复的。
我将这个输出放到控制台上:
07-27 21:14:01.786 9062-9062/com.example.android.aware D/BluetoothGatt:setCharacteristicNotification() - uuid:00002a37-0000-1000-8000-00805f9b34fb 启用:true
07-27 21:14:01.786 9062-9062/com.example.android.aware D/BluetoothLeService2:尝试使用现有的 mBluetoothGatt 进行连接。此错误来自 BLS2
07-27 21:14:01.796 9062-10009/com.example.android.aware D/BluetoothGatt: onClientConnectionState() - status=133 clientIf=7 device=E3:64:43:37:D2:AA
07-27 21:14:01.796 9062-10009/com.example.android.aware I/BluetoothLeService2:与 GATT 服务器断开连接。
07-27 21:14:01.796 9062-9062/com.example.android.aware D/BluetoothGatt:setCharacteristicNotification() - uuid:00002a37-0000-1000-8000-00805f9b34fb 启用:true
07-27 21:14:01.816 9062-9062/com.example.android.aware D/BluetoothLeService:尝试使用现有的 mBluetoothGatt 进行连接。此错误来自 BLS1
07-27 21:14:01.826 9062-10009/com.example.android.aware D/BluetoothGatt: onClientConnectionState() - status=133 clientIf=6 device=00:22:D0:41:CA:B6
07-27 21:14:01.826 9062-10009/com.example.android.aware I/BluetoothLeService:与 GATT 服务器断开连接。
尝试
-
我尝试在 SampleGattAttributes 类中添加一个新的 CLIENT_CHARACTERISTIC_CONFIG(称为 CLIENT_CHARACTERISTIC_CONFIG2)字符串,这在以下代码 sn-p(来自服务类)中起作用:
BluetoothGattDescriptor descriptor = characteristic .getDescriptor(UUID .fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
我认为这个问题,就像控制台所说的那样,与两个服务中名为 mBluetoothGatt 的变量(这是一个 BluetoothGatt 类型的对象)有关。我的想法是这样的:
如果我有两个服务同步运行,那么如果我在每个服务中创建两个不同的 BluetoothGatt 对象,为什么会被告知正在使用同一个 BluetoothGatt 对象?我>
【问题讨论】:
-
尽管您认为您应该能够在实践中独立处理这两个设备,但我发现让事情变得可靠的唯一方法是同步多个外围设备的代码,所以我只有一个一次对单个外围设备的单个请求。它使启动非常缓慢。
标签: java android bluetooth bluetooth-lowenergy