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

"Failed enabling advertiser" when running mesh provisioner on nRF5340

I've tried to run a program which allows to run mesh provisioner, among with Direction Finding connectionless locator. 

I was using mesh provisioner example from Zephyr, and previously tested it on nRF52840 - it seemed to be working fine. However when I'm trying to run it on nRF5340, I have an error "Failed enabling advertiser"  when running bt_ready_provisioner.

Code for that function is mostly the same as from example (from separate .c file):

int bt_ready_prov(const struct bt_mesh_prov *prov,
		  const struct bt_mesh_comp *comp)
{
	uint8_t net_key[16], dev_key[16];
	int err;

	err = bt_mesh_init(prov, comp);
        
	if (err) {
		printk("Initializing mesh failed (err %d)\n", err);
		return err;
	}

        err = bt_set_name("nRF 52840");

        if (err) {
		printk("Setting new name failed (err %d)\n", err);
		return err;
	}

	printk("Mesh initialized\n");

	if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
		printk("Loading stored settings\n");
		err = settings_load();
                if (err) {
                      printk("failed err %d\n", err);
                } else {
                      printk("Loaded successfully\n");
                }
	}

	bt_rand(net_key, 16);

	err = bt_mesh_cdb_create(net_key);
	if (err == -EALREADY) {
		printk("Using stored CDB\n");
	} else if (err) {
		printk("Failed to create CDB (err %d)\n", err);
		return err;
	} else {
		printk("Created CDB\n");
		setup_cdb();
	}

	bt_rand(dev_key, 16);

	err = bt_mesh_provision(net_key, BT_MESH_NET_PRIMARY, 0, 0, self_addr,
				dev_key);
	if (err == -EALREADY) {
		printk("Using stored settings\n");
	} else if (err) {
		printk("Provisioning failed (err %d)\n", err);
		return err;
	} else {
		printk("Provisioning completed\n");
	}

	return 0;
}

Main function:

void main(void)
{
	static struct k_work button_work;
	int err = -1;
	printk("Initializing...\n");
        LOG_INF(CONFIG_BOARD);

	if (IS_ENABLED(CONFIG_HWINFO)) {
		err = hwinfo_get_device_id(dev_uuid, sizeof(dev_uuid));
	}
	if (err < 0) {
		dev_uuid[0] = 0xdd;
		dev_uuid[1] = 0xdd;
	}

	err = board_init(&button_work);
	if (err) {
		printk("Board init failed (err: %d)\n", err);
		return;
	}

        printk("Version: 2.3.3.15\n");
        os_mgmt_register_group();
        img_mgmt_register_group();
        smp_bt_register();
        
        /* Initialize the Bluetooth Subsystem and mesh stack as provisioner */
        err = bt_enable(NULL);
        if (err) {
    		printk("Bluetooth init or mesh failed (err %d)\n", err);
    	}
        err = bt_ready_prov(&provisioner, &comp);
        if (err) {
                LOG_ERR("BT Mesh provisioner failed: %d\n", err);
        }

        threads_init();

        LOG_INF("Launched successfully");
}

threads_init():

static void threads_init(void) {
        
        printk("Initialising uuid_print_thread...\n");
        uuid_thread_tid = k_thread_create(&uuid_thread, uuid_stack, K_THREAD_STACK_SIZEOF(uuid_stack), (k_thread_entry_t) uuid_print_thread, 
                                          NULL, NULL, NULL, UUID_THREAD_PRIORITY, 0, K_NO_WAIT);
        
#if defined(CONFIG_BOARD_NRF5340DK_NRF5340_CPUAPP) && defined(CONFIG_BT_DF)
        scan_init();
        printk("Initialising reading direction thread...\n");
        direction_finding_tid = k_thread_create(&direction_thread, direction_finding_stack, K_THREAD_STACK_SIZEOF(direction_finding_stack), 
                                                (k_thread_entry_t) reading_direction, 
                                                NULL, NULL, NULL, DF_RX_PRIORITY, 0, K_NO_WAIT); //regular thread
        k_thread_name_set(prov_wfb_thread, "DF launched");
#endif // defined(CONFIG_BOARD_NRF5340DK_NRF5340_CPUAPP) && defined(CONFIG_BT_DF)
        
        printk("Initialising wfb_thread...\n");
        prov_wfb_thread = k_thread_create(&prov_thread, prov_stack, K_THREAD_STACK_SIZEOF(prov_stack), wait_for_beacon_thread, 
                                          NULL, NULL, NULL, PROV_PRIORITY, 0, K_NO_WAIT); //regular thread
        k_thread_name_set(prov_wfb_thread, "Prov Beacon");
}

Output when running looks like this:

*** Booting Zephyr OS build v2.7.99-ncs1  ***
Initializing...
[00:00:00.016,784] <inf> mesh_main: nrf5340dk_nrf5340_cpuapp
Version: 2.3.3.15
[00:00:00.022,064] <inf> fs_nvs: 2 Sectors of 4096 bytes
[00:00:00.022,094] <inf> fs_nvs: alloc wra: 0, ec0
[00:00:00.022,094] <inf> fs_nvs: data wra: 0, 200
[00:00:00.058,166] <inf> bt_hci_core: HCI: version 5.2 (0x0b) revision 0x2190, manufacturer 0x0059
--- 8 messages dropped ---
[00:00:00.058,197] <inf> bt_hci_core: LMP: version 5.2 (0x0b) subver 0x2190
[00:00:00.060,546] <wrn> bt_hci_core: opcode 0x2036 status 0x01
[00:00:00.060,577] <err> bt_mesh_main: Failed enabling advertiser
Loaded successfully
Using stored CDB
[00:00:00.063,568] <inf> bt_mesh_main: Primary Element: 0x0001
[00:00:00.063,568] <dbg> bt_mesh_main.bt_mesh_provision: net_idx 0x0000 flags 0x00 iv_index 0x0000
Using stored settings
Initialising uuid_print_thread...
Starting Connectionless Locator
success.
Initialising reading direction thread...
Initialising wfb_thread...
[00:00:00.063,812] <inf> mesh_main: Launched successfully
[00:00:00.064,666] <inf> mesh_main: UUID Print thread entered
[00:00:00.064,697] <inf> mesh_main: UUID: be95250522343f3f0000000000000000
[00:00:00.064,758] <inf> direction_rx: Start scanning...
[00:00:00.066,314] <inf> provisioner: Waiting for unprovisioned beacon...
[00:00:00.067,810] <wrn> bt_hci_core: opcode 0x2041 status 0x01
[00:00:00.067,810] <inf> direction_rx: failed (err -5)

[00:00:00.067,840] <inf> direction_rx: Waiting for periodic advertising...

I don't know what's wrong with it, considering it worked well on nRF52840. Is there anything I'm missing?

Parents
  • Hi

     I have a few questions here. First off, the nRF52840 doesn't support the Direction Finding (introduced in BLE 5.1) so it seems strange that the locator application would work with that board at all. 

    Secondly, you say that the error you see is "Failed enabling advertiser" but the Direction Finding locator doesn't advertise, is this advertising happening in over Bluetooth Mesh? The error from your log does not seem to be related to advertising but rather an error from a log line with "direction_rx" (which I can't find in the nRF Connect SDK). Have you added this logging line yourself? Are you able to see what the err -5 returns as? What NCS version are you working on?

    Lastly, Bluetooth Mesh and Direction Finding features are not trivial to combine I'm afraid, since they both use timeslots they will likely have quite a few conflicts on time critical tasks, so you need to use something like the MPSL timeslot functionality to handle correctly.

    Best regards,

    Simon

  • I have a few questions here. First off, the nRF52840 doesn't support the Direction Finding (introduced in BLE 5.1) so it seems strange that the locator application would work with that board at all. 

    It doesn't. But I've had in CMakeLists.txt and in the code itself safety measures, such as "if the chosen board isn't nRF5340, then all direction finding code won't be included in the project". That had no issues. So basically when I ran this code in nRF52840, anything related to direction finding isn't there and it runs only provisioner. 

    is this advertising happening in over Bluetooth Mesh?

    I guess so, because the code was supposed to launch mesh provisioner.

    The error from your log does not seem to be related to advertising but rather an error from a log line with "direction_rx" (which I can't find in the nRF Connect SDK). Have you added this logging line yourself?

    "direction_rx" is basically the sample code from direction_finding_connectionless_rx from the Nordic samples. Only thing I changed was to rename "main" to a different function so I could run it as a thread.

    Are you able to see what the err -5 returns as? What NCS version are you working on?

    -5 is EIO, which is weird for me. NCS is the latest one, 1.9.0.

    Lastly, Bluetooth Mesh and Direction Finding features are not trivial to combine I'm afraid, since they both use timeslots they will likely have quite a few conflicts on time critical tasks, so you need to use something like the MPSL timeslot functionality to handle correctly.

    Duly noted, I'll look at this, thanks!

    P.S: even if I comment the thread initialisation for Direction Finding so it could run only provisioner, it still throws "Failed enabling advertiser". Could there be something around configuration files? I have a regular "prj.conf", and "hci_rpmg.conf" in "child_image" folder which is copied from Direction Finding sample. Also, if I run a sample of mesh_provisioner from Zephyr samples, during the provision of another remote device it reboots throwing stack overflow error and hard reset.

Reply
  • I have a few questions here. First off, the nRF52840 doesn't support the Direction Finding (introduced in BLE 5.1) so it seems strange that the locator application would work with that board at all. 

    It doesn't. But I've had in CMakeLists.txt and in the code itself safety measures, such as "if the chosen board isn't nRF5340, then all direction finding code won't be included in the project". That had no issues. So basically when I ran this code in nRF52840, anything related to direction finding isn't there and it runs only provisioner. 

    is this advertising happening in over Bluetooth Mesh?

    I guess so, because the code was supposed to launch mesh provisioner.

    The error from your log does not seem to be related to advertising but rather an error from a log line with "direction_rx" (which I can't find in the nRF Connect SDK). Have you added this logging line yourself?

    "direction_rx" is basically the sample code from direction_finding_connectionless_rx from the Nordic samples. Only thing I changed was to rename "main" to a different function so I could run it as a thread.

    Are you able to see what the err -5 returns as? What NCS version are you working on?

    -5 is EIO, which is weird for me. NCS is the latest one, 1.9.0.

    Lastly, Bluetooth Mesh and Direction Finding features are not trivial to combine I'm afraid, since they both use timeslots they will likely have quite a few conflicts on time critical tasks, so you need to use something like the MPSL timeslot functionality to handle correctly.

    Duly noted, I'll look at this, thanks!

    P.S: even if I comment the thread initialisation for Direction Finding so it could run only provisioner, it still throws "Failed enabling advertiser". Could there be something around configuration files? I have a regular "prj.conf", and "hci_rpmg.conf" in "child_image" folder which is copied from Direction Finding sample. Also, if I run a sample of mesh_provisioner from Zephyr samples, during the provision of another remote device it reboots throwing stack overflow error and hard reset.

Children
No Data
Related