bluetooth_low_energy icon indicating copy to clipboard operation
bluetooth_low_energy copied to clipboard

PeripheralManager.characteristicRead and GattCharacteristicReadEventArgs

Open ekuleshov opened this issue 6 months ago • 18 comments

The PeripheralManager.characteristicRead stream spawns GattCharacteristicReadEventArgs events when connected "central" device is sending a read request to a certain characteristic.

But I can't figure out how to return an app-specific data in response to that read request.

There is PeripheralManager.writeCharacteristic() method which sends an updated characteristic value to one or more subscribed centrals, using a notification or indication. But that requires additional orchestration, e.g. have central subscribe for notifications and use some command from central (e.g. a write event) to initiate transmission.

It looks like the value is set in the GattCharacteristic at the time GattService.characteristics are created and then gatt service is registered using PeripheralManager.instance.addService(), but it is unclear how to change value in those chars because the GattCharacteristic has no setter for value, but even then it is too late to update value in those chars at the time characteristicRead event is triggered.

Perhaps you could add a value setter to the GattCharacteristic or better allow to specify a callback there that would allow to pull the up to date value from any custom source.

ekuleshov avatar Jan 27 '24 16:01 ekuleshov