Custom service is advertised with NUS base UUID

Dear all,

I use nRF52840 custom board with nRF52 SDK and I want to advertise two more services:

  • one custom service (0x1523)
  • one battery service (0x180F)

and read them through my mobile with nRF Connect app.

I experiment with the ble_app_uart example (since I want to stream various data after connection with the mobile).

The problem is that the custom service, although it is advertised along with the battery service and the Nordic Uart Service (NUS),
it does not have the 128 bit UUID that I set to it but instead it gets the UUID of the NUS as you can see in the following image.

Obviously I am doing something wrong here but I can't figure out what it is...

Here are the changes  that I have performed in main.c. First I added the custom service UUID  in the list along with its type (128bit)

#define CUSTOM_UUID_BASE {0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15, 0xEF, 0xD6, 0x31, 0xBE, 0x00, 0x00, 0x15, 0x16}
#define CUSTOM_SERVICE_UUID 0x1523

static ble_uuid_t m_adv_uuids[]   =                                  
{
   {BLE_UUID_NUS_SERVICE, NUS_SERVICE_UUID_TYPE},
   {BLE_UUID_BATTERY_SERVICE, BLE_UUID_TYPE_BLE},
   {CUSTOM_SERVICE_UUID, BLE_UUID_TYPE_VENDOR_BEGIN}
};

and then I enabled init.config.ble_adv_extended_enabled flag in advertising_init()

static void advertising_init(void)
{
    uint32_t err_code;
    ble_advertising_init_t init;

    memset(&init, 0, sizeof(init));

    init.advdata.name_type          = BLE_ADVDATA_FULL_NAME;
    init.advdata.include_appearance = true;
    init.advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;  //BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_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;
    

    //init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    //init.srdata.uuids_complete.p_uuids  = m_adv_uuids;

    init.config.ble_adv_extended_enabled = true;
    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);
}

Parents
  • Hi,

    In order to get the correct base UUID you need to register it with sd_ble_uuid_vs_add(). And when you do, the second parameter is an output, and this is the type you need to use when you subsequently refer to it (this is a counter though, so if the base used by NUS is added first this will be 2 (BLE_UUID_TYPE_VENDOR_BEGIN), and your will be 3, so you can use this as well, but then things will break if the order you register the base addresses change).

  • Update: I added the following code in services_init(), in sdk_config I set NRF_SDH_BLE_VS_UUID_CNT to 2 and updated the ram size but the result is the same again.

        ret_code_t  err_code;
        ble_uuid_t ble_uuid;
        uint16_t service_handle;
        uint8_t  uuid_type = 0;
    
        ble_uuid128_t base_uuid = CUSTOM_UUID_BASE;
        err_code = sd_ble_uuid_vs_add(&base_uuid, &uuid_type);
        if (err_code != NRF_SUCCESS) {
          NRF_LOG_INFO("CUSTOM SERVICE ERROR %X| UUID TYPE: %X",err_code ,uuid_type);
        }
        NRF_LOG_INFO(" UUID TYPE: %X",uuid_type);  // returns 3
    
        ble_uuid.type = uuid_type;
        ble_uuid.uuid = CUSTOM_SERVICE_UUID;   //0x1523
    
        // Add the service.
        err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
                                            &ble_uuid,
                                            &service_handle);
       
        if (err_code != NRF_SUCCESS) {
            NRF_LOG_INFO("CUSTOM SERVICE ERROR %X| SERVICE HANDLE: %X",err_code ,service_handle);
        }
        NRF_LOG_INFO("SERVICE HANDLE: %X",service_handle); //returns 11

Reply
  • Update: I added the following code in services_init(), in sdk_config I set NRF_SDH_BLE_VS_UUID_CNT to 2 and updated the ram size but the result is the same again.

        ret_code_t  err_code;
        ble_uuid_t ble_uuid;
        uint16_t service_handle;
        uint8_t  uuid_type = 0;
    
        ble_uuid128_t base_uuid = CUSTOM_UUID_BASE;
        err_code = sd_ble_uuid_vs_add(&base_uuid, &uuid_type);
        if (err_code != NRF_SUCCESS) {
          NRF_LOG_INFO("CUSTOM SERVICE ERROR %X| UUID TYPE: %X",err_code ,uuid_type);
        }
        NRF_LOG_INFO(" UUID TYPE: %X",uuid_type);  // returns 3
    
        ble_uuid.type = uuid_type;
        ble_uuid.uuid = CUSTOM_SERVICE_UUID;   //0x1523
    
        // Add the service.
        err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
                                            &ble_uuid,
                                            &service_handle);
       
        if (err_code != NRF_SUCCESS) {
            NRF_LOG_INFO("CUSTOM SERVICE ERROR %X| SERVICE HANDLE: %X",err_code ,service_handle);
        }
        NRF_LOG_INFO("SERVICE HANDLE: %X",service_handle); //returns 11

Children
Related