Hello,
I would like to use the BLE5 Advertising Extension to be able to transmit more data during advertisements.
The extended advertisement works but, on the other hand, I cannot update the data sent in the advertisement: the function "bt_le_adv_update_data(...)" returns me the error -EINVAL because "adv" is NULL...
Do you know how to fix this problem?
Here is a summary of my code:
//Defines: #define DEFAULT_DEVICE_NAME CONFIG_BT_DEVICE_NAME #define DEVICE_NAME_LEN (sizeof(DEFAULT_DEVICE_NAME) - 1) #define MY_BT_GAP_ADV_FAST_INT_MIN 0x0280 /* 400 ms */ #define MY_BT_GAP_ADV_FAST_INT_MAX 0x03c0 /* 600 ms */ #define DEFAULT_ADV_IDX 0 //Variables: char advertising_name[32] = {DEFAULT_DEVICE_NAME}; struct ble_advdata_manuf_data_t { uint16_t company_identifier; uint8_t manuf_data[9]; }; struct ble_advdata_manuf_data_t manuf_data = {.company_identifier = IMI_CONPANY_ID}; struct bt_data default_ad[] = { //Data in advertisements paquets BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), BT_DATA(BT_DATA_NAME_COMPLETE, advertising_name, (sizeof(advertising_name) - 1)),//BT_DATA(BT_DATA_NAME_COMPLETE, DEFAULT_DEVICE_NAME, DEVICE_NAME_LEN), BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_IMI_US_VAL), BT_DATA(BT_DATA_MANUFACTURER_DATA, &manuf_data, sizeof(manuf_data)), }; static const struct bt_le_adv_param *adv_param = BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_EXT_ADV, MY_BT_GAP_ADV_FAST_INT_MIN, MY_BT_GAP_ADV_FAST_INT_MAX, NULL); static struct bt_le_ext_adv *ext_adv[CONFIG_BT_EXT_ADV_MAX_ADV_SET];//CONFIG_BT_EXT_ADV_MAX_ADV_SET = 1 //Functions: void advertise_init() { ... ret = bt_enable(NULL); if (ret) { LOG_ERR("Bluetooth initialization failed (error: %d)", ret); goto end; } ret = bt_set_name(CONFIG_BT_DEVICE_NAME); if (ret) { LOG_ERR("Failed to set device name (err %d)", ret); return ret; } ret = advertising_set_create(&ext_adv[DEFAULT_ADV_IDX], adv_param, default_ad, ARRAY_SIZE(default_ad), NULL, 0); if(ret!=0) { error = SDK_ERROR | (ret*(-1)); LOG_ERR("Failed to start BLE advertising (error: %d)", ret); return error; } LOG_INF("BLE enabled!"); }
When I want to update my advertised data, I do:
... ret = bt_set_name(p_advertising_data->cName);//Here the name shoud change for the test ret = bt_le_adv_update_data(default_ad, ARRAY_SIZE(default_ad), NULL, 0);
I'm using the nRF Connect SDK V2.5.0.
Thank you