Reputation: 4292
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
Reputation: 10259
I think this is expected.
Because onCharacteristicWrite
only indicates, that your write operation was successful or not.
A BluetoothGattCharacteristic
can hold only one value, which is the last one send or received.
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