2016-07-28 141 views
0

问题

我试图将多个蓝牙LE设备(心率监视器)连接到我的Android设备。我可以扫描并连接到它们。他们流传输很好,只是当我输出通知时,它会在一个传感器的数据之间跳转到另一个。试图通过蓝牙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 enable: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启用:真

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服务器断开连接。


尝试

  • 我试图添加一个新的CLIENT_CHARACTERISTIC_CONFIG(称之为CLIENT_CHARACTERISTIC_CONFIG2)在SampleGattAttributes类的字符串,该进来下面的代码片段播放(从服务分类):

    BluetoothGattDescriptor descriptor = characteristic 
           .getDescriptor(UUID 
             .fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG)); 
    


我想问题,如控制台说,有事情做,在这两种服务称为mBluetoothGatt(这是一个BluetoothGatt类型的对象)的变量。我的想法是这样的:

如果我有同步运行两个服务,那么如果我创造各两个不同BluetoothGatt对象,为什么我被告知正在使用相同BluetoothGatt对象?

+0

即使您认为您应该可以在实践中独立处理这两种设备,但我发现让事情可靠的唯一方法是同步多个外围设备的代码,以便我只有一个请求外设一次。它使启动缓慢。 – Ifor

回答

0

我通过输出基于设备地址的数据解决了这个问题。

因此,我不是只是吐出通知,而是放置一个条件(是DisplayData()方法),它说:“嘿,如果这是我们在这里寻找的输出的设备,那么只输出。

当然,这些设备不是时间同步的,但是当您使用时间记录时,这会有所帮助。

0

我没有看到您引用的源代码,但您是否为每个连接存储了不同的BluetoothGattCallback或返回值?我的意思是你如何评判这两种设备? connectGatt将返回一个BluetoothGattCallback实例来通知状态,或者您可以使用此实例执行进一步的操作,例如,知道连接状态等。