0

I am developing an android app that fetches temperature from a bluetooth thermometer. I followed the instructions on the google developer page.

https://developer.android.com/guide/topics/connectivity/bluetooth-le.html

I could scan the devices and get connected to the thermometer. I am exactly using the same code from the following github.

https://github.com/googlesamples/android-BluetoothLeGatt/

Instead of using the the heart rate service and associated characteristics. I am using temperature service and the characteristic. I have changed these value on the following page that I downloaded from github

android-BluetoothLeGatt/Application/src/main/java/com/example/android/bluetoothlegatt/SampleGattAttributes.java

I using the following bluetooth thermometer.

http://www.cooper-atkins.com/Products/Blue2/

This is the API document I got from COOPER-ATKINS.

https://drive.google.com/open?id=1eq93Qc6uy0Vv9KompukLuIUnJK4B-e-0

In page 6 I have highlighted the service uuids and characteristic uuids I have replaced in the github code.

I could read the temperature data but only once. If the temperature changes I could not see the temperature value is refreshed in app automatically. I have to hit the temperature list button to get the recent value. Could anyone suggest what I am missing or doing wrong.

Please let me know if you need more info.

venutamizh
  • 53
  • 8

1 Answers1

0

The characteristics you highlighted have both read and indicate property.

Reading the characteristic (Calling BluetoothGatt.readCharacteristic in Android) only obtains the value at that instant by definition.

You have to enable the indication to get every update of the value. You can find how to enable a notification (not indication) on this SO thread. You can substitute the constant value to enable indication.

reTs
  • 1,808
  • 1
  • 13
  • 26
  • the code already contains enable notification in function setCharacteristicNotification() on bluetoothLeService.java. Could you please check on the github. Let me know if there's anything wrong in that. – venutamizh Feb 28 '18 at 03:55
  • `descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);` Are you still using this line? You have to change the constant. – reTs Feb 28 '18 at 04:12
  • This what I have used in setCharacteristicNotification function--BluetoothGattDescriptor descriptor = characteristic.getDescriptor( UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG)); descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); – venutamizh Feb 28 '18 at 04:54
  • Sorry I couldn/t edit my comment. After your suggestion I changed to ENABLE_NOTIFICATION_VALUE to ENABLE_INDICATION_VALUE. But when debugging the app sometimes I get the temperature value refreshed but not always and when I try to run the app without any debugger attached it just stays the same(first temp reading) – venutamizh Feb 28 '18 at 05:05
  • As for the question asked, solution given by reTs is perfect. Usage of ENABLE_INDICATION_VALUE got the desired result. – venutamizh Mar 01 '18 at 04:55