How to set BLE device name periodically

I'm using SDK 15.3 on a 52840 and this (How to set BLE device name based on device parameters) works on startup, no problem. I can set a name easily.

Now suppose I want to change the name every couple of minutes?  I can set the name with this code but it's not changing on the adverts as far as I can see.  Must be missing something.

This post ( How to change the device name?) says to issue a function call that doesn't exist in this version of SDK (the post is quite old) and I haven't figured out what the right one is in this version of SDK.  If I go back for an init using ble_advertising_init(), I get an 8 error code back.

Any hint on this SDK 15.3?

Parents
  • Hi there,

    You can use ble_advertising_advdata_update() to change the advertising data, remember that error will be returned if:

    • It is invalid to provide non-NULL advertising set parameters while advertising.
    • It is invalid to provide the same data buffers while advertising. To update advertising data, provide new advertising buffers.

    You can use an app timer to schedule the change of advertising set every minute. 

    Hopefully that answered your question Slight smile

    regards

    Jared

  • OK, not all that familiar with the actual structure of this code, but I'm having trouble understanding the buffer thing here.  I don't actually set a buffer that would have this name.  When I init the advertising (with MFG data) I use this code:

    static const ble_advertising_init_t advertising_params = {
    		.advdata = {
    				.name_type          = BLE_ADVDATA_FULL_NAME,					// this is like 12 bytes long
    				.include_appearance = false,
    				.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE,
    				.p_manuf_specific_data = &manuf_data,
    		},
    
    		.config = {
    				.ble_adv_whitelist_enabled = true,                              // This flag causes generation of BLE_ADV_EVT_WHITELIST_REQUEST's
    				.ble_adv_fast_enabled      = true,                              // Fast is completely the same as slow so choose any
    				.ble_adv_fast_interval     = MSEC_TO_UNITS(500, UNIT_0_625_MS), // The advertising interval.
    				.ble_adv_fast_timeout      = MSEC_TO_UNITS(0, UNIT_10_MS)       // The advertising duration. 0 - forever
    		},
    
    		.evt_handler = on_adv_evt
    };
    ...
    static void advertising_init(void) {
    	APP_ERROR_CHECK(ble_advertising_init(&m_advertising, &advertising_params));
    	ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
    }
    
    When it sets the name first this code is using:
    	BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
    
    	ErrCode = sd_ble_gap_device_name_set(&sec_mode, BabyID, BABY_NAME_LEN);
    

    So I,m not setting a buffer up that has this name at all, but using particular calls to set it. 

    This function wants an advertising buffer (a different one that's being used), but I don't exactly have the first one.

    Is there some code I can look at that has this call and how to deal with it and the rest of the stuff?

Reply
  • OK, not all that familiar with the actual structure of this code, but I'm having trouble understanding the buffer thing here.  I don't actually set a buffer that would have this name.  When I init the advertising (with MFG data) I use this code:

    static const ble_advertising_init_t advertising_params = {
    		.advdata = {
    				.name_type          = BLE_ADVDATA_FULL_NAME,					// this is like 12 bytes long
    				.include_appearance = false,
    				.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE,
    				.p_manuf_specific_data = &manuf_data,
    		},
    
    		.config = {
    				.ble_adv_whitelist_enabled = true,                              // This flag causes generation of BLE_ADV_EVT_WHITELIST_REQUEST's
    				.ble_adv_fast_enabled      = true,                              // Fast is completely the same as slow so choose any
    				.ble_adv_fast_interval     = MSEC_TO_UNITS(500, UNIT_0_625_MS), // The advertising interval.
    				.ble_adv_fast_timeout      = MSEC_TO_UNITS(0, UNIT_10_MS)       // The advertising duration. 0 - forever
    		},
    
    		.evt_handler = on_adv_evt
    };
    ...
    static void advertising_init(void) {
    	APP_ERROR_CHECK(ble_advertising_init(&m_advertising, &advertising_params));
    	ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
    }
    
    When it sets the name first this code is using:
    	BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
    
    	ErrCode = sd_ble_gap_device_name_set(&sec_mode, BabyID, BABY_NAME_LEN);
    

    So I,m not setting a buffer up that has this name at all, but using particular calls to set it. 

    This function wants an advertising buffer (a different one that's being used), but I don't exactly have the first one.

    Is there some code I can look at that has this call and how to deal with it and the rest of the stuff?

Children
  • Hi,

    The advertising name is actually set with sd_ble_gap_device_name_set() which is often in gap_params_init() function in most of our examples. 

    To change the advertising name:

    1. Change advertising name by calling  sd_ble_gap_device_name_set()
    2. Update advertising data by calling ble_advertising_advdata_update() with new buffers but that contains the same arguments that you set in advertising_init. 

    That will update your advertising data with the new GAP device name.

    See this answer,

    regards

    Jared 

Related