WindyCao-6167 avatar image
0 Votes"
WindyCao-6167 asked RoyLi-MSFT answered

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

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

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

First of all, sending Advertisements and publishing GATT services are two different features. These two features can be used at the same time. Please be more specific about what you are trying to do. Do you want to publish a GATT server first, then send subscriptions to the clients? Or do you just want to send Advertisements(without creating a GATT service)

0 Votes 0 ·

Thanks for your reply, I am using Bluetooth::GenericAttributeProfile::GattServiceProvider API to start advertising, I want to broadcast more than 31 bytes of data, and then put the extra data in ServiceData, but through packet capture and Demo testing, it is found that this part of the data in ServiceData has not been broadcasted. Is there any way to broadcast this part of the data? Looking forward to your response, thank you!

0 Votes 0 ·

1 Answer

RoyLi-MSFT avatar image
0 Votes"
RoyLi-MSFT answered


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 Docs.

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 Docs

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.