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

HID Keyboard + Custom GATT

Hi,

I'm using SDK 15.2 & trying to combine hid keyboard with custom gatt service, but it was not advertising. When I debug, it got stuck on the line below with error code 12-

err_code = sd_ble_gap_device_name_get(&p_encoded_data[(*p_offset) + AD_DATA_OFFSET],
                                          &actual_length);
    VERIFY_SUCCESS(err_code);

& the rtt logs showed

ble_app_hids_keyboard_custom.zip

So after going through several tickets, I changed -

init.advdata.include_appearance from true to false, & I could see the device name being advertised as 'Nord'.

How do I advertise full name?

I plan to use HID service with custom gatt & DFU service. How should I tackle the advertising data? Should I remove other services which come along with HID service like the battery service & device info service?

By referring https://devzone.nordicsemi.com/nordic/short-range-guides/b/bluetooth-low-energy/posts/ble-advertising-a-beginners-tutorial & other tickets, I tried adding

static ble_uuid_t m_adv_uuids_new[] = {{CUSTOM_SERVICE_UUID, BLE_UUID_TYPE_VENDOR_BEGIN }};
init.srdata.uuids_more_available.uuid_cnt = sizeof(m_adv_uuids_new) / sizeof(m_adv_uuids_new[0]);
init.srdata.uuids_more_available.p_uuids = m_adv_uuids_new;

OR

static ble_uuid_t m_adv_uuids_new[] = {{CUSTOM_SERVICE_UUID, BLE_UUID_TYPE_VENDOR_BEGIN }};
init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids_new) / sizeof(m_adv_uuids_new[0]);
init.srdata.uuids_complete.p_uuids = m_adv_uuids_new;

but didnt work.

Parents
  • Hi. 

    It seems that your advertising packet is full, that is why you are seeing the shortened "Nord" advertising name. 

    Note that the advertising packet will only fit 31 bytes of data. 

    Best regards, 
    Joakim

  • Yes  know but according to https://devzone.nordicsemi.com/nordic/short-range-guides/b/bluetooth-low-energy/posts/ble-advertising-a-beginners-tutorial, there seems to be a workaround to extend the packet to 62 bytes. Can you please help me with that, that is what I was asking in my question above

  • Ok, I misunderstood your question.

    Could you please upload your advertising_init() function so that I can see how you tried adding the scan response data.

    Best regards,
    Joakim

  • 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;
        init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
        init.advdata.uuids_complete.p_uuids  = m_adv_uuids;
    	
    	/*new*/
    	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;
    	
        advertising_config_get(&init.config);
        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);
    }
    ble_app_buttonless_dfu_custom.zip

    I have also attached the full code.

    Also what adjustments do I need to make in advertising data for the full device name to be visible with custom gatt & dfu service? I removed the hid service.

    Thanks.

  • 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;
        init.advdata.uuids_complete.uuid_cnt = 1;//sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
        //init.advdata.uuids_complete.p_uuids  = m_adv_uuids;
    	init.advdata.uuids_complete.p_uuids  = &m_adv_uuids[0];
    	/*new*/
    	init.srdata.name_type               = BLE_ADVDATA_NO_NAME;
    	init.srdata.uuids_complete.uuid_cnt = 1;//sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    	init.srdata.uuids_complete.p_uuids  = &m_adv_uuids[1];
    	/*new*/
    	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.config.ble_adv_extended_enabled = true;
    	
        advertising_config_get(&init.config);
        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);
    }

    This seems to work. 

    Is this

    init.config.ble_adv_extended_enabled = true;

    required?

    What if I wanted to add

    1. Custom gatt service

    2. HID service

    3. DFU service

    , how do I add all of these to advertisement packet?

    Should the uuids_more_available be used?

Reply
  • 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;
        init.advdata.uuids_complete.uuid_cnt = 1;//sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
        //init.advdata.uuids_complete.p_uuids  = m_adv_uuids;
    	init.advdata.uuids_complete.p_uuids  = &m_adv_uuids[0];
    	/*new*/
    	init.srdata.name_type               = BLE_ADVDATA_NO_NAME;
    	init.srdata.uuids_complete.uuid_cnt = 1;//sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    	init.srdata.uuids_complete.p_uuids  = &m_adv_uuids[1];
    	/*new*/
    	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.config.ble_adv_extended_enabled = true;
    	
        advertising_config_get(&init.config);
        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);
    }

    This seems to work. 

    Is this

    init.config.ble_adv_extended_enabled = true;

    required?

    What if I wanted to add

    1. Custom gatt service

    2. HID service

    3. DFU service

    , how do I add all of these to advertisement packet?

    Should the uuids_more_available be used?

Children
  • Your advertising init looks ok. You don't need to include the init.srdata.name_type in the srdata. 

     

    bscdb said:

    Is this: init.config.ble_adv_extended_enabled = true; required?

     It's not required. Extended advertising is a BT5 feature which allows you to extend the advertising packet from 31 bytes and up to 255 bytes. 

     

    bscdb said:

    , how do I add all of these to advertisement packet?

     Both the Custom service and the DFU service is a 128-bit service. So unless extended advertising is used, the will use a lot of the available space in the advertising packet. As you effectively have 29 bytes of payload available in the advertising packet (or 29 x2 with scan response) you can only fit one 128-bit service in each advertising packet. 

    Best regards, 
    Joakim

  • Thank you for your reply. I again changed the advertising_init() to accommodate the full device name. I this permissible?

    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;
        //init.advdata.uuids_complete.uuid_cnt = 1;//sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
        //init.advdata.uuids_complete.p_uuids  = m_adv_uuids;
    	//init.advdata.uuids_complete.p_uuids  = &m_adv_uuids[1];
    	/*new*/
    	init.config.ble_adv_whitelist_enabled          = false;//true;	
    	init.srdata.name_type               = BLE_ADVDATA_NO_NAME;//BLE_ADVDATA_NO_NAME;
    	init.srdata.uuids_complete.uuid_cnt = 1;//sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    	init.srdata.uuids_complete.p_uuids  = &m_adv_uuids[0];
    	init.srdata.uuids_more_available.uuid_cnt = 1;
    	init.srdata.uuids_more_available.p_uuids = &m_adv_uuids[1];
    	/*new*/
    	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.config.ble_adv_extended_enabled = true;
    	
        advertising_config_get(&init.config);
        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);
    }

    Will it affect the scanning for services by host after the bluetooth connection?

  • Yes, you are allowed to advertise the full device name. As long as there is enough space in the advertising packet, there is no problem advertising the full name. 

    Best regards, 
    Joakim

Related