'Medisana BS 444 - onCharacteristicChanged never triggered

I try for my BLE Scale to write a simple app which displays my weight. I followed the openscale guide for this, but my onCharacteristicChange method never changes. If I pass it manually with nRF Connect (subscribe to the indicate services) and the keyword I get the respective values. I have also tried to implement this with code, but I have no effect with it.

private BluetoothGattCallback serverCallback =
        new BluetoothGattCallback() {
            List<BluetoothGattCharacteristic> characteristics = new ArrayList<>();

            public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
                super.onConnectionStateChange(gatt, status, newState);

                if (newState == BluetoothProfile.STATE_CONNECTED) {
                    Log.d("LOL444", "Connected to GATT.");
                    gatt.discoverServices();
                } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
                    Log.d("LOL444", "Disconnected from GATT.");
                }


            }

            @Override
            public void onServicesDiscovered(BluetoothGatt gatt, int status) {
                Log.d("LOL444", "onServicesDiscovered");

                if (status == BluetoothGatt.GATT_SUCCESS) {
                    characteristics.add(gatt.getService(WEIGHT_MEASUREMENT_SERVICE)
                            .getCharacteristic(FEATURE_MEASUREMENT_CHARACTERISTIC));
                    characteristics.add(gatt.getService(WEIGHT_MEASUREMENT_SERVICE)
                            .getCharacteristic(WEIGHT_MEASUREMENT_CHARACTERISTIC));
                    characteristics.add(gatt.getService(WEIGHT_MEASUREMENT_SERVICE)
                            .getCharacteristic(CUSTOM5_MEASUREMENT_CHARACTERISTIC));

                    subscribeToCharacteristics(gatt);

                }

            }




            @Override
            public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
                Log.d("LOL444", "onCharacteristicChanged");
                processData(characteristic.getValue(), gatt);
            }

            @Override
            public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
                Log.d("LOL444", "onDescriptorWrite " + status);
                //super.onDescriptorWrite(gatt, descriptor, status);

                if(characteristics.size() > 1){
                    characteristics.remove(0);
                    subscribeToCharacteristics(gatt);
                }
                else{
                    writeCMD(gatt);
                }
            }


            private void subscribeToCharacteristics(BluetoothGatt gatt) {
                Log.d("LOL444", "subscribeToCharacteristics " + characteristics.get(0).getUuid());
                if(characteristics.size() == 0) return;

                BluetoothGattCharacteristic characteristic = characteristics.get(0);
                gatt.setCharacteristicNotification(characteristic, true);

                BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_UUID);
                if(descriptor != null) {
                    descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
                    gatt.writeDescriptor(descriptor);
                }
            }


            public void writeCMD(BluetoothGatt gatt){
                Log.d("LOL444", "writeCMD: CMD");

                BluetoothGattCharacteristic characteristic = gatt.getService(WEIGHT_MEASUREMENT_SERVICE)
                        .getCharacteristic(CMD_MEASUREMENT_CHARACTERISTIC);
                
                byte[] magicnumber = {0x02,0x7b,0x7b, (byte) 0xf6,0x0d};
                characteristic.setValue(magicnumber);

            }


        };

I also made sure that the respective write commands are executed one after the other (I think). Thank you in advance and best regards



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source