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);
}

Parents
  • 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.  

Reply
  • 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.  

Children
Related