Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

How to implement 1650byte periodic advertise?

Hi.

I wanna test 1650 byte periodic advertise.

I have reffered the following QAs.
https://devzone.nordicsemi.com/f/nordic-q-a/88164/advertising-1650-bytes-of-host-advertising-data-in-an-auxiliary-segment-using-advertising-extensions
https://devzone.nordicsemi.com/f/nordic-q-a/92514/updating-data-in-chained-periodic-advertising-1-650-bytes

My environments and codes are the following.

[Enviroments]
NCS SDK2.5.1
nRF52840-DK
Windows10 64bit
Sniffer: ellisys BEX400

[Codes]
It is based on "periodic_adv".
main.c

/*
 * Copyright (c) 2020 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr/bluetooth/bluetooth.h>

#define ADV_SIZE 200
static uint8_t mfg_data[ADV_SIZE] = { 0 };
static const struct bt_data ad[] = {
	BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, ADV_SIZE),
	BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, ADV_SIZE),
	BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, ADV_SIZE),
	BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, ADV_SIZE),
};

//NOTE - 
/*
struct bt_data {
	uint8_t type;
	uint8_t data_len;		//! cause of this type, ADV_SIZE is 255 at max.
	const uint8_t *data;
};
*/




int main(void)
{
	struct bt_le_ext_adv *adv;
	int err;

	printk("Starting Periodic Advertising Demo\n");

	/* Initialize the Bluetooth Subsystem */
	err = bt_enable(NULL);
	if (err) {
		printk("Bluetooth init failed (err %d)\n", err);
		return 0;
	}

	/* Create a non-connectable non-scannable advertising set */
	err = bt_le_ext_adv_create(BT_LE_EXT_ADV_NCONN_NAME, NULL, &adv);
	if (err) {
		printk("Failed to create advertising set (err %d)\n", err);
		return 0;
	}

	/* Set periodic advertising parameters */
	err = bt_le_per_adv_set_param(adv, BT_LE_PER_ADV_DEFAULT);
	if (err) {
		printk("Failed to set periodic advertising parameters"
		       " (err %d)\n", err);
		return 0;
	}

	/* Enable Periodic Advertising */
	err = bt_le_per_adv_start(adv);
	if (err) {
		printk("Failed to enable periodic advertising (err %d)\n", err);
		return 0;
	}

	printk("Start Extended Advertising...");
	err = bt_le_ext_adv_start(adv, BT_LE_EXT_ADV_START_DEFAULT);
	if (err) {
		printk("Failed to start extended advertising "
			"(err %d)\n", err);
		return 0;
	}
	printk("done.\n");


	while (true) {

		k_sleep(K_SECONDS(10));

		mfg_data[0] = 0xFF;
		mfg_data[1] = 0xFF;
		mfg_data[2] = 0x00;
		for(int j=3; j<ADV_SIZE; j++){
			mfg_data[j]=j;
		}

		printk("Set Periodic Advertising Data...");
		err = bt_le_per_adv_set_data(adv, ad, ARRAY_SIZE(ad));
		if (err) {
			printk("Failed (err %d)\n", err);
			return 0;
		}
		printk("done.\n");

	}
	return 0;
}

prj.conf

CONFIG_BT=y
CONFIG_BT_EXT_ADV=y
CONFIG_BT_PER_ADV=y
CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_DEVICE_NAME="Test Periodic Advertising"

CONFIG_LOG=y
CONFIG_BT_CTLR_ADV_EXT=y
CONFIG_BT_CTLR_ADV_PERIODIC=y
CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=1650



When this code is builded and debuged, AUX_SYNC_IND packet is just 1byte (0x00).
In the case that the data size is 200 like the bellow,  AUX_SYNC_IND packet is 203byte and the data looks correct.

#define ADV_SIZE 200
static uint8_t mfg_data[ADV_SIZE] = { 0 };
static const struct bt_data ad[] = {
	BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, ADV_SIZE),
	// BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, ADV_SIZE),
	// BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, ADV_SIZE),
	// BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, ADV_SIZE),
};

To chain the data exceeding 255byte, how should I do?
Could you tell me any mistakes in the codes?

Thank you.

Parents Reply Children
  • Hi.

    Thank you for your answer.

    I'm sorry, but I missed the zip file based on HR sample in the link you showed.
    I found AUX_CHAIN_INT packets in the sample.

    Additionaly, I found the chain advertises also in my sample based on "periodic_adv". However, some changes is needed.

    1. prepare "ad[]" of 800bytes as shown in the link.
    2. comment out all "bt_le_per_***" functions.
    3. bt_le_ext_adv_start() is put before while loop(, that is maybe before bt_le_ext_adv_start() ).
    4. add "CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=1650" to prj.conf file.
    5. add to "BT_LE_ADV_OPT_USE_IDENTITY" to the first parameter of "bt_le_ext_adv_create()".

    Anyway, my issue is resolved.
    I appreciate your help.

    Thank you.

Related