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

nRF52 returning error code 7 when trying to set proprietary UUID in advertising data

I'm using the nRF52 + SDK11.0.0 + s132. I started with the ble_hrs example and modified it. I now want to make the service/characteristics use proprietary UUIDs and I'm following the ble_app_uart example. I set the uuid array as follows:

static ble_uuid_t                       m_adv_uuids[] = {{BLE_UUID_PROPRIETARYSERVICE, BLE_UUID_TYPE_VENDOR_BEGIN}};

and call

static void advertising_init(void)
{
uint32_t      err_code;
ble_advdata_t advdata;
ble_advdata_t scanrsp;

// Build advertising data struct to pass into @ref ble_advertising_init.
memset(&advdata, 0, sizeof(advdata));

advdata.name_type               = BLE_ADVDATA_FULL_NAME;
advdata.include_appearance      = true;		// set in gap_params_init()
advdata.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    //	advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    //	advdata.uuids_complete.p_uuids  = m_adv_uuids;

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

ble_adv_modes_config_t options = {0};
options.ble_adv_fast_enabled  = BLE_ADV_FAST_ENABLED;
options.ble_adv_fast_interval = APP_ADV_INTERVAL;
options.ble_adv_fast_timeout  = APP_ADV_TIMEOUT_IN_SECONDS;

err_code = ble_advertising_init(&advdata, &scanrsp, &options, on_adv_evt, NULL);
//err_code = ble_advertising_init(&advdata, NULL, &options, on_adv_evt, NULL);
APP_ERROR_CHECK(err_code);
}

This returnx 0x7 in sd_ble_uuid_encode():

static uint32_t uuid_list_sized_encode(const ble_advdata_uuid_list_t * p_uuid_list,
                                   uint8_t                         adv_type,
                                   uint8_t                         uuid_size,
                                   uint8_t                       * p_encoded_data,
                                   uint16_t                      * p_offset,
                                   uint16_t                        max_size)
{
int      i;
bool     is_heading_written = false;
uint16_t start_pos          = *p_offset;
uint16_t length;

for (i = 0; i < p_uuid_list->uuid_cnt; i++)
{
    uint32_t   err_code;
    uint8_t    encoded_size;
    ble_uuid_t uuid = p_uuid_list->p_uuids[i];
    
    // Find encoded uuid size.
    err_code = sd_ble_uuid_encode(&uuid, &encoded_size, NULL);
    VERIFY_SUCCESS(err_code);
   ...
 }

What is the issue? I saw this thread, but it doesn't spell out the answer...

  • Why don't you look at the documentation for sd_ble_uuid_encode() which gives the error codes. That tells you the parameter is invalid, so you've passed an invalid UUID.

    As the thread you liked to tell you, don't use BLE_UUID_TYPE_VENDOR_BEGIN, but you have done exactly that. Most likely you haven't actually registered your custom UUID with sd_ble_uuid_vs_add() or you haven't used the result of that function.

  • In ble_app_uart, services_init() is called before advertising_init(). Hence sd_ble_uuid_vs_add() with the PROPRIETARY_BASE_UUID is called before advertising_init(). This is not the case in ble_hrs, so I got the error.

  • I didn't ask for what the error code was; I asked for why I was getting the error. I am not sure why that thread says not to use BLE_UUID_TYPE_VENDOR_BEGIN when the ble_app_uart example does exactly that. Anyhow, the clue was sd_ble_uuid_vs_add() not being called in the proper sequence, since the ble_hrs example and ble_app_uart example call these in different orders and I did not catch that until your post.

Related