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

advertising packets include gatt attribute data

Hi:

I want to include the Characteristic value in the advertising packet,for example the real time battery level,thus there is no need to  establish a connection between a central and a
peripheral,is it impossible?(the chip is nrf52832,sdk version nRF5_SDK_17.0.2_d674dde)

Currently I get the following clues:

Table 4-7. Service Data AD Type

Field Length in bytes Description
UUID 2, 4, or 16 The actual UUID identifying the data
The data associated with the service identified by the UUID
Service Data Variable

Table 4-6. Characteristic properties

Property Location Description
Broadcast Properties If set, allows this characteristic value to be placed in advertising packets, using the Service
Data AD Type (see
“GATT Attribute Data in Advertising Packets”)

According the two clues above ,enable the characteristic broadcast property and config the Service Data AD Type may achieve that goal,but the result is that the battery level does not appear in the advertising packet,is there anything wrong?

part of service data config code:

static ble_advdata_service_data_t adv;
static ble_advdata_manuf_data_t mna_data;
static uint8_t mdata[5]={9,5};

/**@brief Function for initializing the Advertising functionality.
*/
static void advertising_init(void)
{
ret_code_t err_code;
ble_advertising_init_t init;

adv.service_uuid=BLE_UUID_BATTERY_LEVEL_CHAR;//BLE_UUID_BATTERY_LEVEL_CHAR;//BLE_UUID_BATTERY_SERVICE;
adv.data.size=1;
adv.data.p_data=&m_bas.battery_level_last;

init.advdata.p_service_data_array=&adv;
init.advdata.service_data_count=1;

part of characteristic broadcast property code:

static ret_code_t battery_level_char_add(ble_bas_t * p_bas, const ble_bas_init_t * p_bas_init)
{
ret_code_t err_code;
ble_add_char_params_t add_char_params;
ble_add_descr_params_t add_descr_params;
uint8_t initial_battery_level;
uint8_t init_len;
uint8_t encoded_report_ref[BLE_SRV_ENCODED_REPORT_REF_LEN];

// Add battery level characteristic
initial_battery_level = p_bas_init->initial_batt_level;

memset(&add_char_params, 0, sizeof(add_char_params));
add_char_params.uuid = BLE_UUID_BATTERY_LEVEL_CHAR;
add_char_params.max_len = sizeof(uint8_t);
add_char_params.init_len = sizeof(uint8_t);
add_char_params.p_init_value = &initial_battery_level;
add_char_params.char_props.notify = p_bas->is_notification_supported;
add_char_params.char_props.read = 1;
add_char_params.char_props.broadcast = 1;
add_char_params.cccd_write_access = p_bas_init->bl_cccd_wr_sec;
add_char_params.read_access = p_bas_init->bl_rd_sec;

Has anyone used this feature? Please provide me with some help, thanks!

Related