Read Temperature from BLE Thermometer using Android App

74 views Asked by At

I have purchased a BLE thermometer and developing an android app to read the temperature. I installed nRF connect and was able to see the BLE device listed with all its services. The temperature measurement characteristic is marked as Indicate. I don't seem to find how to get this indicate in nRF. Nothing happens when I read the temperature using the BLE device. This temperature is not reflected in nRF logs.

I developed an android app and was able to scan this BLE device, connect to it and enable indications. But the onCharacteristicChanged never gets invoked when I measure the temperature using the BLE device. My code is below.

private final UUID temperatureServiceUuid = UUID.fromString("00001809-0000-1000-8000-00805f9b34fb");
private final UUID temperatureMeasureUuid = UUID.fromString("00002A1C-0000-1000-8000-00805f9b34fb");
private final UUID temperatureDescriptorUuid = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");

public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) {
        mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);

        BluetoothGattDescriptor descriptor = characteristic.getDescriptor(temperatureDescriptorUuid);
        mBluetoothGatt.writeDescriptor(descriptor, BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);

    }

1

There are 1 answers

1
Vishnu S Dharan On
private final UUID temperatureServiceUuid = UUID.fromString("00001809-0000-1000-8000-00805f9b34fb");
private final UUID temperatureMeasureUuid = UUID.fromString("00002A1C-0000-1000-8000-00805f9b34fb");
private final UUID temperatureDescriptorUuid = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");

private void setNotificationTemp(BluetoothGatt gatt) {
    BluetoothGattService temperatureService = gatt.getService(temperatureServiceUuid);
    BluetoothGattCharacteristic temperatureChar = temperatureService.getCharacteristic(temperatureMeasureUuid);
    gatt.setCharacteristicNotification(temperatureChar, true)

    BluetoothGattDescriptor temperatureDescriptor = temperatureChar.getDescriptor(temperatureDescriptorUuid);
    gatt.writeDescriptor(temperatureDescriptor, BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
}