This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Why am I getting a length error (0x09) with this advertisement

Here is the advertisement and scan response:

Advertisement 02, 01, 06, 12, 09, 47, 68, 73, 47, 6C, 75, 63, 6F, 73, 65, 4D, 6F, 6E, 69, 74, 6F, 72, 03, 03, 90, F9, 05, 16, 90, F9, 11, 10
Scan Response 12, 09, 47, 68, 73, 47, 6C, 75, 63, 6F, 73, 65, 4D, 6F, 6E, 69, 74, 6F, 72

Failed to set advertisement data. Error code: 0x09

Which gives me the above error. However this advertisement does not

Advertisement 02, 01, 06, 11, 09, 47, 68, 73, 42, 6C, 6F, 6F, 64, 50, 72, 65, 73, 73, 75, 72, 65, 03, 03, 90, F9, 05, 16, 90, F9, 07, 10
Scan Response 11, 09, 47, 68, 73, 42, 6C, 6F, 6F, 64, 50, 72, 65, 73, 73, 75, 72, 65

neither does this:

Advertisement 02, 01, 06, 0F, 09, 47, 68, 73, 54, 68, 65, 72, 6D, 6F, 6D, 65, 74, 65, 72, 03, 03, 90, F9, 05, 16, 90, F9, 08, 10
Scan Response 0F, 09, 47, 68, 73, 54, 68, 65, 72, 6D, 6F, 6D, 65, 74, 65, 72

I do not see any error in any of the length fields.

The same code is used to generate both sets. The only difference between the two is the name (09) field.

  • The max length is 31 bytes, so 32 bytes gives an error as you see; worth reading up on how to handle this. I have these notes:

    // 0..31 byte long payload in Bluetooth Core specification is AdvData
    // Advertising data consists of one or more Advertising Data (AD) elements. Each element is formatted as follows:
    //  1st byte: length of the element (excluding the length byte itself)
    //  2nd byte: AD type specifies what data is included in the element
    //  AD data one or more bytes - the meaning is defined by AD type
    // The possible AD type values are listed in the Bluetooth SIG website:
    //  https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile
    // Some common data types:
    //  0x01 flags
    //  0x03 Complete List of 16-bit Service Class UUIDs
    //  0x09 Complete Local Name
    //  0x08 Shortened Local Name
    //  0xFF reserverd for proprietary data

  • Oh bummer! Never thought of that simple thing. I was looking for some mess up in my code in the generation of the individual lengths. Now why do I have the name in both places? First I want a scan response. But I think there was something about being forced to have the name in the advertisement or I would get an error from Softdevice. I will need to check that again.

    Thanks for the heads up.

Related