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

advertise multiple services

Hi,

This seems to be an issue that pops up often. However, I wasn't able to find an answer here in the Nordic forum.

What I have:

  • a number of vendor services
  • (services / characteristics are successfully added, I can see them using a Central device)
  • (I have increased 'vs_uuid_count' as suggested in the forum - works fine)

What I want:

  • From these services I'd like to advertise two
  • (I think I understand how 'ble_advertising_init' works, including advertising data and scan response)
  • (I think I understand the concept behind 'ble_uuid_t' , i.e.byte 12/13 and BLE_UUID_TYPE_VENDOR_BEGIN)

My question:

  • How do I setup advertising so that the 3rd and 5th service is advertised
  • (I understand that I have to use the standard advertisement packet and the scan response to advertise two separate 128bit services)

I appreciate your reply

Thank you Matthias

  • Have a look at ble_app_uart, it advertises a vendor specific UUID. What do you mean by 3rd and 5th service?

  • Hi Petter,

    Thank you for your quick reply. Yes I understand the uart app.

    Ok, let's assume that I have added 6 vendor services using 'sd_ble_uuid_vs_add' and 'sd_ble_gatts_service_add'.

    Now I'd like to advertise service #3 and #6. How do I setup 'ble_advertising_init' parameters, the 'ble_uuid_t' list respectively?

  • Hi Petter,

    or another question: if you look at the UART example

    static ble_uuid_t m_adv_uuids[] = { {BLE_UUID_NUS_SERVICE, NUS_SERVICE_UUID_TYPE} }; /**< Universally unique service identifier. */

    BLE_UUID_NUS_SERVICE --> what is in byte 12/13 NUS_SERVICE_UUID_TYPE --> that we're talking about a vendor service

    My question: where do we say WHICH vendor service

    Greetings Matthias

  • FormerMember
    0 FormerMember

    Advertising two custom services means to advertise 2 x 16 bytes of data. The maximum payload for advertising data is 31 bytes. It means that two custom services won't fit within the advertising data. What you can do is to add one service UUID in the advertising data, and add the other service UUID in the scan response data.

    Regarding how to add the service UUIDs: In ble_app_uart in the SDK, the struct ble_uuid_t is used to manange UUIDs.

    ble_uuid_t.uuid is byte 12-13 of the advertised UUID.

    ble_uuid.type refers to the base UUID of the service, added using sd_ble_uuid_vs_add(..).

    The base UUID is the 128-bit/16-byte UUID without byte 12-13. It means that when adding a 128-bit UUID using sd_ble_uuid_vs_add(..), byte 12-13 will be discarded (replaced by zeros). When using services and/or characteristics, you have to refer to both the base UUID and byte 12-13 of the UUID in use.

    In ble_app_uart, BLE_UUID_NUS_SERVICE is byte 12-13 and NUS_SERVICE_UUID_TYPE is the base UUID.

  • Hi Kristin,

    Thank you for this. Referring to the ble_app_uart example, NUS_SERVICE_UUID_TYPE maps to BLE_UUID_TYPE_VENDOR_BEGIN (--> s. ble_types.h).

    But how/where to I tell the SoftDevice which one of my services I actually want? BLE_UUID_TYPE_VENDOR_BEGIN just says that I want a vendor-specific service.

    And: when setting up advertising/scan response: how/where do I tell the SoftDevice to use service A for the advertise packet and service B for the scan response?

    Thank you again, Matthias

Related