Bluetooth address and settings_load()

Hello all,

i have a problem and I hope that someone can help me.

I can change the bluetooth address of the device with the following code:

err = bt_addr_le_from_str(addr_str, type_str, &addr);
if (err) {
	printk("Invalid BT address (err %d)\n", err);
}

if (addr.type == BT_ADDR_LE_PUBLIC) {
	printk("Using public address\n");
	err = bt_ctlr_set_public_addr(addr.a.val);
	if (err) {
        printk("Failed to set public address (err %d)\n", err);
    } else {
        printk("Public address set successfully\n");
    }
	return;
}

and this is okay.

I have the problem when I add this part of code:
CONFIG_SETTINGS=y

and

if (IS_ENABLED(CONFIG_SETTINGS)) {
	settings_load();
	printk("Settings load \n");
}

With this part of code I can not set my bluetooth address. The bluetooth address of the the device is not the one that I have setted but is the one inside the chip (i think).

I need to add settings_load() to keep the bond device information after the power off.

How can avoid this??

Thanks in advance.

Parents
  • Hello,

    The address handling is a bit different when BT settings is enabled, but I'm unsure why it no longer works after enabling it. Please try to use the bt_id_create() host function instead of bt_ctlr_set_public_addr() from the controller. 

    Which version of the SDK are you using?

    Thanks,

    Vidar

  • Hello, 
    I had already tried to use "bt_id_create()" but i have always err-22.

    bt_addr_le_t newAddr;
    	err = bt_addr_le_from_str("DE:AD:BE:EF:BA:11", "random", &newAddr);
    	if (err < 0) {
    		printk("Error conversion bt addres %d)\n", err);
    	}
    
    	printk("Bluetooth address readed: %x%x%x%x%x%x: ",  newAddr.a.val[0], newAddr.a.val[1], newAddr.a.val[2], newAddr.a.val[3], newAddr.a.val[4],  newAddr.a.val[5]);
    
    	err = bt_id_create(&newAddr, NULL);
    	if (err < 0) {
    		printk("Creating new ID failed (err %d)\n", err);
    	}


    I can not set "CONFIG_BT...." I have unknow symbol.

    I'm still investigate why I have this problem.

    I'm using NCS2.6.1 with VSCode.
    If you can help me many thanks in advance.

    Best regards

Reply
  • Hello, 
    I had already tried to use "bt_id_create()" but i have always err-22.

    bt_addr_le_t newAddr;
    	err = bt_addr_le_from_str("DE:AD:BE:EF:BA:11", "random", &newAddr);
    	if (err < 0) {
    		printk("Error conversion bt addres %d)\n", err);
    	}
    
    	printk("Bluetooth address readed: %x%x%x%x%x%x: ",  newAddr.a.val[0], newAddr.a.val[1], newAddr.a.val[2], newAddr.a.val[3], newAddr.a.val[4],  newAddr.a.val[5]);
    
    	err = bt_id_create(&newAddr, NULL);
    	if (err < 0) {
    		printk("Creating new ID failed (err %d)\n", err);
    	}


    I can not set "CONFIG_BT...." I have unknow symbol.

    I'm still investigate why I have this problem.

    I'm using NCS2.6.1 with VSCode.
    If you can help me many thanks in advance.

    Best regards

Children
Related