how to change the device name by ble_app

hi ... i want to change the device name by using our customized nrf toolbox , user will entry the name of device , so that particular name should with the previous name (nRF5X) ..How to do that ?

 i tried by copying the received data to device name (strcpy (device_name , user_name) , the name is not changing . i have seen multiple threads, none of them work out

suggest me 

Parents
  • Hi,

    To update the device name via BLE you need to do the following:

    • Call sd_ble_gap_device_name_set() with the new name
    • Update the advertising set with new advertising data to use the new name.
    • If you want this to be persistent, you also need to write it to flash and read it back and use that when you set the advertising name after reset.

    Note that the phones cache the advertising name, so you will not necessarily see the new name on an existing phone unless you delete the bond, toggle Bluetooth off and on, and pair again (or similar).

  • Hi ,Einar 

    How to update the advertising set with new advertising data to use the new name ?

    Best Regards ,

    pspavi

  • Hi,

    ps_anu said:
    How to update the advertising set with new advertising data to use the new name ?

    You initialize the advertising set in the same way as you did originally. Essentially you do the exact same thing as before you called sd_ble_gap_device_name_set() with the new name. You can refer to the example Jimmy posted, or for instance this post.

  • I have seen the example , but i am not getting . 

    static void gap_params_init(void)
    {
        uint32_t                err_code;
        ble_gap_conn_params_t   gap_conn_params;
        ble_gap_conn_sec_mode_t sec_mode;
    
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
    
        err_code = sd_ble_gap_device_name_set(&sec_mode,
                                              (const uint8_t *) DEVICE_NAME,
                                              strlen(DEVICE_NAME));
        APP_ERROR_CHECK(err_code);
    
     
    
    
        
        err_code = sd_ble_gap_device_name_set(&sec_mode,
                                              (const uint8_t *)RECEIVED_NEW_NAME,
                                              strlen(RECEIVED_NEW_NAME));
        APP_ERROR_CHECK(err_code);
    
        memset(&gap_conn_params, 0, sizeof(gap_conn_params));
    
        gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL;
        gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL;
        gap_conn_params.slave_latency     = SLAVE_LATENCY;
        gap_conn_params.conn_sup_timeout  = CONN_SUP_TIMEOUT;
    
        err_code = sd_ble_gap_ppcp_set(&gap_conn_params);
        APP_ERROR_CHECK(err_code);
    }

    I want to change the device name by receiving the device name in uart , i want to replace it with new device name which is entered manually. please tel me , above code i tried . it is not changing 

  • Hi,

    you need to disconnect the ble link and stop the advertising first if you need to change the device name.

    Please run the code on my example to see how it works.

    static void gap_params_init(bool load_setting)
    {
            uint32_t err_code;
            ble_gap_conn_params_t gap_conn_params;
            ble_gap_conn_sec_mode_t sec_mode;
    
            BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
    
            if (load_setting)
            {
                    if (m_ble_config)
                    {
                            err_code = sd_ble_gap_device_name_set(&sec_mode,
                                                                  m_ble_config->dev_name.name,
                                                                  strlen((const char *)m_ble_config->dev_name.name));
                            APP_ERROR_CHECK(err_code);
                            NRF_LOG_INFO("gap_params device name = %s", m_ble_config->dev_name.name);
                    }
            }
            else
            {
                    err_code = sd_ble_gap_device_name_set(&sec_mode,
                                                          (const uint8_t *) DEVICE_NAME,
                                                          strlen(DEVICE_NAME));
                    APP_ERROR_CHECK(err_code);
            }
    
            memset(&gap_conn_params, 0, sizeof(gap_conn_params));
            if (load_setting)
            {
    
                    gap_conn_params.min_conn_interval = m_ble_config->conn_params.min_conn_int;
                    gap_conn_params.max_conn_interval = m_ble_config->conn_params.max_conn_int;
                    gap_conn_params.slave_latency     = m_ble_config->conn_params.slave_latency;
                    gap_conn_params.conn_sup_timeout  = m_ble_config->conn_params.sup_timeout;
            }
            else
            {
                    gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL_MS;
                    gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL_MS;
                    gap_conn_params.slave_latency     = SLAVE_LATENCY;
                    gap_conn_params.conn_sup_timeout  = CONN_SUP_TIMEOUT_MS;
            }
            err_code = sd_ble_gap_ppcp_set(&gap_conn_params);
            APP_ERROR_CHECK(err_code);
    
            ble_gap_addr_t ble_address = {.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC,
                                          .addr_id_peer = 0,
                                          .addr = {0xC3,0x11,0x99,0x33,0x44,0xFF}};
            err_code = sd_ble_gap_addr_set(&ble_address);
    }
    

  • If I disconnected then how I will enter the data in ble_app_uart 

Reply Children