Ahmad Soomro
Ahmad Soomro

Reputation: 1

Trying to connect multiple devices via Bluetooth LE to android device

The Problem

I am trying to connect multiple Bluetooth LE devices (heart rate monitors) to my android device. I am able to scan, and connect to them. They stream just fine, just that when I output the notifications it jumps between one sensor's data to another.

I basically used this GitHub source code for a majority of this project. In the project, they use ONE service (called BluetoothLeService). In my project I have created TWO services, pretty much duplicates of each other except one handles calls for one user, the other one handles for the other user.

I'm getting this output onto the console:

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: Trying to use an existing mBluetoothGatt for connection. THIS ERROR IS FROM 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: Disconnected from GATT server.

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: Trying to use an existing mBluetoothGatt for connection. THIS ERROR IS FROM 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: Disconnected from GATT server.


Attempts


I think the problem, like the consoles says, has something to do with the variable in both Services called mBluetoothGatt (which is a BluetoothGatt type object). My thinking is like this:

If I have two services running synchronously, then if I create two different BluetoothGatt objects in each, why am I being told that the same BluetoothGatt object is being used?

Upvotes: 0

Views: 513

Answers (2)

Ahmad Soomro
Ahmad Soomro

Reputation: 1

I solved this problem by outputting data based on address of the device.

So instead of just spitting out the notifications, I put a condition (is the DisplayData() method) that said, "Hey, only output here if this is the device whose output we're looking for here."

Sure, the devices were not time-synched, but when you log using the time, that helps.

Upvotes: 0

Guo Xingmin
Guo Xingmin

Reputation: 1013

I was not see the source code you referred but did you stored the different BluetoothGattCallback or return values for each connection? I mean how did you judge the two devices? The connectGatt will return a BluetoothGattCallback instance to notify the status or you can use this instance to do further operations, e.g. know the connect status etc.

Upvotes: 0

Related Questions