none
GattServicesChanged triggered unexpectedly after connecting to BLE device RRS feed

  • Question

  • I wrote C++/WinRT code that

    1) connects to a BLE peripheral using BluetoothLEDevice::FromBluetoothAddressAsync

    2) registers a callback to listen for GattServicesChanged event if it ever occurs

    3) read or write to the characteristics of the peripheral.

    The code works fine on Windows 10 build 1803 and 1809 as in after successfully connected to the device, the GattServicesChanged event is only triggered(though multiple times) when the services have actually changed.

    Since we upgraded to build 1903, the GattServicesChanged event is triggered several times after connecting to the device for no reason. If I ignore those events, the peripheral can still be read from/written to as normal. However, this breaks my logic because I need to know when the services have indeed changed. The object parameter of the event callback is always null so that doesn't give me any information about why the GattServicesChanged event is fired at a given time.

    Any reason why this event gets triggered after connecting to a device in 1903? I don't see the doc mentioning any behavior change so is this a regression?


    Friday, October 4, 2019 9:10 PM

All replies

  • Hello hanabanana,

    I test official sample Bluetooth Low Energy sample ( C# ) with TI SensorTag device. 

    For me there are two reasons of receiving GattServicesChanged event when connecting:

    1. Connect the device not paired. 
    2. Call GetGattServicesAsync method with BluetoothCacheMode.Uncached.

    Either I pair the device before connecting or use BluetoothCacheMode.Cached it will not receiving these GattServicesChanged event when connecting.

    I don't test C++/WinRT version of this sample.

    Please check if it helps.

    BTW, this forum is for "Discuss general issues about developing applications for Windows."

    For C++/WinRT you can ask a question at UWP forum for more professional support.

    Best regards,

    Rita


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 7, 2019 2:52 AM
  • Hi Rita, 

    I've confirmed that FromBluetoothAddressAsync is not the problem. The GetGattServicesAsync however shows the following behavior on my Win10 build 1903,

    1. If device is paired, GetGattServicesAsync with Uncached mode does not trigger that event.

    2. If device is unpaired, GetGattServicesAsync with Uncached mode always triggers that event. Cached mode still triggers that event for 5 out of the 6 times I tried.

    Using Uncached mode on unpaired device was not triggering the event in previous builds, so why is this change introduced?

    Thanks.

    Monday, October 7, 2019 3:35 PM
  • Hello hanabanana,

    Since this issue is C++/WinRT related I'll move it to UWP forum for more professional support.

    Best regards,

    Rita


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, October 8, 2019 7:10 AM
  • Hi hanabanana,

    It seems that the services are not cached if the device is not paired and does not support persistent caching. Can you please use this guidence to provide some traces for us?

    Best Regards,

    Fay


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, October 9, 2019 9:39 AM
  • Hi Fay,

    Not sure what exactly you are looking for but I generated a BthTracing.etl file following the link you provided. How can I share it with you?

    Thanks.

    Wednesday, October 9, 2019 5:23 PM
  • Hi,

    Any platform which can download the file is OK(.e.g. OneDrive). Through these traces, I want to see if the services are cached when the device is not paired and does not support persistent caching.

    Best Regards,

    Fay


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, October 10, 2019 8:00 AM
  • You can find the file in below link,

    https://www.dropbox.com/s/h1qhwx03der461l/BthTracing.etl?dl=0

    Thanks.

    Thursday, October 10, 2019 7:14 PM
  • Hi,

    I have send the log to our engineers, they will check it as soon as possible. If there is any update, I will tell you.

    Best Regards,

    Fay


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, October 11, 2019 9:12 AM