Bluetooth Low Energy Service Discovery with Android 4.3 on Nexus 4

I am trying to use the BLE module (bluegiga BLE112) with my nexus 4 (android 4.3). I can connect, get the device name, connect to GATT, but service discovery fails.

Here's how the initial gatt connection happens (which seems to work successfully:

dev.connectGatt(getBaseContext(), true, btGattCB); 

Here's the GATT callback:

 private BluetoothGattCallback btGattCB = new BluetoothGattCallback() { @Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { super.onConnectionStateChange(gatt, status, newState); if(newState == BluetoothProfile.STATE_CONNECTED){ Log.i(TAG, "Gatt Connected"); gatt.discoverServices(); } else if(newState == BluetoothProfile.STATE_DISCONNECTED){ Log.i(TAG, "Gatt Disconnected"); } } @Override public void onServicesDiscovered(BluetoothGatt gatt, int status){ Log.i(TAG,"Status onServiceDiscovered: "+status); //status code i'm getting here is 129 List<BluetoothGattService> btServices = gatt.getServices();//try anyway } }; 

And here is my magazine:

 09-28 12:58:37.611 4118-4130/com.jnewt.btFive I/PDU? Scan Callback 09-28 12:58:37.611 4118-4130/com.jnewt.btFive I/PDU? Device is: 00:07:80:67:2F:63 09-28 12:58:37.611 4118-4130/com.jnewt.btFive I/PDU? Device Name: BGT GPIO Test 09-28 12:58:43.607 4118-4118/com.jnewt.btFive I/PDU? Scan Timeout 09-28 12:59:13.539 4118-4129/com.jnewt.btFive I/PDU? Gatt Connected 09-28 12:59:43.561 4118-4190/com.jnewt.btFive I/PDU? Service Discovery Failed 09-28 12:59:43.581 4118-4130/com.jnewt.btFive I/PDU? Gatt Disconnected 09-28 13:00:00.920 4118-4129/com.jnewt.btFive I/PDU? Gatt Connected 09-28 13:00:30.902 4118-4130/com.jnewt.btFive I/PDU? Service Discovery Failed 09-28 13:00:30.922 4118-4190/com.jnewt.btFive I/PDU? Gatt Disconnected 09-28 13:01:20.265 4118-4129/com.jnewt.btFive I/PDU? Gatt Connected 09-28 13:01:50.277 4118-4190/com.jnewt.btFive I/PDU? Service Discovery Failed 09-28 13:01:50.297 4118-4130/com.jnewt.btFive I/PDU? Gatt Disconnected 09-28 13:01:56.113 4118-4129/com.jnewt.btFive I/PDU? Gatt Connected 09-28 13:02:26.115 4118-4190/com.jnewt.btFive I/PDU? Service Discovery Failed 09-28 13:02:26.125 4118-4130/com.jnewt.btFive I/PDU? Gatt Disconnected 

On the page https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html I do not mention 129 as a possible status (none of the constants matches 129).

At the moment I have all the ideas. I highlighted the problem on an Android phone by testing a similar example for iphone. I also tried several applications available in the playback store, and they have a similar problem (you can connect, get a name, etc., but no services).

+7
android nexus-4 bluetooth-lowenergy
source share
6 answers

Actually today I got the same error code when testing my application on Nexus 7. My problem was that I called 2 X Gatt.connect in a short time. Perhaps this will help you. Keep in mind that you do not connect twice in a short time to your touch device.

+6
source share

from BleConstants.java public static final int GATT_INTERNAL_ERROR = 129;

+4
source share

I did some tests on my Nexus 7 with a TI sensor tag.

  • Nexus 7 (Android 4.3) β†’ 0x81 GATT_INTERNAL_ERROR
  • Upgraded Nexus 7 for Android 4.4.2 β†’ 0x81 GATT_INTERNAL_ERROR
  • Disable WiFi, onServicesDiscovered has never been called.
  • Turn off and turn on Bluetooth, it works !!!
  • Turn on Wi-Fi, onServicesDiscovered again failed.
  • Turn off WiFi, it works again.

I am also testing the same program on the Galaxy S4 (Android 4.3) and it works well at all times.

Therefore, I believe that the BLE stack on the Nexus 7 is not very good.

If you can live without WiFi, maybe everything is fine, but if you find another Android 4.3 device, try other devices.

+2
source share

Well, I have the same problem.

Checking binary constants in BluetoothGATT. I suggest just getting rid of the error. Perhaps, when defining constants, someone incorrectly typed 0 too much, and in the end it was 257 instead of 129. (If the status code is always looking for a binary representation, it shows more than a decimal value)

I will definitely not look for Android source code to find out if it is pasted in binary or decimal.

  Binary Dec ----------- --- 0 1000 0001 129 1 0000 0001 257 0 0000 0101 5 0 0000 1111 15 0 0000 1101 13 0 0000 0111 7 0 0000 0110 6 0 0000 0000 0 0 0000 0011 3 

However, do you need a solution? For me, rebooting the phone helped. During the second reboot, I first turned off Bluetooth manually.

Until an error occurred, I programmatically disabled and activated Bluetooth every time I tested my application. He worked flawlessly for almost 2 months. Then I deleted the β€œwaste of time” BT-restart-code, and this error appeared and cost me half a day to check.

Deduplication time was never a problem for me, devices were displayed instantly.

Development phone: Nexus 4 / Android 4.3 (constantly updated) BLE device: Texas Instruments CC2541 devices

+1
source share

I get this error if my BLE device is already paired with my phone. The error will be fixed as soon as I turn off the device and open the service again.

+1
source share

I got the same error using the TI-CC2541 chip. The solution was to use a 128kB chip instead of 256kB. For example, "SimpleBLEPeripheral" is for a 128kB chip.

0
source share

All Articles