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.

  • 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?

Related