This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Periodically changing the MAC address on nRF51822 Beacon Kit

Hi,

I am able to change the MAC address of the beacon using the call sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &gap_addr), where gap_addr is of type BLE_GAP_ADDR_TYPE_RANDOM_STATIC.

Now what I want to do is to change the MAC address periodically, while the beacon is still advertising. From what I understand, I need to use sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_AUTO, &gap_addr), with an address of type BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE. However, the MAC address seems to change only during the boot up and when the SW2 button is pressed (changes one when beacon goes into config mode and once when beacon switches back to advertising). I set the BLE_GAP_DEFAULT_PRIVATE_ADDR_CYCLE_INTERVAL_S to 5 to be able to observe the change. I am calling the sd_ble_gap_address_set function after ble_stack_init() call in the main function of the sample beacon app.

What should I do to achieve periodic change of MAC address? Can this be achieved with LE_GAP_ADDR_CYCLE_MODE_AUTO mode at all, or should I simply set up a timer, create random MAC address and call sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &gap_addr) every time timer expires?

Thanks for your help in advance.

Parents
  • Hi Sarah,

    The address should change even while advertising, so there is no need to set up any timers for this. Just to make sure: Are you calling sd_ble_opt_set() with gap_opt.privacy.interval_s set to 5, or just changing the define?

    To change the default address rotation time (15 minutes) you have to do something like this:

    ble_opt_t opt = {0};
    opt.gap_opt.privacy.interval_s = TIME_IN_SECONDS_HERE;
    err_code = sd_ble_opt_set(BLE_GAP_OPT_PRIVACY, &opt);
    APP_ERROR_CHECK(err_code);
    
  • I just changed this default line #define BLE_GAP_DEFAULT_PRIVATE_ADDR_CYCLE_INTERVAL_S (60 * 15) to #define BLE_GAP_DEFAULT_PRIVATE_ADDR_CYCLE_INTERVAL_S (5). I did not use sd_ble_opt_set() function. It looks like this is where the problem is, changing the above default value in the code has no effect. If I wait for 15 minutes, then the MAC address changes. How do I fix this?

    Below is my code for the periodic change. Like I said before, I observe a change in MAC address only when I press SW2 button.

    void periodically_change_mac_address() {

    ble_gap_addr_t gap_address; uint8_t err_code;

    gap_address.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE;
    
    err_code = sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_AUTO, &gap_address);
    APP_ERROR_CHECK(err_code);
    

    }

Reply
  • I just changed this default line #define BLE_GAP_DEFAULT_PRIVATE_ADDR_CYCLE_INTERVAL_S (60 * 15) to #define BLE_GAP_DEFAULT_PRIVATE_ADDR_CYCLE_INTERVAL_S (5). I did not use sd_ble_opt_set() function. It looks like this is where the problem is, changing the above default value in the code has no effect. If I wait for 15 minutes, then the MAC address changes. How do I fix this?

    Below is my code for the periodic change. Like I said before, I observe a change in MAC address only when I press SW2 button.

    void periodically_change_mac_address() {

    ble_gap_addr_t gap_address; uint8_t err_code;

    gap_address.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE;
    
    err_code = sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_AUTO, &gap_address);
    APP_ERROR_CHECK(err_code);
    

    }

Children
No Data
Related