cancel
Showing results for 
Search instead for 
Did you mean: 

How to change the advertising data length?

JDamm.1
Associate

Hi,

I am using the STM32WB55 Nucleo Board and am trying to characterize the current consumption of the board using the BLE HeartRate example. For this, I want to send 20 bytes in the advertisement data packet. How do I set the length of the advertisement data? Or how should I go about changing the advertisement data length? Any insights would be appreciated.

Thanks,

Josh

1 ACCEPTED SOLUTION

Accepted Solutions
Remi QUINTIN
ST Employee

Please have a look at the attached slide detailing the fields of an advertising packet.

According to the BLE standard, there are 31 bytes dedicated to advanced data (AD) to be inserted in the payload of an advertising packet.

Each Advanced Data (AD) has 3 fields: Length, AD_TYPE and the data itself.

You can insert any advanced data you see appropriate to add in the payload but be sure the total sum of all ADs does not exceed 31 bytes.

If you want to send 20 bytes, you just have to consider all the AD inserted in the advertising packet, knowing there are a few mandatory advanced data that always have to be included (see the list further below). You can guess those fields considering the input parameters of the ACI_GAP_SET_DISCOVERABLE function when it is called on the advertising server side.

Payload of advertising packets is built with different AD types: AD_TYPE_FLAGS, AD_TYPE_COMPLETE_LOCAL_NAME, AD_TYPE_TX_POWER_LEVEL etc.. (defined in ble_def.h). Note that AD_TYPE_FLAGS is mandatory to be discoverable.

If AD_TYPE_FLAGS is removed from advertising indication, you will see the advertising packet in the air, but the event is filtered at GAP level when aci_gap_start_general_discovery_proc is used on the scanning client side (it's the standard).

To insert advanced data in the advertising payload, you can use ACI_GAP_UPDATE_ADV_DATA function. Note updated AD replaces AD if of the same AD_TYPE. Otherwise new AD is added to already existing AD.

In pre-existing AD,  AD_TYPE_FLAGS, AD_TYPE_TX_POWER_LEVEL and AD_TYPE_COMPLETE_LOCAL_NAME are always present in all advertising packets.

You can also delete an AD with the aci_gap_delete_ad_type function.

View solution in original post

4 REPLIES 4
Remi QUINTIN
ST Employee

Please have a look at the attached slide detailing the fields of an advertising packet.

According to the BLE standard, there are 31 bytes dedicated to advanced data (AD) to be inserted in the payload of an advertising packet.

Each Advanced Data (AD) has 3 fields: Length, AD_TYPE and the data itself.

You can insert any advanced data you see appropriate to add in the payload but be sure the total sum of all ADs does not exceed 31 bytes.

If you want to send 20 bytes, you just have to consider all the AD inserted in the advertising packet, knowing there are a few mandatory advanced data that always have to be included (see the list further below). You can guess those fields considering the input parameters of the ACI_GAP_SET_DISCOVERABLE function when it is called on the advertising server side.

Payload of advertising packets is built with different AD types: AD_TYPE_FLAGS, AD_TYPE_COMPLETE_LOCAL_NAME, AD_TYPE_TX_POWER_LEVEL etc.. (defined in ble_def.h). Note that AD_TYPE_FLAGS is mandatory to be discoverable.

If AD_TYPE_FLAGS is removed from advertising indication, you will see the advertising packet in the air, but the event is filtered at GAP level when aci_gap_start_general_discovery_proc is used on the scanning client side (it's the standard).

To insert advanced data in the advertising payload, you can use ACI_GAP_UPDATE_ADV_DATA function. Note updated AD replaces AD if of the same AD_TYPE. Otherwise new AD is added to already existing AD.

In pre-existing AD,  AD_TYPE_FLAGS, AD_TYPE_TX_POWER_LEVEL and AD_TYPE_COMPLETE_LOCAL_NAME are always present in all advertising packets.

You can also delete an AD with the aci_gap_delete_ad_type function.

@Remi QUINTIN​ great answer and diagram as well, thanks!

@JDamm.1​ you are lucky to get this much attention for such a basic question, and so quickly at that - you should mark this as answered.

Scott Löhr
Senior II

@JDamm.1​ on a side note, I use hci_le_set_advertising_data() to just all at once set the useful bytes of the advertisement packet to be exactly what is required (the ADV_DATA_FLAGS entry as @Remi QUINTIN​ mentions above) and the rest as my proprietary data field.

/**

 * @brief HCI_LE_SET_ADVERTISING_DATA

 * The LE_Set_Advertising_Data command is used to set the data used in

 * advertising packets that have a data field.

 * Only the significant part of the Advertising_Data is transmitted in the

 * advertising packets, as defined in [Vol 3] Part C, Section 11.,

 * (See Bluetooth Specification v.5.0, Vol. 2, Part E, 7.8.7)

 * 

 * @param Advertising_Data_Length The number of significant octets in the

 *    following data field

 * @param Advertising_Data 31 octets of data formatted as defined in [Vol 3]

 *    Part C, Section 11.

 * @return Value indicating success or error code.

 */

tBleStatus hci_le_set_advertising_data( uint8_t Advertising_Data_Length,

                    const uint8_t* Advertising_Data );

JDamm.1
Associate

Remi and Scott,

Thank you both for your information and detail. It is very helpful!