what is the max length for serviceData in Advertisement? (GattServiceProviderAdvertisingParameters)

frank zhang 121 Reputation points
2022-05-08T01:39:10.317+00:00

I want to send as much serviceData as possible in ble advertisement , but when I set it into ServiceData, if data length is more than 18bytes, it did not send out any serviceData, and noting wrong occured, I am puzzled.
I can not find any infomation from MircosoftDocs for max length for serviceData, is there any notice ?

code demo:

auto advParameters = ref new Bluetooth::GenericAttributeProfile::GattServiceProviderAdvertisingParameters();
advParameters->IsConnectable = true;
advParameters->IsDiscoverable = true;
auto writer = ref new Windows::Storage::Streams::DataWriter();
writer->WriteString("123456789012345678"); // success
//writer->WriteString("12345678901234567890"); // fail to send out servicedata, but noting wrong occured
advParameters->ServiceData = writer->DetachBuffer();

Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. Roy Li - MSFT 31,766 Reputation points Microsoft Vendor
    2022-05-09T02:59:34.563+00:00

    Hello,

    Welcome to Microsoft Q&A!

    Based on the document Gatt Server, there is a note for publishing service with a parameter that said: 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!

    So, if the service UUID is added, there are only 15 bytes left for the payload that you could use.

    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 additional answer

Sort by: Most helpful
  1. Lowell Liu 21 Reputation points
    2022-08-02T02:06:56.173+00:00

    Hi @frank zhang ,
    I set private data into ServiceData and advertise it(no matter the ServieData's length is over than 18bytes), but I can not parse it from the gatt client after received the advertisement.\
    Is there any parameter should be enabled?

    Could you share the way to use GattServiceProviderAdvertisingParameters's serviceData section to sent the private data to client and how to parse it from the gatt client?

    0 comments No comments