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

Can't change device name nrf_dfu_ble.c

Now I'm trying to change a device name in `nrf_dfu_ble.c`. I set NRF_DFU_BLE_ADV_NAME like following.

#define NRF_DFU_BLE_ADV_NAME "SPB"

And I imported `stdio.h`, `string.h`. And I edited `gap_params_init` function of `nrf_dfu_ble.c` like following.

static uint32_t gap_params_init(void)
{
    uint32_t err_code;
    ble_gap_conn_sec_mode_t sec_mode;
    uint8_t const *device_name;
    uint32_t name_len;

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);

#if (!NRF_DFU_BLE_REQUIRES_BONDS)

    err_code = gap_address_change();
    VERIFY_SUCCESS(err_code);

    if ((m_flags & DFU_BLE_FLAG_USE_ADV_NAME) != 0)
    {
        NRF_LOG_DEBUG("Setting adv name: %s, length: %d", m_adv_name.name, m_adv_name.len);
        device_name = m_adv_name.name;
        name_len = m_adv_name.len;
    }
    else
#endif
    {
        NRF_LOG_DEBUG("Using default advertising name");
        // device_name = (uint8_t const *)(NRF_DFU_BLE_ADV_NAME);
        // name_len = strlen(NRF_DFU_BLE_ADV_NAME);

        ble_gap_addr_t addr;

        err_code = sd_ble_gap_addr_get(&addr);
        VERIFY_SUCCESS(err_code);

        char name[strlen(NRF_DFU_BLE_ADV_NAME) + 4];

        sprintf(name, "%s%02X%02X", NRF_DFU_BLE_ADV_NAME, addr.addr[1], addr.addr[0]);
        
        device_name = (uint8_t const *)name;
        name_len = sizeof name;
    }

    err_code = sd_ble_gap_device_name_set(&sec_mode, device_name, name_len);
    VERIFY_SUCCESS(err_code);

    err_code = sd_ble_gap_ppcp_set(&m_gap_conn_params);
    return err_code;
}

I succeeded to build and download a bootloader project that includes `nrf_dfu_ble.c`.

But the device is not working.

What should I do for it?

Parents
  • Hello,

    If you want to change the advertising name for the bootloader, you should only need to change NRF_DFU_BLE_ADV_NAME inside sdk_config.h of your bootloader project.

    It is probably possible to do it similar to what you are doing as well, but probably, one of the err_code returned non-zero, and the error handler picked it up, resetting the bootloader.

    If you want to dig into why it doesn't work, you should use the debug equivalent of the project you are now using, so I would guess the pca10040e_s112_ble_debug project folder in your case, and then monitor the log output.

    Best regards,

    Edvin

Reply
  • Hello,

    If you want to change the advertising name for the bootloader, you should only need to change NRF_DFU_BLE_ADV_NAME inside sdk_config.h of your bootloader project.

    It is probably possible to do it similar to what you are doing as well, but probably, one of the err_code returned non-zero, and the error handler picked it up, resetting the bootloader.

    If you want to dig into why it doesn't work, you should use the debug equivalent of the project you are now using, so I would guess the pca10040e_s112_ble_debug project folder in your case, and then monitor the log output.

    Best regards,

    Edvin

Children
Related