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

Trying to advertise the shotend name not the complete name

I am trying to advertise the shotend name of the device no the complete local name, so code looks like follow

#define DEVICE_NAME                     "DEVK"

/**@brief Function for the GAP initialization.
 *
 * @details This function sets up all the necessary GAP (Generic Access Profile) parameters of the
 *          device including the device name, appearance, and the preferred connection parameters.
 */
void gap_params_init(void)
{
    ret_code_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_appearance_set(BLE_APPEARANCE_UNKNOWN);
    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);
}



void advertising_init(void)
{
    ret_code_t err_code;
    uint32_t adv_value = 0;
    ble_advertising_init_t init;
    ble_advdata_manuf_data_t manuf_data; //Variable to hold manufacturer specific data
    uint8_t manufacture_data[5];

    adv_value = APP_ADV_DURATION_FOREVER;
    memset(&init, 0, sizeof(init));

    init.advdata.name_type = BLE_ADVDATA_SHORT_NAME; // BLE_ADVDATA_FULL_NAME, BLE_ADVDATA_SHORT_NAME, BLE_ADVDATA_NO_NAME
    init.advdata.short_name_len = strlen(DEVICE_NAME);
    init.advdata.include_appearance = true;
    init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    // init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    // init.advdata.uuids_complete.p_uuids = m_adv_uuids;
    manuf_data.company_identifier = 0x0059;                 //Nordics company ID
    memcpy(manufacture_data, device_configuration.serial_number, SERIAL_BYTES_LEN);

    NRF_LOG_GREEN("Manfacture data on advertising packets:");
    nrf_log_hex(manufacture_data, sizeof(manufacture_data), COLOR_GREEN);

    NRF_LOG_GREEN("Advertising frequency = %d msec", adv_value);

    manuf_data.data.p_data = manufacture_data;
    manuf_data.data.size = sizeof(manufacture_data);

    // Advertising Packet
    init.advdata.p_manuf_specific_data = &manuf_data;

    // Scan Response
    // init.srdata.p_manuf_specific_data = &manuf_data;

    init.config.ble_adv_fast_enabled = true;
    init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
    init.config.ble_adv_fast_timeout = (adv_value / 10);

    init.evt_handler = on_adv_evt;

    err_code = ble_advertising_init(&m_advertising, &init);
    APP_ERROR_CHECK(err_code);

    ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
}

After scanning I can still find the name in the advertisement packet is the complete local name, not sure what I am doing wrong 

Parents Reply Children
  • I am using sdk ver 17.0.2

    device name as shown is DEVK, I traced the low level functions after settings the name sd_ble_gap_device_name_set as I show on the code up there, then calling sd_ble_gap_device_name_get the length of the string is still 0.

    I checked also bytes of the advertising on nrf52 I can see, it is advertising 0x09 (complete local name), not 0x08 (shortend name).

    I debugged low level functions on softdevice and found that I have to make sure when I call sd_ble_gap_device_name_set  I have to pass full name only, and shortname has to be part of this name, this is the only way it works, so length of full name can't be same as length of short name.

Related