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?
Related
My BLE discovery and connecting is working fine on Android 6.0 and higher. However, on version 5.x devices (both are Samsung - Note 4 and Galaxy Core Prime) I am able to scan, find my peripheral, connect and get the onConnectionStateChange callback. All the connection steps work fine.
After onConnectionStateChange I call gatt.discoverServices() - this returns onServicesDiscovered() and then I call getSupportedGattServices(). getSupportedGattServices() returns successfully but it's missing the specific Service UUID that is on my peripheral. I know the UUID is there because I can see it on the peripheral and my other Android devices can connect to it. I'm logging all the discovered UUIDs and it only sees the Generic Attribute Profile and the Generic Access Profile services.
I checked the ScanResult class returned in LeScanCallback and the service UUID is there. And again, this is only happening on 5.x. 6.0+ Android devices discover the service without issue.
Thanks.
I've written an app that scans for bluetooth smart devices, you can pick one from a list, connect to it and exchange some data. All went fine until Android 6.0.
First, i fixed the new permission system so the app requests the location permission at runtime to be able to scan for devices. With that the app worked like it used to, but after turning bluetooth off and back on again the app won't connect anymore but always returns disconnected state with status code 133 in the gatt callback.
I then tried several things:
rebooted the device
re-installed the app
turn off wifi, enable / disable flight mode
checked with NRF master control panel, same issue with same statuscode
This all didn't solve the problem. The only way i was able to get it working again was the option "Network Settings Reset" from the menu "Backup & reset". Both development phones available here (Moto G3 and Samsung S6) feature this option, haven't seen it before Android 6.0.
My question is: are there others experiencing this problem and is there a fix or workaround for this? This could cause a lot of troubles, it so common to turn off /on bluetooth and the problem also appears after been in flight-mode.
Ok, so after a while i tackled this. I was working with NRF ble devices and could not connect but i was still able to connect to TI sensorTag devices.
There were some differences between the advertisements of the devices, some flags were not enabled for the NRF device and also the NRF device had no device name set. After changing this, i was able to connect again. Turned out that devicename must be enabled but can be left empty.
It seems in the Android 6.0 ble stack there is a change in how the connection to a device is made, the device is not connectable anymore if not the right advertisement settings are used after bluetooth is turned off and on again.
Remember Bluetooth has 4 states, ensure to check when it's already ON and not TURNING_ON:
if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_ON) {
...
}
Else you can't connect yet to the gatt server...
I'm developing 2 Android BLE applications. One app will serve as the peripheral role and the other app will serve as the central role. On the peripheral app, there is one encrypted characteristic with PROPERTY_WRITE and PERMISSION_WRITE_ENCRYPTED.
The central app is able to connect to the peripheral and discover its services. The first time that central attempts to write to the encrypted characteristic, the system begins the bonding process and a dialog for entering the PIN appears. After the PIN is entered correctly, the characteristic can be written to successfully. If the central disconnects from the peripheral and then attempts to reconnect, a connection is briefly established but then disconnected. The onConnectionStateChange callback is received on the peripheral with a status of STATE_CONNECTED and then immediately called again with a status of STATE_DISCONNECTED.
Unless I manually unpair the devices (from the Bluetooth settings) and then start the connection process again, the central is unable to connect to the peripheral.
I've tried this solution but it did not work for me.
BLE Device Bonding Remove Automatically in Android
Both apps are running on devices with Android 5.
This issue seems to be resolved in Android 5.1.1. Originally, I was running the peripheral app on a Samsung Galaxy Tab A with Android 5.0.2. I switched to a Nexus 9 running 5.1.1 and 6.0.1 and did not encounter the issue described above.
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
I have an application that needs to keep the bluetooth discovery process in a loop to always discover new bluetooth devices (when the BroadcastReceiver gets a BluetoothAdapter.ACTION_DISCOVERY_FINISHED, I just call the startDiscovery() again). I've recently added some socket communication to the app, that basically opens a Socket to a server, sends data and then closes the socket.
When I'm using 3G, everything works fine and a sniffer shows no TCP Retransmissions, the socket is cleanly opened and closed. Using Wifi, however, shows lots of TCP Retransmissions and sometimes even failures to connect the socket (with java.net.SocketException timeout).
I'm using a Samsung Galaxy S with Android 2.2.1. Is there something I'm overlooking?
Can you try to configure and move WiFi to a different channel ? If you are using WiFi also in the 2.4 GHz band interference is expected specially during initial discovery / connection, after connection it should become better as Bluetooth should frequency hop to avoid interference (unless WiFi is clogging the complete spectrum)