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

NRF_ERROR_INVALID_LENGTH when setting 10 chars device name

I use sd_ble_gap_device_name_set to set 10 chars device name 

then getting NRF_ERROR_INVALID_LENGTH  in sd_ble_gap_adv_set_configure.

all OK when tested 3 chars device name .

ret_code_t ret;
ble_gap_adv_params_t adv_params = get_adv_params();

adv_params.duration = flash_adv_params.adv_duration_sec*1000/10;

ble_gap_conn_sec_mode_t sec_mode;
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
char unitName[DEVICE_NAME_MAX_LEN];
device_info_get_unit_name(&unitName);


ret = sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *)unitName, (uint16_t)strlen(unitName));
APP_ERROR_CHECK(ret);


advertise_whitelist_clear();
NRF_LOG_DEBUG("Setting adv params PHY to 1M. ");
adv_params.primary_phy = BLE_GAP_PHY_1MBPS;
adv_params.secondary_phy = BLE_GAP_PHY_1MBPS;
adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
ret = ble_advdata_encode(&adv_data, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
APP_ERROR_CHECK(ret);
ret = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &adv_params);
APP_ERROR_CHECK(ret);

Parents
  • I am running into a similar issue with SDK 16.0.0 on my nRF52 device.

    My advertisement packet is only 27 bytes (including all the protocol required fields, etc.) so there are 4 more bytes available to the SoftDevice to use.
    I set the name to have 11 characters (and the 12th is a NULL byte).
    I call sd_ble_gap_device_name_set() with the 16 byte array with the first 11 bytes populated by the name, and the 12th byte onwards is all NULL.
    I pass in the 'len' parameter as 11 (since I only want to broadcast the first 11 bytes of the name)

    The call succeeds but it only broadcasts the first 10 bytes (almost as if it is treating the last byte as the NULL termination, even though the comments in the header ask for the NON-NULL terminated length of the character array).

    RMV

  • Sorry, but I was wrong. It looks like a newly added service descriptor takes up additional bytes.
    This seemed to be limiting the number of bytes left over for the full name.

    RMV

Reply Children
No Data
Related