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);
    
  • probably because you it returned an error code, there are 5 documented, I'm going to guess NRF_ERROR_INVALID_PARAM. Your code's wrong anyway, the opt_id is not the value of the option it is, as I wrote earlier, BLE_GAP_OPT_PRIVACY

    err_code = sd_ble_opt_set( BLE_GAP_OPT_PRIVACY, &opt );
    

    if you have to comment out APP_ERROR_CHECK() then you are just ignoring errors.

Reply
  • probably because you it returned an error code, there are 5 documented, I'm going to guess NRF_ERROR_INVALID_PARAM. Your code's wrong anyway, the opt_id is not the value of the option it is, as I wrote earlier, BLE_GAP_OPT_PRIVACY

    err_code = sd_ble_opt_set( BLE_GAP_OPT_PRIVACY, &opt );
    

    if you have to comment out APP_ERROR_CHECK() then you are just ignoring errors.

Children
No Data
Related