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

Device Name Change

Hi all ,

I'm using SDK 15.0, working on ble_uart.c

I need to change the DEVICE  NAME of the  frequently.

Can you please tell me how to change the the device name and store it in a buffer.

If you provide a example code, it will be a great help.

Thanks and Regards,

 Venu

  • Hi Martin,

    Can you elaborate a little bit about the APIs to use to disable, re-initialize, and start advertising again?  I am actually trying to do the same but unable to find the error?

  • Hi Arya,

    You will need to call sd_ble_gap_adv_stop() after you have changed the name with sd_ble_gap_device_name_set().

    See this thread for more info.

  • Hi

    I found myself in the situation to implement a dynamically updating device name. Here some working, user-friendly code. The idea is to reuse the ble_advertising_init_t struct from initialization:

    #include "nrf_sdh_ble.h"
    
    
    BLE_ADVERTISING_DEF(m_advertising);
    static ble_advertising_init_t adv_init;
    
    /* This function will update the device name and advertising data accordingly. */
    void bluetooth_update_name(uint8_t* name) {
    	ret_code_t err_code;
    	ble_gap_conn_sec_mode_t sec_mode;
    
    	BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&sec_mode);
    
    	if (current_config.name[0] != '\0') {
    		err_code = sd_ble_gap_device_name_set(&sec_mode, name, strnlen(name, 10));
    		APP_ERROR_CHECK(err_code);
    	}
    	else {
    		err_code = sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *)NUS_DEVICE_NAME, strlen(NUS_DEVICE_NAME));
    		APP_ERROR_CHECK(err_code);
    	}
    
    
      //sd_ble_gap_adv_stop(&m_advertising.adv_handle);
    
    	err_code = ble_advdata_encode(&adv_init.advdata, m_advertising.enc_advdata, &m_advertising.adv_data.adv_data.len);
    	VERIFY_SUCCESS(err_code);
    
    	if (m_advertising.adv_modes_config.ble_adv_extended_enabled == true)
    	{
    #ifdef BLE_GAP_ADV_SET_DATA_SIZE_EXTENDED_CONNECTABLE_MAX_SUPPORTED
    		m_advertising.adv_data.scan_rsp_data.len = BLE_GAP_ADV_SET_DATA_SIZE_EXTENDED_CONNECTABLE_MAX_SUPPORTED;
    #else
    		m_advertising.adv_data.scan_rsp_data.len = BLE_GAP_ADV_SET_DATA_SIZE_MAX;
    #endif // BLE_GAP_ADV_SET_DATA_SIZE_EXTENDED_CONNECTABLE_MAX_SUPPORTED
    	}
    	else
    	{
    		m_advertising.adv_data.scan_rsp_data.len = BLE_GAP_ADV_SET_DATA_SIZE_MAX;
    	}
    
    	err_code = ble_advdata_encode(&adv_init.srdata,
    		m_advertising.adv_data.scan_rsp_data.p_data,
    		&m_advertising.adv_data.scan_rsp_data.len);
    
    	sd_ble_gap_adv_set_configure(&m_advertising.adv_handle,
    		m_advertising.p_adv_data,
    		NULL);
    }
    
    
    /* This is my initialization routine for advertising */
    static void advertising_init(void) {
    	uint32_t err_code;
    
    	memset(&adv_init, 0, sizeof(adv_init));
    
    	adv_init.advdata.name_type = BLE_ADVDATA_FULL_NAME;
    	adv_init.advdata.include_appearance = false;
    	adv_init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
    
    	adv_init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    	adv_init.srdata.uuids_complete.p_uuids = m_adv_uuids;
    
    	adv_init.config.ble_adv_fast_enabled = true;
    	adv_init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
    	adv_init.config.ble_adv_fast_timeout = APP_ADV_DURATION;
    
    	adv_init.evt_handler = on_adv_evt;
    
    	err_code = ble_advertising_init(&m_advertising, &adv_init);
    	APP_ERROR_CHECK(err_code);
    
    	ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
    }
    

    If you have some questions, please ask right away Slight smile

    Best regards

    Markus, Technokrat GmbH

  • hi atok... i need your help pls . i need to change the device name using ble app uart

  • Hi pspavi
    What do you intend to do?

    Best regards

    Markus, Technokrat GmbH

Related