How to set Service data in windows BLE peripheral with gatt servers

Windy-Cao 1 Reputation point
2022-08-03T14:45:29.64+00:00

I am currently developing a BLE peripheral on the Windows platform, I want to advertise some data(including 16 bytes UUID, device name, and some custom data), but I did not find any windows API to set data into Service Data of Advertisement, can you please tell me how to set data into Service Data, and advertise them. I'll appreciate it if you tell me the exact windows API or give some code examples. Thanks

Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Roy Li - MSFT 31,526 Reputation points Microsoft Vendor
    2022-08-05T06:49:28.757+00:00

    Hello,

    Welcome to Microsoft Q&A!

    First of all, based on the document - Bluetooth GATT Server, it is mentioned that - When a service is both Discoverable and Connectable, the system will add the Service Uuid to the advertisement packet. There are only 31 bytes in the Advertisement packet and a 128-bit UUID takes up 16 of them!. This is the default behavior. So what you are getting is expected.

    Now with Bluetooth 5.0, the max payload for a single adv packet (AdvData) expands to 0-254 bytes. If you want to send more data than 31 bytes from a GATT server when communicating with a GATT client, you have to check if the system supports BLE 5.0. Be clear that this is not an advertisement, sending advertisements uses a different API.

    Use the following API to check if the feature is supported on the system the App is running on:

    BluetoothAdapter.IsExtendedAdvertisingSupported Property (Windows.Devices.Bluetooth) - Windows UWP applications | Microsoft Learn.

    If the system supported extended advertising, then you could send more data than 31 bytes.

    Besides, if you want to send an advertisement using the BluetoothLEAdvertisementPublisher class . You have an extra step to enable it using this API: BluetoothLEAdvertisementPublisher.UseExtendedAdvertisement Property (Windows.Devices.Bluetooth.Advertisement) - Windows UWP applications | Microsoft Learn

    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.

    0 comments No comments