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

chnage adv name on push btn event

hi, i am doing a project where i have to change adv name of ble device.

i am using nrf sdk 15.3.0 ble_app_blinky example for pca 10040e because it has all the things i need ble adv name and push btn driver.

i have modified the code that app_button_enable();  will be always active.

so now on push btn event i have to change adv name of the device.

here is the code snippet which will be called by the push btn event handler and i also changed to GPIOTE_CONFIG_IN_SENSE_LOTOHI interrupt type.

void name_change(void)
{
    ret_code_t err_code;
    ble_gap_conn_sec_mode_t sec_mode;
    
    (void)sd_ble_gap_adv_stop(m_adv_handle);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);

      err_code = sd_ble_gap_device_name_set(&sec_mode,
                                            (const uint8_t *)DEVICE_NAME1,
                                             strlen(DEVICE_NAME1));
    APP_ERROR_CHECK(err_code);
    advertising_init();
    advertising_start();
}

but problem which i am facing is that i am not able to change adv name which has more string length then the adv name which is previously advertised

for eg,

initial adv name is "blinky_test"

new adv name is "new_blinky_test"

then in this case the name is advertise as "new_blinky_"

but when i used shorter name then original adv name it worked fine but new problem is that when i go back to original adv name from here it is taking last adv name's length.

for eg.

initial adv name is "blinky_test"

new adv name is "new_blink"

if we go back to "blinky_test" then the new name which is adv is "blinky_te"

 

please help me to figure out what i am doing wrong. 

Related