繁体   English   中英

尝试通过蓝牙LE将多个设备连接到android设备

[英]Trying to connect multiple devices via Bluetooth LE to android device

问题

我正在尝试将多个Bluetooth LE设备(心率监视器)连接到我的android设备。 我能够扫描并连接到它们。 它们流式传输很好,只是当我输出通知时,它在一个传感器的数据与另一个传感器的数据之间跳转。

对于该项目的大部分内容,我基本上都使用 GitHub源代码。 在项目中,他们使用一项服务(称为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 enable: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)字符串,这在以下代码片段(来自服务类)中起作用:

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


我认为问题就像控制台所说的那样,与两个服务中称为mBluetoothGatt的变量(这是BluetoothGatt类型的对象)有关。 我的想法是这样的:

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

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

因此,我不只是吐出通知,而是输入一个条件(是DisplayData()方法),说:“嘿,只有在这是我们要在这里寻找其输出的设备时,才在这里输出。”

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM