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

How to set my nRF device to use the private resolvable address

Hello~ I'm using the nRF52832 board, s132_nrf52_6.1.0_softdevice, SDK 15.2. I'm focusing on 3 peripheral examples;

ble_app_hrs & ble_app_eddystone & ble_app_beacon

If I understood correctly, I think these examples' MAC address doesn't change.

I made this conclusion after viewing with the nRF connect mobile App.

Umm, it is possible to make these examples to change the MAC addresses as the resolvable random addresses, right?

What SoftDevice function should I call to make this happen?

Lastly, can I set a duration to make the address to change?

For example, I want to make the MAC address (which is resolvable) to change its address every 5 minutes.

Parents
  • Hello, 

    Yes, your observation is correct, the SDK examples uses the random static address by default.  In SDK 15.2.0 you can use the peer manager API to enable privacy. E.g. 

    /**@brief Function for the Peer Manager initialization.
     */
    static void peer_manager_init(void)
    {
        ble_gap_sec_params_t sec_param;
        pm_privacy_params_t  privacy_params;
        ret_code_t           err_code;
    ...
    
        err_code = pm_sec_params_set(&sec_param);
        APP_ERROR_CHECK(err_code);
    
        memset(&privacy_params, 0, sizeof(pm_privacy_params_t));
    
        privacy_params.privacy_mode         = BLE_GAP_PRIVACY_MODE_DEVICE_PRIVACY;
        privacy_params.private_addr_type    = BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE;
        privacy_params.private_addr_cycle_s = 300; // Change address every 5 minutes
    
        err_code = pm_privacy_set(&privacy_params);
    ...
    }
    

  • Thanks for your help, Vidar!

    // in sdk_config.h
    #define PEER_MANAGER_ENABLED 1
    

    I tried the ble_app_beacon example from Embedded Studio 4.10.

    I thought simply enabling the PEER_MANAGER_ENABLED macro and adding the source file peer_manager.c would end this.

    Are there extra steps left for solving this error?

  • Do you intend to support pairing/bonding in your app? In that case I think ble_app_hrs/ble_app_template would be a better starting point. The beacon example is missing several source files typically used to manage BLE connections. sdk_config.h will only enable compilation of source files included in the project. 

  • Do you intend to support pairing/bonding in your app?

    Nope, except the ble_app_hrs example. I just wanted to change the address every 5 minutes for each example ( ble_app_eddystone & ble_app_beacon).

    I think ble_app_hrs/ble_app_template would be a better starting point.

    Thanks, I will try with the Heart Rate example.

    The beacon example is missing several source files typically used to manage BLE connections.

    Then, what should I add to make the beacon example (both iBeacon and Eddystone) to change its address every 5 minutes?

  • Thanks for the clarification. The peer manager is meant for bond management, so will not be needed in a beacon application.  I would suggest to use the SD API to enable privacy instead.

    API to enable privacy: sd_ble_gap_privacy_set()

  • Thank you, Vidar. One last question, please.

    #include "ble_gap.h"
    
        ble_gap_privacy_params_t ble_gap_privacy_params = {0};
        
        ble_gap_privacy_params.privacy_mode = BLE_GAP_PRIVACY_MODE_DEVICE_PRIVACY;
        ble_gap_privacy_params.private_addr_type = BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE;
        ble_gap_privacy_params.private_addr_cycle_s = BLE_GAP_DEFAULT_PRIVATE_ADDR_CYCLE_INTERVAL_S;
        ble_gap_privacy_params.p_device_irk = NULL;
        err_code = sd_ble_gap_privacy_set(&ble_gap_privacy_params);
        APP_ERROR_CHECK(err_code);

    I tried this by referring this thread. I noticed that the MAC address of the beacon changes after I turn off/on the device. When using the sd_ble_gap_privacy_set, is there a way to set the period for changing the address? just like you this this;

    privacy_params.private_addr_cycle_s = 300; // Change address every 5 minutes

Reply
  • Thank you, Vidar. One last question, please.

    #include "ble_gap.h"
    
        ble_gap_privacy_params_t ble_gap_privacy_params = {0};
        
        ble_gap_privacy_params.privacy_mode = BLE_GAP_PRIVACY_MODE_DEVICE_PRIVACY;
        ble_gap_privacy_params.private_addr_type = BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE;
        ble_gap_privacy_params.private_addr_cycle_s = BLE_GAP_DEFAULT_PRIVATE_ADDR_CYCLE_INTERVAL_S;
        ble_gap_privacy_params.p_device_irk = NULL;
        err_code = sd_ble_gap_privacy_set(&ble_gap_privacy_params);
        APP_ERROR_CHECK(err_code);

    I tried this by referring this thread. I noticed that the MAC address of the beacon changes after I turn off/on the device. When using the sd_ble_gap_privacy_set, is there a way to set the period for changing the address? just like you this this;

    privacy_params.private_addr_cycle_s = 300; // Change address every 5 minutes

Children
  • Sure, just replace BLE_GAP_DEFAULT_PRIVATE_ADDR_CYCLE_INTERVAL_S with 300. Default interval is 15 minutes. Same code as I posted earlier but without PM:

    void gap_init(void)
    {
        uint32_t err_code;
        ble_gap_privacy_params_t privacy_params;
    
        memset(&privacy_params, 0, sizeof(ble_gap_privacy_params_t));
    
        privacy_params.privacy_mode         = BLE_GAP_PRIVACY_MODE_DEVICE_PRIVACY;
        privacy_params.private_addr_type    = BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE;
        privacy_params.private_addr_cycle_s = 300;
    
        err_code = sd_ble_gap_privacy_set(&privacy_params);
        APP_ERROR_CHECK(err_code);
    }

Related