4

i am trying to read temperature value from health profile.health thermometer service. according to official google ble devlopment page when i try to notify a health thermometer characteristic to read temperature i try to write descriptor value (Client Characteristic Configuration) using writeDescriptor a callback method of writeDescriptor return status 5 according to google it's GATT_INSUFFICIENT_AUTHENTICATION. so i comment the code of writedescriptor and try to call the method mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); but onCharacteristicChanged method never called. when i talk to my ios devloper team. they said that they never write a descriptor value they just set the notification to true and they get temperature value from the same chip. to write a descriptor value is necessary for android developer to get notification ??? so at last i try to run the official bluetooth app from the bluetooth.com site for test purpose they just disable all three buttons notify read and write??? thank you and sorry for my English

[UPDATE]
find out some log which may cause some bonding issues please help me if you have any solution for that.

  • Short-Term Key generated still log as error
    11-08 11:26:44.392: E/bt-smp(1014): STK Generated

  • after that bond state change dramatically may this cause insufficient authentication
    11-08 11:26:49.437: I/BluetoothBondStateMachine(1014): bondStateChangeCallback: Status: 0 Address: 00:16:A4:C0:FF:EE newState: 2
    11-08 11:26:49.437: D/BtGatt.btif(1014): btif_gattc_upstreams_evt: Event 9
    11-08 11:26:49.437: E/BluetoothBondStateMachine(1014): In stable state, received invalid newState: 12

[UPDATE]
after upgrading kitkat 4.4 on nexus 7 . add two method
device.createBond();
device.setPairingConfirmation(true);

works for me now i can read the encrypted characteristic. but still unstable. but some success i got.

mcd
  • 1,434
  • 15
  • 31

2 Answers2

4

Yes, in Android for enabling BLE notification, you must both call mBluetoothGatt.setCharacteristicNotification(characteristic, enabled) and write suitable value to descriptor 0x2902 of that characteristic.

I am not sure why you get GATT_INSUFFICIENT_AUTHENTICATION, this may be caused by the implementation of the thermometer.

EDIT : From the new information in the comment and also the screen captured provided, there are a few things you may want to check :

  1. The characteristic is a indication characteristic, but not a notification characteristic. The value you write to the descriptor should be BluetoothGattDescriptor.ENABLE_INDICATION_VALUE, but not BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE. Notice that you still need to turn on the indication by setCharacteristicNotification(). (Confusing terminology here, but it is necessary as per the docs)

  2. For the unstable Bluetooth stack on Android, try to restart the Bluetooth, and turn of WiFi. This will increase the stability. (Although not 100% solving the problem)

reTs
  • 1,808
  • 1
  • 13
  • 26
  • Thanks For the response but Why over ios developer get the temperature value without setting the descriptor value just set notification true ??.so we have to create two different firmware for thermometer hardware one for ios and other for android ??????? – mcd Oct 28 '13 at 03:55
  • 1
    @mcd You don't need to create two different firmware. The same thermometer will work in both Android and iOS, but in the Android application you have to make an additional call to write the descriptor to make it work. My guess is actually iOS also write the descriptor, but iOS do it automatically when setting notification to true. – reTs Oct 28 '13 at 04:39
  • thanks . i already try to write the descriptor but it give me the status code of callback method onWriteDiscriptor call to 5. and i try to read the characteristic using readCharacteristic(characteristic); method return false – mcd Oct 28 '13 at 04:44
  • 1
    @mcd If the read method return false, there are quite a number of possible causes. I recommend you to check the property of the characteristic to see if it is readable first. – reTs Oct 28 '13 at 06:52
  • @mcd Something ran in to my mind suddenly. In iOS 5/6 it seems you can "read" a characteristic with notification property (PROPERTY_NOTIFY). In Android you can only read characteristic with read property (PROPERTY_READ). – reTs Oct 29 '13 at 02:53
  • thanks for your response i found that i don't have a read permission to read a characteristic (property & BluetoothGattCharacteristic.PERMISSION_READ) > 0) .so what should i do now how can i read a characteristic ????????? – mcd Oct 29 '13 at 05:04
  • Your check is incorrect. It should be (property & PROPERTY_READ) or/and (permission & PERMISSION_READ). – reTs Oct 29 '13 at 06:22
  • read property also not available and permission is also not available even notify property also not available . how ios fetch the characteristic ??????? – mcd Oct 29 '13 at 06:44
  • i found that android 4.3 ble sdk is unstable some time i get notification and some time i get descriptor value 5 i have to reconnect the device more then 5 time to get notification an write descriptor value. please give me some suggestion.device name is nexus 7 @reTs – mcd Oct 31 '13 at 05:41
  • @mcd See my edit. Hope I understand your lastest comment correctly. – reTs Oct 31 '13 at 07:06
0

In my case the problem was that BluetoothGatt object can accept only one pending operation. Solution was to do read/write operations in sequence, waiting for the completion callback of first before requesting second read/write operation.

madabrowski
  • 1,273
  • 14
  • 17