I am currently working on an Android App to read the temperature from a remote device. At the remote device I have a server which is running a device Information Service and a Health Thermometer service. My Android App can scan through and detect both the service and their characteristics. I have a button on my App which on click should request for the temperature from the remote server. Below is the code that executes on Button click.
public void readCustomCharacteristic() {
if (mBluetoothAdapter == null || mBluetoothGatt == null) {
Log.w(TAG, "BluetoothAdapter not initialized");
return;
}
/*check if the service is available on the device*/
BluetoothGattService mCustomService = mBluetoothGatt.getService(UUID.fromString("00001809-0000-1000-8000-00805f9b34fb"));
if(mCustomService == null){
Log.w(TAG, "Custom BLE Service not found");
return;
}
/*get the read characteristic from the service*/
BluetoothGattCharacteristic mReadCharacteristic = mCustomService.getCharacteristic(UUID.fromString("00002a1c-0000-1000-8000-00805f9b34fb"));
Log.i(TAG, mReadCharacteristic.toString());
BluetoothGattDescriptor descriptor = mReadCharacteristic.getDescriptor(
UUID.fromString(GattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
Log.i(TAG, descriptor.toString());
// final byte[] data = descriptor.getValue();
// Log.i(TAG, data.toString());
// descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
if(mBluetoothGatt.readCharacteristic(mReadCharacteristic) == false){
Log.w(TAG, "Failed to read characteristic");
}
}
The code detects the service properly along with the descriptors, but on read characteristics the value returned is false and I get Failed to read characteristics as a log message. Is there something that I am not doing. Any advise on this would definitely help. Thanks