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

How to use more than one custom service in the scan response?

Hello,

my BLE application needs at least 5 different services to transmit different sensor data to a GATT client. I´m wondering how I can add that many UUIDs in my packet package. I use the following code:

static ble_uuid_t BLE_UUID[] =
{
    {BLE_UUID_DEVICE_INFORMATION_SERVICE,   BLE_UUID_TYPE_BLE},
    {BLE_UUID_BATTERY_SERVICE,              BLE_UUID_TYPE_BLE},
    {BLE_TIME_SERVICE,			    BLE_UUID_TYPE_VENDOR_BEGIN},
    {BLE_SENSOR_SERVICE,		    BLE_UUID_TYPE_VENDOR_BEGIN} 
};

static void Init_Advertising(void)
{
    ble_advertising_init_t Adv_Params;

    NRF_LOG_DEBUG(" Initialize advertising module...");

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

    Adv_Params.advdata.name_type		    = BLE_ADVDATA_FULL_NAME;
    Adv_Params.advdata.include_appearance	    = true;
    Adv_Params.advdata.flags			    = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    Adv_Params.advdata.uuids_complete.uuid_cnt	    = 2;
    Adv_Params.advdata.uuids_complete.p_uuids	    = &BLE_UUID[0];
    Adv_Params.srdata.uuids_more_available.uuid_cnt = 2;
    Adv_Params.srdata.uuids_more_available.p_uuids  = &BLE_UUID[2];
    Adv_Params.config.ble_adv_fast_enabled	    = true;
    Adv_Params.config.ble_adv_fast_interval	    = BLE_ADV_INTERVAL;
    Adv_Params.config.ble_adv_fast_timeout	    = BLE_ADV_DURATION;
    Adv_Params.evt_handler			    = Advertising_On_Event_Handler;

    APP_ERROR_CHECK(ble_advertising_init(&Advertising, &Adv_Params));

    ble_advertising_conn_cfg_tag_set(&Advertising, BLE_CONN_CFG_TAG);
}

This code produces the error 12 in ble_advertising_init, because there are too many data bytes for the advertisment and the scan response packet. So I reduce the number of custom services in the scan response packet to 1 instead of 2 and the application doesn´t crash and I see all services through the nRF Connect app. But I believe this is not an ideal solution....

How can I use more than one custom service with my BLE application? Do I have to send more than one scan response packets or how can I handle it?

  • Hi Daniel

    The challenge in adding custom UUID's to the advertise or scan response packet is that a single one takes up 18 bytes of your packet, and with only 31 bytes total that means you can only fit a single one in each. 

    Potentially you could put one in the advertise packet and one in the scan response packet for a total of two, but this means you won't have room for much else advertising data, and it won't solve your issue of having 5 custom services. 

    That being said, there is really no need for you to advertise every single service that your application uses. 
    The common way to handle proprietary services and applications is to assign a single 128-bit UUID to your product, and use that to identify the product to a scanning device nearby.
    If you make a proprietary app on the scanner side and you discover this UUID you know that there might be other proprietary services in the product, and once you connect to it and do a service discovery you will get a list of all the UUID's in the GATT server. 

    Best regards
    Torbjørn

Related