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

Device name advertises for short name even after setting for full name.

Hello,

I have set the device advertising as follows: 

static void advertising_init(void)
{
    ret_code_t           err_code;
    ble_advdata_t        advdata;
    ble_advdata_t        srdata;
    ble_gap_adv_params_t adv_params;


    ble_uuid_t adv_uuids[] = {{LBS_UUID_SERVICE, m_lbs.uuid_type}};

    // Build and set advertising data.
    memset(&advdata, 0, sizeof(advdata));

    advdata.name_type          = BLE_ADVDATA_FULL_NAME;
    advdata.include_appearance = true;
    advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;


    memset(&srdata, 0, sizeof(srdata));
    srdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
    srdata.uuids_complete.p_uuids  = adv_uuids;

    err_code = ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
    #ifdef DEBUG
     printf("ble_advdata_encode%d\n",err_code);
    #endif
    APP_ERROR_CHECK(err_code);

    err_code = ble_advdata_encode(&srdata, m_adv_data.scan_rsp_data.p_data, &m_adv_data.scan_rsp_data.len);
    #ifdef DEBUG
     printf("ble_advdata_encodesrdata%d\n",err_code);
    #endif
    APP_ERROR_CHECK(err_code);

    // Start advertising.
    memset(&adv_params, 0, sizeof(adv_params));
    adv_params.p_peer_addr   = NULL;
    adv_params.filter_policy = BLE_GAP_ADV_FP_ANY;
    adv_params.interval      = APP_ADV_INTERVAL;

    adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
    adv_params.duration        = APP_ADV_DURATION;
    adv_params.primary_phy     = BLE_GAP_PHY_1MBPS;

    err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &adv_params);
    #ifdef DEBUG
     printf("sd_ble_gap_adv_set_configure%d\n",err_code);
    #endif
    APP_ERROR_CHECK(err_code);
}

Advertising name is getting broadcasted with a full name until it gets changed and to 4 letters device name. In my application, there is a need for changing the advertising name for 5 min duration and that name is of 4 characters only. That gets advertised successfully. But the problem arises after again changing to the first advertising name, which has more than 4 letters. It does not get advertised with full name only the first 4 characteristics get advertised. 

Advertising init function is used every time I changed the advertising name which has full name advertising settings. My first name is "LED_BUTTON"(10 characters) and the second name is "TEST"(4 characters). I want to switch the first name with 2nd for 5 min and again to first. Below code shows how i have changed name:

ret_code_t err_code = sd_ble_gap_adv_stop(m_adv_handle);
        APP_ERROR_CHECK(err_code);
        err_code = sd_ble_gap_device_name_set(&sec_mode,(const uint8_t *)DEVICE_NAME,strlen(DEVICE_NAME));
        APP_ERROR_CHECK(err_code);
        advertising_init();
        err_code = sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG);
        APP_ERROR_CHECK(err_code);

What should i do for advertising with full name after changing advertising name dynamucally in code for 5 min. 

  • Hi

    Do you set the name type as SHORT_NAME when you change the name to TEST? If so, can you try keeping it as FULL_NAME to see if that lets you get the full first name again? Does the advertisement itself change when it's called LED_BUTTON the first time versus after the name has changed once and twice? It might be that the advertising packet is filled with something else the third time around, not leaving any space for the full name to be advertised.

    Best regards,

    Simon

  • Do you set the name type as SHORT_NAME when you change the name to TEST?

    NO, I am using the same advertising_init(); function for setting advertising parameters. 

    t might be that the advertising packet is filled with something else the third time around, not leaving any space for the full name to be advertised.

    How to know an advertising packet is getting filled with some data that no space for advertising full name.?

  • Hi

    Are there any other parameters in your advertising data that are changing when you update the device name? You should be able to read the encoded advertising data in &advdata after ble_advdata_encode() is called. This will be in ASCII format if I'm not mistaken so you'll have to decode it to see what it actually is. 

    There's a couple of things I can think of that could cause this. What device/platform are you receiving this advertising data on? If it's a phone, it might not be able to read the new name properly after the device_name change. You can also try adding a reset of the device between the advertising inits, to make sure that everything is erased and starts off properly.

    Best regards,

    Simon

  • I am using SDK v15.3.0 and I found a solution (more like a hack) to rationalize this strange behavior and work around it.
    This is so frustrating!!!

    The hack is in three parts:
    1) Use a customized manufacturer/vendor packet that expands to cover the entire 31-byte available size.
    2) Pick a device name such that adding ALL the characters in that name OVERFLOWS the 31-byte limit.
    3) Tell the Nordic SDK that the size of the short name is "1 less than it actually is" i.e. if you chose the device name as "NORDIC" then you should specify the short name lenght to be 5 (1 less than the number of characters in NORDIC)

    Hope this helps.

Related