2

I am developing an app to read glucose measurements from a BLE device which has the Glucose service enable. However i am not being able to read the measurements already taken, the on onCharacteristicChanged callback is never called. My code snippet is the following:

 @Override
 public void onServicesDiscovered(BluetoothGatt gatt, int status) {
        super.onServicesDiscovered(gatt, status);
        if (status == BluetoothGatt.GATT_SUCCESS) {
          mGlucoseService = 
          gatt.getService(BluetoothUUIDS.GLUCOSE_MEASUREMENT_SERVICE_UUID);
          mGlucoseCharacteristic = 
          mGlucoseService.getCharacteristic(BluetoothUUIDS
                    .GLUCOSE_MEASUREMENT_CHARACTERISTIC_UUID);
            gatt.setCharacteristicNotification(mGlucoseCharacteristic, true);
            BluetoothGattDescriptor descMeasurement = mGlucoseCharacteristic.getDescriptor(BluetoothUUIDS
                    .CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
            descMeasurement.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
            gatt.writeDescriptor(descMeasurement);

            mGlucoseContextCharacteristic = mGlucoseService.getCharacteristic(BluetoothUUIDS
                    .GLUCOSE_MEASUREMENT_CONTEXT_CHARACTERISTIC_UUID);
            gatt.setCharacteristicNotification(mGlucoseContextCharacteristic, true);
            BluetoothGattDescriptor descContext = mGlucoseCharacteristic.getDescriptor(BluetoothUUIDS
                    .CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
            descContext.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
            gatt.writeDescriptor(descContext);

            mRecordAccessCharacteristic = mGlucoseService.getCharacteristic(BluetoothUUIDS
                    .GLUCOSE_RECORD_ACCESS_CHARACTERISTIC_UUID);
            gatt.setCharacteristicNotification(mRecordAccessCharacteristic, true);
            mRecordAccessConfigurationDescriptor = mRecordAccessCharacteristic.getDescriptor(BluetoothUUIDS
                    .CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
            if (mRecordAccessConfigurationDescriptor != null) {
                mRecordAccessConfigurationDescriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);

                new Thread(new Runnable() {
                    public void run() {
                        boolean success = false;
                        while (!success) {
                            if (mGatt.writeDescriptor(mRecordAccessConfigurationDescriptor)){
                                success = true;
                            }
                        }
                    }
                }).start();

For getting the records i am using:

mRecordAccessCharacteristic.setValue(new byte[2]);
mRecordAccessCharacteristic.setValue(OPCODE_REPORT_NUMBER_OF_RECORDS, BluetoothGattCharacteristic
            .FORMAT_UINT8, 0);
    mRecordAccessCharacteristic.setValue(OPERATOR_ALL_RECORDS, BluetoothGattCharacteristic.FORMAT_UINT8, 1);
    mGattDevice.writeCharacteristic(mRecordAccessCharacteristic);

OR

    byte[] data = new byte[2];
    data[0] = 0x01; // Report Stored records
    data[1] = 0x01; // All records
    mRecordAccessCharacteristic.setValue(data);
    mGattDevice.writeCharacteristic(mRecordAccessCharacteristic);

Both ways are not working. Please, any help would be greatly appreciated!

Alex
  • 21
  • 1

0 Answers0