Android BLE BluetoothGattDescriptor пишет проблему с дескриптором

Я создаю приложение, которое взаимодействует с BLE. Мне нужно записать в BluetoothGattDescriptor значение int. Если я делаю это один раз, все работает отлично, но если я хочу написать в BluetoothGattDescriptor (в отдельных характеристиках) для каждой, я получаю значение false в методе mBluetoothGatt.writeDescriptor(descriptor), но только для второй характеристики, для в первый раз я получаю true. Я заметил, что если я устанавливаю задержку между ними примерно на 1,3 секунды, я получаю true в обеих попытках. Кто-то сталкивается с той же проблемой?

Вот отправляю регистрацию на уведомления с задержкой:

            Handler handler = new Handler();

    registeredToNotification(BLEGattAttributes.UUID_STERN_DATA__REMOTE_CONTROLS_SETTINGS_SERVICE,
            BLEGattAttributes.UUID_STERN_DATA_SETTINGS_REMOTES_CONTROL_READ_REQUEST_DELAY_IN, SettingsProperties.DELAY_IN_REGISTER_NOTIFICATION_REQUEST);

    handler.postDelayed(() -> registeredToNotification(BLEGattAttributes.UUID_STERN_DATA__REMOTE_CONTROLS_SETTINGS_SERVICE,
            BLEGattAttributes.UUID_STERN_DATA_SETTINGS_REMOTES_CONTROL_READ_REQUEST_DELAY_OUT, SettingsProperties.DELAY_OUT_REGISTER_NOTIFICATION_REQUEST), 1300);


    handler.postDelayed(() -> registeredToNotification(BLEGattAttributes.UUID_STERN_DATA__REMOTE_CONTROLS_SETTINGS_SERVICE,
            BLEGattAttributes.UUID_STERN_DATA_SETTINGS_REMOTES_CONTROL_READ_REQUEST_SHORT_WASH, SettingsProperties.SHORT_FLUSH_REGISTER_NOTIFICATION_REQUEST), 2600);


    handler.postDelayed(() -> registeredToNotification(BLEGattAttributes.UUID_STERN_DATA__REMOTE_CONTROLS_SETTINGS_SERVICE,
            BLEGattAttributes.UUID_STERN_DATA_SETTINGS_REMOTES_CONTROL_READ_REQUEST_LONG_WASH, SettingsProperties.LONG_FLUSH_REGISTER_NOTIFICATION_REQUEST), 3900);


    handler.postDelayed(() -> registeredToNotification(BLEGattAttributes.UUID_STERN_DATA__REMOTE_CONTROLS_SETTINGS_SERVICE,
            BLEGattAttributes.UUID_STERN_DATA_SETTINGS_REMOTES_CONTROL_READ_REQUEST_SECURITY_TIME, SettingsProperties.SECURITY_TIME_REGISTER_NOTIFICATION_REQUEST), 5200);

Вот журнал для этих команд:

 D/IDTEST: ............................setRegisterToNotification
 D/IDTEST: ......setRegisterToNotification ID = 53
 D/IDTEST: ............................Is descriptor registered? = true
 D/IDTEST: ............................Is Notification registered? = true
 D/IDTEST: ............................setRegisterToNotification
 D/IDTEST: ......setRegisterToNotification ID = 56
 D/IDTEST: ............................Is descriptor registered? = true
 D/IDTEST: ............................Is Notification registered? = true
 D/IDTEST: ............................setRegisterToNotification
 D/IDTEST: ......setRegisterToNotification ID = 63
 D/IDTEST: ............................Is descriptor registered? = true
 D/IDTEST: ............................Is Notification registered? = true
 D/IDTEST: ............................setRegisterToNotification
 D/IDTEST: ......setRegisterToNotification ID = 60
 D/IDTEST: ............................Is descriptor registered? = true
 D/IDTEST: ............................Is Notification registered? = true
 D/IDTEST: ............................setRegisterToNotification
 D/IDTEST: ......setRegisterToNotification ID = 66
 D/IDTEST: ............................Is descriptor registered? = true
 D/IDTEST: ............................Is Notification registered? = true

Метод setRegisterToNotification():

public void setRegisterToNotification(BLEDeviceConnectionManager.DataClass dataClass) {

        Log.d("IDTEST", "............................setRegisterToNotification");
        Log.d("IDTEST", "......setRegisterToNotification ID = " + dataClass.getRequestID());


        BluetoothGattCharacteristic characteristic = mBluetoothGatt.getService(dataClass.getServiceUUid()).getCharacteristic(dataClass.getCharacteristicsUUid());

        BluetoothGattDescriptor descriptor = characteristic.getDescriptors().get(0);

        if (descriptor != null) {
            descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
            descriptor.setValue(BleDataParser.getInstance().intTobyteArray(dataClass.getRequestID()));
            boolean isRegistered = mBluetoothGatt.writeDescriptor(descriptor);

            Log.d("IDTEST", "............................Is descriptor registered? = " + isRegistered);

        }

        boolean isRegistered = mBluetoothGatt.setCharacteristicNotification(characteristic, dataClass.isEnableNotification());

        Log.d("IDTEST", "............................Is Notification registered? = " + isRegistered);


    }

person Igor Fridman    schedule 06.09.2018    source источник


Ответы (1)


Вам нужно дождаться обратного вызова дескриптора, прежде чем писать снова. Это можно найти в BluetoothGattCallback#onDescriptorWrite используется при вызове connectGatt.

person zafrani    schedule 06.09.2018