Sagar Shah
Sagar Shah

Reputation: 4292

Android BLE : onCharacteristicChanged triggers before onCharacteristicWrite after writeCharacteristic

After successful ble connection, I am writing a Characteristic with DefaultWriteType.

Just after that onCharacteristicChanged triggers and after that onCharacteristicWrite triggers with same Characteristics UUID which was write but with values came as response in that Characteristics are same as response of onCharacteristicChanged.

Summary:

How onCharacteristicChanged triggers before onCharacteristicWrite ?

As I believe onCharacteristicWrite indicates that your write operation was successful or not. And onCharacteristicChanged responds/notify to the command for which we write to ble device.

Is this possible or is it going out of Ble cycle?

Upvotes: 0

Views: 941

Answers (1)

Christopher
Christopher

Reputation: 10259

I think this is expected.

  1. Because onCharacteristicWrite only indicates, that your write operation was successful or not.

  2. A BluetoothGattCharacteristic can hold only one value, which is the last one send or received.

  3. Both operations are using the same BluetoothGattCharacteristic instance.

So regarding to your described sequence, it is "normal" that you have the same value in both callbacks. Since the last operation, which manipulates the value in your characteristic was a BLE notification.

I think that was not the best idea, how it was implemented in the BLE stack. It would be better if the operations would not interfere each other and would be more idempotent/immutable.

Upvotes: 1

Related Questions