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

how to set ble gap address type to RANDOM_PRIVATE_RESOLVABLE

I want to change the ble gap address type to RANDOM_PRIVATE_RESOLVABLE. In gap_params_init(), I add these line at the end of the function

ble_gap_addr_t *p_gap_address;
err_code = sd_ble_gap_addr_get(p_gap_address);
APP_ERROR_CHECK(err_code);
p_gap_address->addr_type = BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE;
err_code = sd_ble_gap_addr_set(p_gap_address);
APP_ERROR_CHECK(err_code);

The code is based on ble_app_template. No error or warning, but it does not work. what should I do?

  • For S132 v3 you need to use sd_ble_gap_privacy_set if you want to use a random private resolvable address. See ble_gap_privacy_params_t for details.

  • I tried to use sd_ble_gap_privacy_set() to set a random private resolvable address. I added these code in gap_params_init():

    	ble_gap_privacy_params_t *ble_gap_privacy_params;
    	err_code = sd_ble_gap_privacy_get(ble_gap_privacy_params);
    	APP_ERROR_CHECK(err_code);
    	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);
    

    No error or warning, but it still does not work.

  • you don't have to do sd_ble_gap_privacy_get first. just initialize the struct to 0. Anyway it looks like you are using the correct parameters. How do verify if this works or not?

  • The error you got was "NRF_ERROR_INVALID_ADDR (NRF_ERROR_BASE_NUM + 16)" So your program was stuck in an endless loop.

    Your code needs to look like this to work.

    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);
    
  • Do I really have to use sd_ble_gap_privacy_set if I want to use BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE? Or can I keep my code that works with version v2 by simply changing the GAP address myself using sd_ble_gap_addr_set?


    I have just implemented a multi advertiser that can broadcast using different addresses, but no it seems like this functionality has been modified and this is no longer possible :-( Any workarounds? This was the only sensible method for broadcasting multiple messages,...

Related