1
votes

I am working on an app where I want to connect to multiple BLE devices. I have 2 types of BLE devices I need to connect to(one using a TI board and one using a Nordic board).

Issue 1

My Issue comes when connecting to a Nordic board while using a S5. Essentially any time I connect another device after a nordic device is connected it will disconnect and the log shows:

onClientConnectionState() status=22

From what I read this means the Android OS disconnected from the device and there is not much I can do

I can connect to as many of the TI Boards as I want(tested 6) and can connect a Nordic board after, but as soon as I connect any other device the nordic board disconnects.

When there is a Nordic board connected and I try to connect another nordic board both disconnect.

Issue 2

When I connect to a Nordic board it stays connected(even with other devices connected prior) but after a certain amount of time it disconnects and in the log shows:

onClientConnectionState() status=19

From what I read on this it means the BLE device terminated connection

I tested it twice and it seems to be almost exactly 1 minute between connection and disconnection:

11:00:09.850 D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=7 device=F9:A2:E9:86:EC:82
11:01:09.730 D/BluetoothGatt: onClientConnectionState() - status=19 clientIf=7 device=F9:A2:E9:86:EC:82

11:04:20.270 D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=F9:A2:E9:86:EC:82
11:05:19.740 D/BluetoothGatt: onClientConnectionState() - status=19 clientIf=6 device=F9:A2:E9:86:EC:82

Things I've tried

So my first idea was lets see if its just my app or maybe an issue with the BLE device. I use nRF app and connected to the Nordic board and then connected to multiple other devices. It was fine, I watched the log and no disconnects and I was able to listen to all the characteristic from every device.

So I came to the conclusion I am doing something wrong in my app as it is possible to connect to multiple devices after the nordic board. So I began analyzing what I am doing in my app.

Am I handling the 2 device types differently? The devices have different advertised services and I filter for them. The only thing I do differently between devices is depending on the service found I label them by their device type. But that is it, I have analyzed this multiple times to make sure nothing that would matter is handled differently.

After trying to figure out what causes this for a while, I decided to try on another device(lower spec Android GO phone and Doogee x20 Android 7) and my app worked completely fine. Connected to 2 Nordic boards then multiple TI boards, and they do not disconnect. Testing multiple times it works consistently how it should, no issues.

One oddity is occasionally on the S5 I've gotten it to work just by continually trying to connect but this has only happened 2 times and I didn't think to wait and see if the Nordic boards disconnect after a minute as I hadn't realized this the 1 minute issue yet.

I just tested on another S5 and it worked on my first attempt but hasn't since.

So the recipe for this to happens seems to be:

  • Samsung S5(Whether this is due to Android 5.0 or specific to the device I'm not sure)
  • Nordic boards but not TI
  • My app but not nRF

Changing any of the above and there is no issue

Edit: I am using this to connect:

deviceEntry.gatt = device.connectGatt(this, false, GattCallback(this, deviceEntry))

deviceEntry is just a class that I made to hold the BluetoothGatt and the state together

1

1 Answers

1
votes

The issue was solved by communicating to the BLE device. Not sure why this was specific to the Samsung S5 and Nordic board. But all I did was setup notifications for a characteristic and it no longer disconnected.