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

Adding a Custom service to the HID keyboard service [Advertising Issue]

Hi,

We're trying to add a custom service to the HID keyboard example. the service is initialized we can see the service when connected to the device from the nrfConnect app. but not in the adverting packet. we only see the HID service !

When using our phone app, in where we scan for a specific service UUID (custom service) the app can't find the device, but when scanning for hid service, the app can find it.

static ble_uuid_t m_adv_uuids[] = {

   {BLE_UUID_HUMAN_INTERFACE_DEVICE_SERVICE, BLE_UUID_TYPE_BLE}
  // {SM_SERVICE_UUID, BLE_UUID_TYPE_VENDOR_BEGIN}
              
};

using only the Custom service in the m_adv_uuids[], makes the ble_advertising_init(&m_advertising, &init);  return and error ( INVALID PARAMETER ) .

/**@brief Function for initializing the Advertising functionality.
 */
static void advertising_init(void)
{
    uint32_t               err_code;
    uint8_t                adv_flags;
    ble_advertising_init_t init;

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

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

    //int8_t tx_power                      = -4;// Set Power Level
    //init.advdata.p_tx_power_level        = &tx_power;

    init.config.ble_adv_whitelist_enabled          = false;
    init.config.ble_adv_directed_high_duty_enabled = true;
    init.config.ble_adv_directed_enabled           = false;
    init.config.ble_adv_directed_interval          = 0;
    init.config.ble_adv_directed_timeout           = 0;
    init.config.ble_adv_fast_enabled               = true;
    init.config.ble_adv_fast_interval              = APP_ADV_FAST_INTERVAL;
    init.config.ble_adv_fast_timeout               = APP_ADV_FAST_DURATION;
    init.config.ble_adv_slow_enabled               = false;
    init.config.ble_adv_slow_interval              = APP_ADV_SLOW_INTERVAL;
    init.config.ble_adv_slow_timeout               = APP_ADV_SLOW_DURATION;

    init.evt_handler   = on_adv_evt;
    init.error_handler = ble_advertising_error_handler;

    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);
}

note: we did set the  NRF_SDH_BLE_VS_UUID_COUNT 1  , in the sdk_config file !

What we need to achieve, is to have that Custom service advertised. and not affecting the the HID service, meaning the host will still can see this device as a Hid device !

Thanks in advance,

best regards,

Abdelali

Parents
  • Hi Abdelali

    I see. What is happening here is that you don't have room for both service UUIDs in your advertising packet. The SM_SERVICE_UUID is 128 bit (16 bytes) long, which means it takes up more than half of the advertising packet, which is 31 byte, where 2 are overhead by default. In order to add this custom service, you should fit it into the scan response data instead of the advertising packet. You can take a look at I.E. the BLE app blinky example to see how a scan response is added to your advertising.

    Best regards,

    Simon

Reply
  • Hi Abdelali

    I see. What is happening here is that you don't have room for both service UUIDs in your advertising packet. The SM_SERVICE_UUID is 128 bit (16 bytes) long, which means it takes up more than half of the advertising packet, which is 31 byte, where 2 are overhead by default. In order to add this custom service, you should fit it into the scan response data instead of the advertising packet. You can take a look at I.E. the BLE app blinky example to see how a scan response is added to your advertising.

    Best regards,

    Simon

Children
Related