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

nRf52832 device name change by using mobile app

Hi,

I need to change the Device name in nRf52832. Mobile app sends the request to nRf52832. 

Thanks.

static void ChangeDeviceName(void)
{
        uint32_t err_code;
        ble_gap_conn_sec_mode_t sec_mode;
        ble_gap_conn_params_t gap_conn_params;
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
        static uint8_t index = 0;

        advertising_stop();

        //sprintf(Devicename3, "HUAWEI_DEVICE %d", index);
        index++;
        err_code = sd_ble_gap_device_name_set(&sec_mode,
                                              (uint8_t *) Devicename3,
                                              strlen(Devicename3));

        NRF_LOG_INFO("device name error %d", err_code);
        APP_ERROR_CHECK(err_code);
}

  • Hi, 

    After changing the GAP device name with sd_ble_gap_device_name_set(), it should call ble_advertising_advdata_update() with the same 'srdata' and 'advata' arguments that were used in advertising_init(). This process will update your adv. payload with the new GAP device name.

     

    Regards,

    Amanda H.

  • static void ChangeDeviceName(void)
    {
            uint32_t err_code;
            ble_gap_conn_sec_mode_t sec_mode;
            ble_gap_conn_params_t gap_conn_params;
            BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
            ble_advdata_manuf_data_t    manuf_data;
            new_advdata.p_manuf_specific_data = &manuf_data;
            
            static uint8_t index = 0;
            static uint8_t payload_index = 0;
    
            advertising_stop();
    
            index++;
            err_code = sd_ble_gap_device_name_set(&sec_mode,
                                                  (uint8_t *) Devicename2,
                                                  strlen(Devicename2));
    
            NRF_LOG_INFO("device name error %d", err_code);
            APP_ERROR_CHECK(err_code);
            
            manuf_data.company_identifier = APP_COMPANY_IDENTIFIER;
    
            manuf_data.data.p_data = manufacturing_data_payload_list + payload_index;
            manuf_data.data.size = PAYLOAD_SIZE;
            
            err_code = ble_advertising_advdata_update(&m_advertising, &new_advdata, NULL);
            APP_ERROR_CHECK(err_code);  
            if(payload_index == TOP_INDEX)
            {
                payload_index = 0;
            }
            else
            {
                payload_index++;
            }
    }

    Is it Ok.  

  • 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);
    
            err_code = sd_ble_gap_adv_stop(m_advertising.adv_handle);
            
            
            ble_advertising_restart_without_whitelist(&m_advertising);
    	
    
    		err_code = sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *)Devicename2, strlen(Devicename2));
    		APP_ERROR_CHECK(err_code);
    
    	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);
            ble_advertising_restart_without_whitelist(&m_advertising);
                     
    }
    

    Check this function also. Thanks. 

  • Do you see any issue with your functions?

    -Amanda H. 

Related