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

Is it possible to add a custom service to an existing hids_keyboard code?

I am trying to add an extra service from an exiting nordic example code:"experimental_ble_app_blinky" into another exiting nordic example code: "ble_app_hids_keyboard".

  1. device manger service
  2. battery service
  3. HID service

This extra service code which is a custom service with a new UUID is not showing up as 4th service in the new code.

Here is the code I am adding:

static void services_init(void)
{
dis_init(); //device information service
bas_init(); //battery service
hids_init(); //human interface service
bls_init();  // this is the extra new service button led service 
}

Last line is the new 4th service I am adding which is called "led button service", which comes right from example "experimental_led blinky"

static void lbs_init(void)
{
uint32_t err_code;
ble_lbs_init_t init;
init.led_write_handler = led_write_handler;
err_code = ble_lbs_init(&m_lbs,init);
}

Of course, I have added all relevant code for building and compiling with no error. What I was expecting to see 1 more service which is a custom service in addition to device manager service and battery service, in my iphone which I am running a BLE scanner apps, but I see no custom service!!. What Am I missing here?

Also in hid keyboard example, during advertisement, in example code there is only one UUID number and type, like this:

static ble_uuid_t m_adv_uuids[] = {{BLE_UUID_HUMAN_INTERFACE_DEVICE_SERVICE, BLE_UUID_TYPE_BLE}};

I don't see any UUID for Device info Service, and battery service, although it shows up as services in my iphone BLE scan app, which I don't understand. Now do I need to add the UUID of my custom service into advertisement init?

I have seen some example that has all services part of adv_init code, like HRS example:

static ble_uuid_t m_adv_uuids[] =
{ {BLE_UUID_HEART_RATE_SERVICE, BLE_UUID_TYPE_BLE},
{BLE_UUID_BATTERY_SERVICE, BLE_UUID_TYPE_BLE}, 
 {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE} }; 

I am thinking may be its optional! One last comment, I also added scan response part of led button service service into advertising_init(). The hid keyboard code adv_init() was like this:

err_code = ble_advertising_init(&advdata, NULL, &options, on_adv_evt, ble_advertising_error_handler); 

As you can see the second parameter is NULL, so I changed it to this:

err_code = ble_advertising_init(&advdata, &scanrsp, &options, on_adv_evt, ble_advertising_error_handler); 

Again it just like the example LED_BLINKY custom service, which scan response is pass into this code:

err_code = ble_advdata_set(&advdata, &scanrsp);

I want to make sure if this is doable to have more than 3 services in HID example code,

Thanks

  • if you want a UUID to be advertised you need to advertise it. The services which can be discovered are not automatically advertised (they couldn't be, there's not enough room in the advertising packet). So no it's not optional, if you want your new service in the ad packet, you need to put the service in your ad packet. Be careful not to put too much in the packet (especially if this is a custom UUID).

    Even with the UUID not in the advertising packet you should still be able to discover the service after connecting to the device.

  • Thanks RK, for clarification, good news is that I got the addition service working now, I had to erase the S110 softdevice and re-load thieving again, and l also wait a bit longer, but eventually I have received, all 4 serveries. Can you also clear the question regarding the Scan response part of adv_init(), what is it for? I don't have in there yet!

Related