Bluetooth Extended Advertising limited to only 112 bytes

Howdy!

I am working with the nRF52840 and currently getting a weird error. Whenever I set the data for the BT_DATA function as anything greater than 110, the system stops advertising. I have tried various different max array sizes from 114 up to 1600. No matter what I choose of these, it still stops transmitting all together. This is even after setting the max value accepted in the prj.conf file as 251. I am providing a snippet of my code below. Any help would be much appreciated.

#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/gap.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/uuid.h>
#define COMPANY_ID_LEN 2
#define SENSOR_DATA_LEN 10
#define SPI_DATA_LEN 98

struct adv_mfg_data {
	uint16_t company_code[COMPANY_ID_LEN];    /* Company Identifier Code. */
	uint8_t custom_data[SENSOR_DATA_LEN];  /* Custom 10-element array */
};
uint8_t The_Vocal_data[SPI_DATA_LEN] = {0};  /* Vocalization 98-element array */

struct adv_mfg_data adv_data_pre = {
	.company_code = COMPANY_ID_CODE,
	.custom_data = {0},
};

struct bt_le_ext_adv *adv;
static struct bt_le_adv_param adv_param = {
	.options = BT_LE_ADV_OPT_USE_IDENTITY | BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_EXT_ADV,
	.interval_min = BT_GAP_ADV_FAST_INT_MIN_1, // Every 1 to 3 seconds
	.interval_max = BT_GAP_ADV_FAST_INT_MAX_1,
	.peer = NULL
};

struct bt_data adv_data[] = {
        //BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR),
        BT_DATA(BT_DATA_MANUFACTURER_DATA, "just zeroes", 6),
};
uint8_t manufacturer_data[112];
static void set_advertising_data(struct adv_mfg_data *adv_data_set) {
        uint8_t n_manufacturer_data = sizeof(adv_data_set->company_code) + sizeof(adv_data_set->custom_data) + sizeof(The_Vocal_data);
        memcpy(manufacturer_data, adv_data_set->company_code, sizeof(adv_data_set->company_code));
        memcpy(manufacturer_data + sizeof(adv_data_set->company_code), adv_data_set->custom_data, sizeof(adv_data_set->custom_data));
        memcpy(manufacturer_data + sizeof(adv_data_set->company_code) + sizeof(adv_data_set->custom_data), The_Vocal_data, sizeof(The_Vocal_data));
 
       struct bt_data adv_data_new[] = {
		BT_DATA(BT_DATA_MANUFACTURER_DATA, manufacturer_data, n_manufacturer_data),
	};
	memcpy(&adv_data,&adv_data_new, sizeof(struct bt_data));
	printk("Created adv: %p\n", adv);
        printk("Size of bt_data struct: %d\n",sizeof(struct bt_data));
        printk("Number of elements in adv_data set: %d\n", sizeof(adv_data) / sizeof(adv_data[0]));

	int err = bt_le_ext_adv_set_data(adv, adv_data, ARRAY_SIZE(adv_data), NULL, 0);
	if (err) {
		printk("Failed to set advertising data (err %d)\n", err);
	} else {
		printk("Advertising data set successfully\n");
	}
}

Parents
  • Howdy!

    Was the CONFIG_BT_CTLR_ADV_DATA_LEN_MAX setting the one you tried increasing in your project configuration? This is typically the only setting you need to modify to support longer advertisement packets. It is usually set to a lower value by default to minimize RAM usage. I also verified this with the peripheral_hr_coded sample by applying these code and configuration changes:

    diff --git a/prj.conf b/prj.conf
    index 0832502..149a9a1 100644
    --- a/prj.conf
    +++ b/prj.conf
    @@ -18,3 +18,5 @@ CONFIG_BT_CTLR_ADV_EXT=y
     
     CONFIG_BT_EXT_ADV=y
     CONFIG_BT_USER_PHY_UPDATE=y
    +
    +CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=251
    diff --git a/src/main.c b/src/main.c
    index a69cd76..8320780 100644
    --- a/src/main.c
    +++ b/src/main.c
    @@ -40,12 +40,13 @@ static K_WORK_DELAYABLE_DEFINE(notify_work, notify_work_handler);
     
     static struct bt_le_ext_adv *adv;
     
    -static const struct bt_data ad[] = {
    +static struct bt_data ad[] = {
     	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
     	BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_HRS_VAL),
     					  BT_UUID_16_ENCODE(BT_UUID_BAS_VAL),
     					  BT_UUID_16_ENCODE(BT_UUID_DIS_VAL)),
    -	BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN)
    +	BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
    +	BT_DATA(BT_DATA_MANUFACTURER_DATA, "just zeroes", 6),
     };
     
     
    @@ -95,8 +96,7 @@ static int create_advertising_coded(void)
     	int err;
     	struct bt_le_adv_param param =
     		BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_CONNECTABLE |
    -				     BT_LE_ADV_OPT_EXT_ADV |
    -				     BT_LE_ADV_OPT_CODED,
    +				     BT_LE_ADV_OPT_EXT_ADV,
     				     BT_GAP_ADV_FAST_INT_MIN_2,
     				     BT_GAP_ADV_FAST_INT_MAX_2,
     				     NULL);
    @@ -107,6 +107,13 @@ static int create_advertising_coded(void)
     		return err;
     	}
     
    +	static uint8_t mfg_data[120];
    +
    +	memset(mfg_data, 0xAA, sizeof(mfg_data));
    +
    +	ad[3].data = mfg_data;
    +	ad[3].data_len = sizeof(mfg_data);
    +	
     	printk("Created adv: %p\n", adv);
     
     	err = bt_le_ext_adv_set_data(adv, ad, ARRAY_SIZE(ad), NULL, 0);

    Best regards.

    Vidar

Reply
  • Howdy!

    Was the CONFIG_BT_CTLR_ADV_DATA_LEN_MAX setting the one you tried increasing in your project configuration? This is typically the only setting you need to modify to support longer advertisement packets. It is usually set to a lower value by default to minimize RAM usage. I also verified this with the peripheral_hr_coded sample by applying these code and configuration changes:

    diff --git a/prj.conf b/prj.conf
    index 0832502..149a9a1 100644
    --- a/prj.conf
    +++ b/prj.conf
    @@ -18,3 +18,5 @@ CONFIG_BT_CTLR_ADV_EXT=y
     
     CONFIG_BT_EXT_ADV=y
     CONFIG_BT_USER_PHY_UPDATE=y
    +
    +CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=251
    diff --git a/src/main.c b/src/main.c
    index a69cd76..8320780 100644
    --- a/src/main.c
    +++ b/src/main.c
    @@ -40,12 +40,13 @@ static K_WORK_DELAYABLE_DEFINE(notify_work, notify_work_handler);
     
     static struct bt_le_ext_adv *adv;
     
    -static const struct bt_data ad[] = {
    +static struct bt_data ad[] = {
     	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
     	BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_HRS_VAL),
     					  BT_UUID_16_ENCODE(BT_UUID_BAS_VAL),
     					  BT_UUID_16_ENCODE(BT_UUID_DIS_VAL)),
    -	BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN)
    +	BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
    +	BT_DATA(BT_DATA_MANUFACTURER_DATA, "just zeroes", 6),
     };
     
     
    @@ -95,8 +96,7 @@ static int create_advertising_coded(void)
     	int err;
     	struct bt_le_adv_param param =
     		BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_CONNECTABLE |
    -				     BT_LE_ADV_OPT_EXT_ADV |
    -				     BT_LE_ADV_OPT_CODED,
    +				     BT_LE_ADV_OPT_EXT_ADV,
     				     BT_GAP_ADV_FAST_INT_MIN_2,
     				     BT_GAP_ADV_FAST_INT_MAX_2,
     				     NULL);
    @@ -107,6 +107,13 @@ static int create_advertising_coded(void)
     		return err;
     	}
     
    +	static uint8_t mfg_data[120];
    +
    +	memset(mfg_data, 0xAA, sizeof(mfg_data));
    +
    +	ad[3].data = mfg_data;
    +	ad[3].data_len = sizeof(mfg_data);
    +	
     	printk("Created adv: %p\n", adv);
     
     	err = bt_le_ext_adv_set_data(adv, ad, ARRAY_SIZE(ad), NULL, 0);

    Best regards.

    Vidar

Children
No Data
Related