question

frankzhang-3676 avatar image
0 Votes"
frankzhang-3676 asked LowellLiu-5084 answered

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

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();

windows-uwp
· 1
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.

@frankzhang-3676 Does my reply make sense?

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

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.



· 6
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.

I know that not only advertisement can contain service data, but also scan response(also 31 bytes) can contain service data.
How to enable it , and put more service data into scan response as well? thanks.

0 Votes 0 ·
RoyLi-MSFT avatar image RoyLi-MSFT frankzhang-3676 ·

@frankzhang-3676 I've consulted the team about your requirement. According to the response I got, the scan response data is not directly controllable from the App. If you want more data payload, you could enable extended advertisement ( which is only available on systems that have radios that support this on both sending and receiving sides). The document is here: BluetoothLEAdvertisementPublisher.UseExtendedAdvertisement Property. This is a limitation of the technology unless extended advertisement is used.


0 Votes 0 ·

Thank you for your reply.
I know there is another api BluetoothLeAdvertisementPublisher can also start a advertisement publisher, but it can not set service uuid/data in advertisement, and can not publish ble service . It seems that advertisement from BluetoothLeAdvertisementPublisher can not be "connected" ?
So what I am puzzled is that why uwp api design two api to start advertisement ?( ServiceProvider->StartAdvertising and BluetoothLeAdvertisementPublisher->start()), should both of them start together ?

0 Votes 0 ·
Show more comments
LowellLiu-5084 avatar image
0 Votes"
LowellLiu-5084 answered

Hi @frankzhang-3676,
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?

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.