Bluetooth Low Energy Multiply times ValueChanged notification

Vladi 25 Reputation points
2023-03-19T13:20:12.9666667+00:00

The GattCharacteristic.ValueChanged event handler is triggered multiple times. The same problem with "Windows-universal-samples" in "BluetoothLE" example.

BluetoothLE" example...

For example when I "connect to device"--> Select Service --> Select Characteristic --> (click on) "Subscribe for notification" first time its works OK.

Then I disconnect from device and make new connect "connect to device"--> Select Service --> Select Characteristic --> (click on) "Subscribe for notification" the ValueChanged is Triggered twice an any single notification from BLE device,

Also any click "Unsubscribe / Subscribe to value changes" in demo add one more times to ValueChanged evens 3,4,5,6 times per each notification.

The main my problem when I connect /disconnect form device (when my code dispose BluetoothLEDevice instance).

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,825 questions
Universal Windows Platform (UWP)
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,228 questions
{count} votes

Accepted answer
  1. Roy Li - MSFT 31,766 Reputation points Microsoft Vendor
    2023-03-30T02:05:43.68+00:00

    Hello,

    Welcome to Microsoft Q&A!

    I've checked the code in the Bluetooth sample that you've mentioned. That's an unexpected behavior and the code you found is the reason causing the behavior.

    I've reported this via our channel that there is a mistake in the Bluetooth sample for subscription. Please also submit an issue in the Issues of the GitHub: https://github.com/microsoft/Windows-universal-samples/issues

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Vladi 25 Reputation points
    2023-03-28T11:55:11.51+00:00

    Hi. I found the bug in the "Windows-universal-samples" "BluetoothLE" sample...

    In "ValueChangedSubscribeToggle_Click()" I just comment the "subscribedForNotifications = false;" line. It placed before 'RemoveValueChangedHandler()' and RemoveValueChangedHandler do nothing when subscribedForNotifications is false...

    Best regards.

    Vladislav.

    1 person found this answer helpful.