How to change the BLE mac address of NRF5430 at Real Time with NCS SDK?

  I follow below thread and refer to sample code and  the BLE mac address can be changed after system just boot up.

   devzone.nordicsemi.com/.../325131

   But after boot up, I want to change  the BLE mac address again, it doesn't work and the ble MAC address keep unchanged, it is expected?  Is it possible to change the desired BLE mac address at real time without HW reset?

Below is my Sudo code:

nrf5340 boot up,  

bt_enable(NULL);

bt_addr_t addr = {{0xFE, 0xCA, 0xA0, 0xAC, 0xDC, 0xBA}};
ble_set_mac(&addr);

settings_load();

ble_advertise();  //it works with ble addr = {{0xFE, 0xCA, 0xA0, 0xAC, 0xDC, 0xBA}}

ble_Stop_advertise();

bt_addr_t addr = {{0xFE, 0xCA, 0xA0, 0xAC, 0xDC, 0xBB}};
ble_set_mac(&addr);

settings_load();

ble_advertise(); //it doesn't work, ble address cant be changed.

found the ble's mac address is still  = {{0xFE, 0xCA, 0xA0, 0xAC, 0xDC, 0xBA}};

  • Hi Andreas,

        I have tried the api bt_id_create(). 

        when nrf5430 just boot up it is ok to set the ble Mac address. 

       But after stop ble adversiting and set the ble address by bt_id_create() again, it show "Creating new ID failed (err -12)".

      Is it possible to change the desired BLE mac address at real time without HW reset?

  • Hi,

    John said:
       But after stop ble adversiting and set the ble address by bt_id_create() again, it show "Creating new ID failed (err -12)".

    Which parameters do you call bt_id_create() with? Error 12 corresponds with invalid parameters

    John said:
      Is it possible to change the desired BLE mac address at real time without HW reset?

    It should be possible to do so, at least if you enable and disable Bluetooth in between swapping the address. You should also be able to create multiple identities and store them in persistent settings and recover them with settings_load() if required

    Kind regards,
    Andreas

  • hi Haug,

        I use below to change the ble mac address:

    bt_addr_le_t addr;
    err = bt_addr_le_from_str("FF:EE:DD:CC:BB:AA", "random", &addr);
    if (err) {
    printk("Invalid BT address (err %d)\n", err);
    }

    err = bt_id_create(&addr, NULL);
    if (err < 0) {
    printk("Creating new ID failed (err %d)\n", err);
    }

    After Stop BLE broadcasting and call below again it return error 12.

    bt_addr_le_t addr;
    err = bt_addr_le_from_str("FF:EE:DD:CC:BB:A1", "random", &addr);
    if (err) {
    printk("Invalid BT address (err %d)\n", err);
    }

    err = bt_id_create(&addr, NULL);
    if (err < 0) {
    printk("Creating new ID failed (err %d)\n", err);
    }

     Let me try to disable BLE and change the address.

  • hi Haug,

        By BT Enable and Disable also not working.

        Below is my test flow:

        1. nrf5430 bootup, call bt_enable(), set new ble mac address. start ble adverstising. it work with new ble mac address.

         2. Stop  ble adverstising  and call bt_disable(), it shows Bluetooth disble failed (err -134)

         3.  call bt_id_create(), it shows Creating new ID failed (err -12).

         4. call bt_enable(), Bluetooth init failed (err -120).

  • Hi,

    The SoftDevice Controller does not support disabling, so bt_disable() will always fail (see this post). It is not allowed in Bluetooth to change a static address runtime, so there is no support for what you are asking for in this thread.

Related