I'm trying to use a BLE module (bluegiga BLE112) with my nexus 4 (android 4.3). I can connect, get the name of the device, connect to GATT, but service discovery fails.
Here's how do the initial gatt connection (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's my Log:
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
From the https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html page, I don't see 129 mentioned as a possible status (none of the constants match 129).
I'm all out of ideas at this point. I have isolated the issue to the android phone by testing with an similar example for iphone. I've also tried several of the apps available at the play store, and they have a similar issue (can connect, get name, etc, but no services).
Actually got the same errorcode today while testing my App on Nexus 7. My problem was, that I called 2 X Gatt.connect in short time. Maybe this helps you. Be aware, that you don't connect twice in a short time to your sensor device.
from BleConstants.java public static final int GATT_INTERNAL_ERROR = 129;
I did several tests on my Nexus 7 with TI sensor tag.
0x81 GATT_INTERNAL_ERROR
0x81 GATT_INTERNAL_ERROR
onServicesDiscovered
was never called.onServicesDiscovered
failed again.I also test the same program on Galaxy S4 (Android 4.3) and it works well at all time.
Therefore, I believe that the BLE stack on Nexus 7 is not good.
If you can live with no WiFi, it may be OK, but if you can find some other Android 4.3 device, you shall try other devices.
Well, I had the same Problem.
Inspecting the binary values of the constants within BluetoothGATT I suggest that simply 129 Means Failure. Maybe, while defining the Constants someone mis-typed a 0 too much and it ended up being 257 instead of 129. (If it's a Status code always look for the binary representation, it reveals more than a decimal value)
I will definitely not look into the Android source code just to find out if it is inserted in binary in there or in decimals.
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
Still, you need a solution to this ? For me rebooting the phone -twice- helped. During second reboot I first turned off Bluetooth manually.
Until the error occured I had programmatically shut-down and reactivated Bluetooth on every test run of my app. It worked flawless for almost 2 Months. Then I removed the "waste of time" BT-restart-code , and this error showed up and cost me half a day to check out.
Dedection time was never an issue for me, devices show up instantly.
Development Phone : Nexus 4 / Android 4.3 (updated constantly) BLE Device : Texas instruments CC2541
I get this error if my BLE device is already paired with my phone. Error gets resolved once I un-pair the device and discover service again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With