...In a Maui project, I'm using the Shiny BLE library and everything works fine except I can't find how to be sent notifications from the device - - none of the documentation samples are correct.
Here is the code used to retrieve characteristic data after the device connection is complete:
public async Task ReadDataAsync(IPeripheral peripheral, string suuid, string cuuid)
{
// Discover the characteristic
var c = await peripheral.GetCharacteristic(suuid, cuuid);
if (c == null) { return; }
if (c.CanRead())
{
var reader = peripheral.ReadCharacteristic(c.Service.Uuid, c.Uuid)
.Subscribe(scanResult =>
{
// process scanResult.data
},
ex => Console.WriteLine("Error reading characteristic: {ex.Message}")
);
}
else if (c.CanNotifyOrIndicate())
{
c
. // How to tell device we want notifications? No examples I've found are syntactically correct!
.Subscribe(
result =>
{
// process result.Data
},
ex => Console.WriteLine("Error subscribing to notifications: {ex.Message}")
);
// turn of notifications
}
How do I tell the device we want to receive notifications when the state changes?