Cannot establish BLE connection between Android 5 and BLE device - android

I'm stuck with implementing connection between Android Lollipop smartphone and BLE device (TI experimenter board with BLE module). I use following call to connect:
device.connectGatt(context, true, mGattCallback);
I've managed to establish connection for Android 4.3 and 4.4, but when I use this same code for Android 5, I get following error on BluetoothGattCallback::onConnectionStateChange:
onClientConnectionState() - status=133 clientIf=5 device=D0:36:12:CD:73:49
Error code 133 means GATT_ERROR.
I tried to use my own app, google sample and BLE scanner app from play market, but none of them were able to connect to device. I also tried several Android 5 smartphones with no luck.
However, I have another device (TI wireless connectivity development kit), and I can establish connection between it and Android 5 smartphone. So the issue is related to Android 5 and my particular device. I wonder how it can be solved or at least how can I debug this kind of error to find out the root cause.
P.S.
I also tried the approach proposed by #nayoso here, but it didn't helped either.

You may have hit the maximum connection number, see this:
https://www.youtube.com/watch?feature=player_detailpage&v=qx55Sa8UZAQ#t=1712

Related

BLE onClientConnectionState() status=22 and status=19 only when connecting to some devices

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
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.

GATT Error 133 when connecting to raspberry pi 3b+ but not when connecting to arduino?

To sumerize what I want to accomplish here:
I want to simulate sensors on a raspberry pi and make them available through bluetooth low energy to an android phone.
So what works:
Connecting with "nRF Connect" app to arduino.
Connecting with own app to arduino.
What sometimes works seemingly at random:
Connecting with "nRF Connect" to rbpi.
What doesn't work:
Connecting with own app to rbpi.
When errors occur with the nRF Connect app it tells me a GATT error 133 error occured, that is the same error that I receive in my app, but my app is never able to connect. The just serves as verification tool so as to determain that the problem is not with my app.
But there must be something diffrent because it does work most/some of the time with the nRF Connect app.
On the other hand if something is wrong with it, it should't work with the arduino but it does work.
What do you guys think?
What is the cause of the problem?
The app or the rbpi?
Ive seen online that error 133 has been a very sticky problem and have not seen concrete solutions for it.
I found the problem.
The raspberry pi 3b+ has a dual mode bluetooth chip.
In de code on the android side of things you use the method connectGatt() to connect to the remote ble gatt server. You would expect that it would naturally connect to the LE side of the bluetooth chip of the rbpi but apperiantly this is not the case.
This post provided me with the answer:
https://raspberrypi.stackexchange.com/questions/90696/bluetooth-low-energy-gatt-services-not-found-on-android

Android 7 Network Unreachable

Through my app, 2 devices can connect by a normal socket connection.
It is working on every device that i have tested, but on devices that have Android 7 it doesn't work, it gives me Network unreachable on the creation of the socket. I did some research and I could not find the solution or even behavourial changes on the devices with Nougat.
Does any of you know a possible solution ?

BLE connectivity not consistent on Samsung devices

We are using Android BLE code for connection to a custom hardware and with most mobile devices, this works perfectly. However, when it comes to Samsung with the Android OS Version 6.0.1, attempt for connection is not successful in most cases.
The problem is happening after trying to connect to a device with bluetoothDevice.connectGatt(context, false, gattCallback);
In onConnectionStateChange callback gatt status code 133 is received and in that case what the app does is to close the current instance of the BluetoothGatt and connect again to the device for a new BluetoothGatt instance. This workaround helps to get a connection after a couple of retries but this is definitely not the way how it should work.
After doing some BLE sniffing, it is clear that the device is not even trying to connect to the peripheral and just gives out the general gatt error (133). What is interesting that this has been a major problem only for the Marshmallow update, more specifically on the Android 6.0.1.
So my question is whether anybody experienced similar connectivity issues with only selected devices, where the mobile device tries to connect to the device and instead receives 133 gatt status code?

Bluetooth HM-10 android bonding

Need advice/help on what I might be doing wrong.
What I have:
Plugged in a HM-10 module to my Arduino.
-Factory Default settings except connection type:
--Using AT+TYPE3 (3:Auth and bond ).
Android LG G4, running Android 6 (Marshmallow) .
Issue:
Bluetooth HM-10 is visible to connect to in Android when searching for Bluetooth devices but when using the default pairing code "000000" "Wrong PIN or passkey. Try again?" message keeps coming up.
What I tested:
Windows 10 laptop bonds with the HM-10 device. (Verified MAC address by running AT+RADD? )
AT+TYPE0 (0:Not need PIN Code ) connects via BLE Scanner app.
Asked three different people with different Android phones for help:
-Newest Samsung phone: Bonds
-Older Samsung phone: Bonds
-OnePlus One phone: Does NOT bond
Hypothesis
Bluetooth library on the devices that cant connect might be lacking handshake protocol when talking to the HM-10 module.
I'm newer of these module HM-10,HM-16, and I meet same problem too.
Finally I found install APP "msmble" in android app store can solve this problem and do some simple test, like send word.
I guess protocol or UUID is the reason, but I don't know the detail.
There's another issue, no matter how I change the PIN setting. msmble always no need to enter PIN code.
Yu-Sheng

Categories

Resources