This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Advertisement packet too long

Hi,

I'm trying to define a new service, and on the GAP settings, I would like to advertise my service, but I get an error message: advertisement packet too long. What could be the reason? I only have 3 characteristics so far, but I would like to add many more. I did setup a new custom 128bit uuid for my service, and I use that for the base UUID for my characteristics. Maybe all the characteristics' UUIDs make it into the advertisement packet? Since I have a bunch of optionals, I would like to advertise that they are available or not. How can I make it work?

Thanks

  • I don't think you're supposed to broadcast all characteristics in a BLE packet nor try to fit them in. You should only broadcast what's really needed, depending on your packet type. It's probably only one UUID, maybe some major and minor values along with rssi is what you need to broadcast only, say if you're trying to broadcast an ibeacon packet. Characteristics and services are values that should be read/written after bonding to the peripheral, one at a time. (The limit was 20 bytes per write operation if I'm not wrong).

    You should check your packet length by accounting for the fields, what you put in it, see Ole's answer here. Your advertising packet cannot exceed 31 bytes. There is probably something wrong at the part you're building it or you're confused about what you should advertise. Please share that snippet so we can comment on it, instead of assuming.

    A BLE packet being broadcasted over the air is actually 47 bytes in total, but actual payload information you can put in it is limited by the packet's structure;

    • 1 byte preamble
    • 4 byte access address
    • 2-39 bytes advertising channel PDU
    • 2 bytes (size and type of payload)
    • 37 bytes payload

    37 = 6 bytes (mac address) + 31 bytes (data from your services, characteristics etc., not the service itself)

    • 3 bytes CRC

    In addition to checking how you build up your fields, you can also sniff your packets and see what's really in them. If one packet is not enough you can always use the scan response data for an additional 31 bytes.

  • Thanks, I changed my packet to only advertise the main service, and the rest can be discovered after connecting.

Related