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

The influence of Bluetooth name and setting tx power level in nRF52832

Hello,

When I set the tx power in the broadcast initialization, I found that there are restrictions on the setting of the Bluetooth name, as follows

My device name:

Then I saw the bluetooth information in the phone as follows

But comment out the code to set the tx power, the name of the Bluetooth device can be fully displayed

Mobile phone display:

What is the reason?

Parents
  • Hello,

    This is likely cause by the 31 advertising byte limit being exceeded when you add the TX data field.
    Including the TX data increases the payload size, which might cause it to exceed the hard 31 byte limit. The ble_advdata_encode function will then truncate the advertising name - by shaving characters off of the name - in order to make it fit into the 31 byte limit. Please see the warning of the ble_advdata_encode function's API reference for more information about this.

    Best regards,
    Karl

  • /** * @brief Function for initializing the Advertising functionality. */ static void advertising_init(void) { uint32_t err_code; ble_advdata_t addata; ble_advertising_init_t init; int8_t tx_power_level = TX_POWER_LEVEL; memset(&init, 0, sizeof(init)); init.advdata.name_type = BLE_ADVDATA_FULL_NAME; init.advdata.include_appearance = false; init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE; init.advdata.p_tx_power_level = &tx_power_level; init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]); init.srdata.uuids_complete.p_uuids = m_adv_uuids; uint8_t my_adv_manuf_data[6] = {0}; memcpy(my_adv_manuf_data, "123456", 6); ble_advdata_manuf_data_t manuf_specific_data; manuf_specific_data.company_identifier = 0x0059; manuf_specific_data.data.p_data = my_adv_manuf_data; manuf_specific_data.data.size = sizeof(my_adv_manuf_data); init.advdata.p_manuf_specific_data = &manuf_specific_data; init.config.ble_adv_fast_enabled = true; init.config.ble_adv_fast_interval = APP_ADV_INTERVAL; init.config.ble_adv_fast_timeout = APP_ADV_DURATION; init.evt_handler = on_adv_evt; m_advertising.adv_data.adv_data.len = 64; 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); }

    I tried to add ble_advdata_encode() and the software restarts indefinitely

  • Hello again,

    Please use the Insert -> Code option when sharing code here on DevZone. The code you have posted above is not readable without considerable effort.

    Mikey said:
    I tried to add ble_advdata_encode() and the software restarts indefinitely

    This sounds like a non-NRF_SUCCESS error code is passed to an APP_ERROR_CHECK somewhere. Could you make sure to have DEBUG defined in your preprocessor defines, like shown in the included image?


    This will make your logger output a detailed error message whenever a non-NRF_SUCCESS error code is passed to an APP_ERROR_CHECK.

    Were you not already calling ble_advdata_encode previously, before configuring the advertising data? Which example are you using as the base of your project?

    Best regards,
    Karl

  • /**
     * @brief Function for initializing the Advertising functionality.
     */
    static void advertising_init(void)
    {
        uint32_t               err_code;
        ble_advertising_init_t init;
        int8_t tx_power_level = TX_POWER_LEVEL;
    
        memset(&init, 0, sizeof(init));
    
        init.advdata.name_type          = BLE_ADVDATA_FULL_NAME;
        init.advdata.include_appearance = false;
        init.advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
        init.advdata.p_tx_power_level 	= &tx_power_level;
    
        init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
        init.srdata.uuids_complete.p_uuids  = m_adv_uuids;
    
        uint8_t my_adv_manuf_data[6] = {0};
        memcpy(my_adv_manuf_data, "123456", 6);
        ble_advdata_manuf_data_t manuf_specific_data;
        manuf_specific_data.company_identifier = 0x0059;
        manuf_specific_data.data.p_data = my_adv_manuf_data;
        manuf_specific_data.data.size   = sizeof(my_adv_manuf_data);
        init.advdata.p_manuf_specific_data = &manuf_specific_data;
    
        init.config.ble_adv_fast_enabled  = true;
        init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
        init.config.ble_adv_fast_timeout  = APP_ADV_DURATION;
        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);
    }

    Sorry, I tried it yesterday but it didn't work, but today I learned that the browser plug-in affected the insertion of my code. I also added a 6-digit random key to the broadcast data

  • Mikey said:
    Sorry, I tried it yesterday but it didn't work, but today I learned that the browser plug-in affected the insertion of my code.

    No worries at all, thank you for formatting the code and making it readable! :) 

    So, back to your issue; I still believe that it is caused by the advertising data exceeding the 31 byte advertising payload limit.
    What is the total size of your advertising packet, with the above code?
    Please also keep in mind that every new datafield (i.e name, uuid's, appearance, manufacturer specific, etc) requires 2 bytes of overhead. So, if you have a 8 byte manufacturing specific data payload(2 bytes company identifier, and 6 bytes arbitrary data), it will take up 10 bytes of your total 31 available bytes.

    Did you add the DEBUG define to your preprocessor defines like I asked?
    If so, are you getting any error messages in your logger when this behavior occurs?

    Best regards,
    Karl

Reply
  • Mikey said:
    Sorry, I tried it yesterday but it didn't work, but today I learned that the browser plug-in affected the insertion of my code.

    No worries at all, thank you for formatting the code and making it readable! :) 

    So, back to your issue; I still believe that it is caused by the advertising data exceeding the 31 byte advertising payload limit.
    What is the total size of your advertising packet, with the above code?
    Please also keep in mind that every new datafield (i.e name, uuid's, appearance, manufacturer specific, etc) requires 2 bytes of overhead. So, if you have a 8 byte manufacturing specific data payload(2 bytes company identifier, and 6 bytes arbitrary data), it will take up 10 bytes of your total 31 available bytes.

    Did you add the DEBUG define to your preprocessor defines like I asked?
    If so, are you getting any error messages in your logger when this behavior occurs?

    Best regards,
    Karl

Children
Related