Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to be able to register for notification from characteristics that is only INDICATE #847

Closed
CodeMusher opened this issue May 6, 2024 · 9 comments · Fixed by #858
Closed

Comments

@CodeMusher
Copy link

To help us fix your issue, please provide the information in the below template. If something causes a crash, provide as much information as you can gather.
Just imagine: we do not know what you are doing!

Note: There is often little we can do without a minimal reproducible sample of the issue, so please provide that in a standalone git repository and link it here.

Steps to reproduce

  1. Try to use a peripheral with a characteristic with only INDICATE

Expected behavior

Registration for updates should succeed

Actual behavior

Registration is not performed. The Windows implementation of the StartUpdatesNativeAsync only register in case of Notify.
It could be solved this way
GattWriteResult result;
if (NativeCharacteristic.CharacteristicProperties.HasFlag(GattCharacteristicProperties.Indicate))
result = await NativeCharacteristic.WriteClientCharacteristicConfigurationDescriptorWithResultAsync(GattClientCharacteristicConfigurationDescriptorValue.Indicate);
else
result = await NativeCharacteristic.WriteClientCharacteristicConfigurationDescriptorWithResultAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);

Crashlog

If something causes an exception paste full stack trace + Exception here

Configuration

Version of the Plugin: e.g. 1.0.0 / 1.0.1-alpha3
3.1.0-rc.1

Platform: e.g. iOS 10.1 / Android 4.4 / ... (including version!!! e.g. Android 5.1 / i0S 10)
UWP/Windows 10

Device: e.g. HTC Sensation /i Phone 7 ...

@smsissuechecker
Copy link

Hi @CodeMusher,

I'm the friendly issue checker.
Thanks for using the issue template 🌟
I appreciate it very much. I'm sure, the maintainers of this repository will answer, soon.

@janusw
Copy link
Member

janusw commented May 19, 2024

Actual behavior

Registration is not performed. The Windows implementation of the StartUpdatesNativeAsync only register in case of Notify. It could be solved this way GattWriteResult result; if (NativeCharacteristic.CharacteristicProperties.HasFlag(GattCharacteristicProperties.Indicate)) result = await NativeCharacteristic.WriteClientCharacteristicConfigurationDescriptorWithResultAsync(GattClientCharacteristicConfigurationDescriptorValue.Indicate); else result = await NativeCharacteristic.WriteClientCharacteristicConfigurationDescriptorWithResultAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);

This fix is supposed to go into Characteristic.StartUpdatesNativeAsync, right? It currently looks like this:

protected override async Task StartUpdatesNativeAsync(CancellationToken cancellationToken = default)
{
NativeCharacteristic.ValueChanged -= OnCharacteristicValueChanged;
NativeCharacteristic.ValueChanged += OnCharacteristicValueChanged;
var result = await NativeCharacteristic.WriteClientCharacteristicConfigurationDescriptorWithResultAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);
result.ThrowIfError();
}

@CodeMusher Can you open a PR for it?

@AskBojesen
Copy link
Contributor

I do not understand the issue. In our project we have a device with a lot of characteristics with only INDICATE.
and even one where the device decides if the characteristic should be send as NOTIFY or INDICATE.
And that works for iOS, Android and Windows

Remember:

  • NOTIFY: Unacknowledged
  • INDICATE: Acknowledged

@CodeMusher
Copy link
Author

@janusw I can try. What is the correct procedure?

@AskBojesen
Copy link
Contributor

But It could be related to how the device handle the requests.

I see the same in the current implementation for Windows, which is also what @janusw points out.
@CodeMusher : Should I make a PR you can test with the solution @janusw suggests?

var result = await NativeCharacteristic.WriteClientCharacteristicConfigurationDescriptorWithResultAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);

@CodeMusher
Copy link
Author

@AskBojesen Do you refer to my suggestion in the original issue?
That works for me but my peripheral has a characteristic with only INDICATE. I'm not sure what happens in case of both INDICATE and NOTIFY. Is one registration enough or do you need to register for both INDICATE and NOTIFY? I feel my knowledge ending here.

@AskBojesen
Copy link
Contributor

I actually see now, that our device is lying in the characteristic properties - reporting NOTIFY, but it is indicate.

@CodeMusher
Copy link
Author

Ok, so then you can understand my issue?

@AskBojesen
Copy link
Contributor

Ok, so then you can understand my issue?

Yes I can imagine there could be an issue - I cannot reproduce.
I have created this PR: #858

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants