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

Multiple service in one platform (HID + LBS)

Hi,

I just met some difficulties to implant more then one service into my project. The project was developed based on hid_keyboard.

The project can work normally when without lbs, but when I add the lbs service it just could not advertise and the button is no response as well.

I have done the below change in to my project:

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

static void led_write_handler(uint16_t conn_handle, ble_lbs_t * p_lbs, uint8_t led_state)
{
    if (led_state)
    {
        bsp_board_led_on(LED_2);
        NRF_LOG_INFO("Received LED ON!");
    }
    else
    {
        bsp_board_led_off(LED_2);
        NRF_LOG_INFO("Received LED OFF!");
    }
}

static void lbs_init(void)
{
	ret_code_t         err_code;
  ble_lbs_init_t     init     = {0};
	
	// Initialize LBS.
    init.led_write_handler = led_write_handler;

    err_code = ble_lbs_init(&m_lbs, &init);
    APP_ERROR_CHECK(err_code);
}

static void services_init(void)
{
    qwr_init();
    dis_init();
    bas_init();
    hids_init();
    lbs_init();
}

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

Parents
  • Hi. 

    The LBS_UUID is a 128-bit vendor specific UUID, so you might not be able to fit both the 16-bit HID UUID and the 128-bit LBS UUID inside the advertising packet without exceeding the 31 byte payload limit. 

    Have you tried debugging your application and tracked down the root cause to be inside the advertising init function? Do you see any error codes?

    Best regards, 
    Joakim

Reply
  • Hi. 

    The LBS_UUID is a 128-bit vendor specific UUID, so you might not be able to fit both the 16-bit HID UUID and the 128-bit LBS UUID inside the advertising packet without exceeding the 31 byte payload limit. 

    Have you tried debugging your application and tracked down the root cause to be inside the advertising init function? Do you see any error codes?

    Best regards, 
    Joakim

Children
  • Ok. Maybe you could look at my suggestion below and try to remove the LBS uuid from your advertising packet, and see if your device will start advertising again?

    Regards, 
    Joakim

  • Hi Joakim,

    It cannot advertise after remove the LBS uuid.

    I need to remove lbs_init() in the service_inti() that I could start advertising but without lbs function.

    And I have looked into the ble_lbs_init() and found the parameter related to uuid128bit.

    Thus, I would like to know how to revise the setting below to meet the 16-bit UUID service, is it possible?

    uint32_t ble_lbs_init(ble_lbs_t * p_lbs, const ble_lbs_init_t * p_lbs_init)
    {
        uint32_t              err_code;
        ble_uuid_t            ble_uuid;
        ble_add_char_params_t add_char_params;
    
        // Initialize service structure.
        p_lbs->led_write_handler = p_lbs_init->led_write_handler;
    
        // Add service.
        ble_uuid128_t base_uuid = {LBS_UUID_BASE};
        err_code = sd_ble_uuid_vs_add(&base_uuid, &p_lbs->uuid_type);
        VERIFY_SUCCESS(err_code);
    
        ble_uuid.type = p_lbs->uuid_type;
        ble_uuid.uuid = LBS_UUID_SERVICE;
    
        err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_lbs->service_handle);
        VERIFY_SUCCESS(err_code);
    
        // Add Button characteristic.
        memset(&add_char_params, 0, sizeof(add_char_params));
        add_char_params.uuid              = LBS_UUID_BUTTON_CHAR;
        add_char_params.uuid_type         = p_lbs->uuid_type;
        add_char_params.init_len          = sizeof(uint8_t);
        add_char_params.max_len           = sizeof(uint8_t);
        add_char_params.char_props.read   = 1;
        add_char_params.char_props.notify = 1;
    
        add_char_params.read_access       = SEC_OPEN;
        add_char_params.cccd_write_access = SEC_OPEN;
    
        err_code = characteristic_add(p_lbs->service_handle,
                                      &add_char_params,
                                      &p_lbs->button_char_handles);
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }
    
        // Add LED characteristic.
        memset(&add_char_params, 0, sizeof(add_char_params));
        add_char_params.uuid             = LBS_UUID_LED_CHAR;
        add_char_params.uuid_type        = p_lbs->uuid_type;
        add_char_params.init_len         = sizeof(uint8_t);
        add_char_params.max_len          = sizeof(uint8_t);
        add_char_params.char_props.read  = 1;
        add_char_params.char_props.write = 1;
    
        add_char_params.read_access  = SEC_OPEN;
        add_char_params.write_access = SEC_OPEN;
    
        return characteristic_add(p_lbs->service_handle, &add_char_params, &p_lbs->led_char_handles);
    }

  • There is an example of an implementation of the LBS-service in our ble_app_blinky example. I suggest that you take a look at how it's done there. 

    Best regards, 
    Joakim

Related