Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

As a BLE peripheral, how can I discover if the host device has the ANCS service?

Currently, as a peripheral, I can discover services like GAP and GATT on the host. However, I'm encountering issues when trying to discover the ANCS service. When calling ble_db_discovery_evt_register, it requires a 16-bit UUID, but the ANCS service uses a 128-bit UUID. How can I adapt the 128-bit UUID to a 16-bit format? Or are there alternative approaches?"

Parents
  • Hi,

    From the tags it looks like you are using the nRF5 SDK. If so, I suggest you have a look at the ANCS clien sample (examples/ble_peripheral/ble_app_ancs_c). This includes serivce discovery of the ANCS service. In the nRF5 SDK, 128 biut UUIDs are referr by by registering a base UUID, and then referring to this together with the 16 bit service UUID, which combined gives the 128 bit UUID. If you use the service implementation in the SDK thi sis handled for you, but you can refer to the implementation in components/ble/ble_services/ble_ancs_c/nrf_ble_ancs_c.c for details.

    PS: I recommend that you use the nRF Connect SDK unless you are workign on a legacy product based on the nRF5 SDK. ANCS is supported there as well, demonstrated in the Bluetooth: Peripheral ANCS client which also demonstrates service discovery.

  • Yes, I am using nRF SDK 5 and have the following questions:

    1. I tried flashing the ble_app_ancs_cexample onto the development board (full erase including whitelist, re-flashed), then started running it. However, my iPhone 15 cannot detect the board via Bluetooth. Why is this happening?

    2. Additionally, in the ANCS example, is the iPhone acting as the ​​GAP Central​​ (initiating connections) while its GATT layer serves as a ​​server providing ANCS service​​? And is our ble_app_ancs_cfirmware acting as a ​​Peripheral​​ but with a ​​GATT Client role​​ that discovers the ANCS service? Is this understanding correct?

    3. Lastly, when the iPhone acts as an ANCS server, can it simultaneously function as a ​​client discovering other services​​? Essentially, is it capable of being a combined server-client device?

      version:nRF5_SDK_17.1.0_ddde560

  • Hi,

    Liny said:
    I tried flashing the ble_app_ancs_cexample onto the development board (full erase including whitelist, re-flashed), then started running it. However, my iPhone 15 cannot detect the board via Bluetooth. Why is this happening?

    How are you trying to connect? You need to open an app such as nRF Connect and search there. There you should see a device called ANCS that you can connect to. This is from my iPhne 15 pro that I just tested on my desk with the unmodified example from SDK 17.1.0:

    After pressing "Connect" you will be asked to bond and then allow the nRF to receive notifications.

    I recommend also observing the UART log so that you see what is happening on the nRF. When I do (but before getting any notifications I see the following in the log):

    <info> app_timer: RTC: initialized.
    <info> app: Apple Notification Center Service client example started.
    <info> app: Fast advertising
    <info> app: Slow advertising
    <info> app: Connected.
    <info> peer_manager_handler: Connection secured: role: Peripheral, conn_handle: 0, procedure: Bonding
    <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Bonding data, action: Update
    <info> ble_ancs_c: Control Point characteristic found.
    <info> ble_ancs_c: Notification Point characteristic found.
    <info> ble_ancs_c: Data Source characteristic found.
    <info> ble_ancs_c: Enable Notification Source. Writing to CCCD handle: 41. 
    <info> ble_ancs_c: Enable Notification Data Source. Writing to CCCD handle: 44. 
    <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Remote database, action: Update

    Liny said:
    Additionally, in the ANCS example, is the iPhone acting as the ​​GAP Central​​ (initiating connections) while its GATT layer serves as a ​​server providing ANCS service​​? And is our ble_app_ancs_cfirmware acting as a ​​Peripheral​​ but with a ​​GATT Client role​​ that discovers the ANCS service? Is this understanding correct?

    This is a misunderstanding. In the ANCS example, the nRF Acts as peripheral, not a central. However, it acts as a GATT client (GATT and GAP roles are independent, and it is also possible to act both as a GATT server and GATT client ant the same time). So the nRF advertises, and the iPhone connects to the nRF. However, the after the connection is established, the nRF acts as a GATT client and performes a service discovery etc.

    Liny said:
    Lastly, when the iPhone acts as an ANCS server, can it simultaneously function as a ​​client discovering other services​​? Essentially, is it capable of being a combined server-client device?

    This is probably a misundarstanding as well? I do not see how you could use the nRF as an ANCS server. ANCS is a custom service by apple indended for use so that other devices can get notification information from the iOS device, and the iOS device is always acting as the server. The peer device then has to act as a client in order to interface with it (as is demontraed by the example). That said, there is no problem combining ANCS with other services. ANCS is a normal service inthis regard, and combining services as well as roles is common.

Reply
  • Hi,

    Liny said:
    I tried flashing the ble_app_ancs_cexample onto the development board (full erase including whitelist, re-flashed), then started running it. However, my iPhone 15 cannot detect the board via Bluetooth. Why is this happening?

    How are you trying to connect? You need to open an app such as nRF Connect and search there. There you should see a device called ANCS that you can connect to. This is from my iPhne 15 pro that I just tested on my desk with the unmodified example from SDK 17.1.0:

    After pressing "Connect" you will be asked to bond and then allow the nRF to receive notifications.

    I recommend also observing the UART log so that you see what is happening on the nRF. When I do (but before getting any notifications I see the following in the log):

    <info> app_timer: RTC: initialized.
    <info> app: Apple Notification Center Service client example started.
    <info> app: Fast advertising
    <info> app: Slow advertising
    <info> app: Connected.
    <info> peer_manager_handler: Connection secured: role: Peripheral, conn_handle: 0, procedure: Bonding
    <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Bonding data, action: Update
    <info> ble_ancs_c: Control Point characteristic found.
    <info> ble_ancs_c: Notification Point characteristic found.
    <info> ble_ancs_c: Data Source characteristic found.
    <info> ble_ancs_c: Enable Notification Source. Writing to CCCD handle: 41. 
    <info> ble_ancs_c: Enable Notification Data Source. Writing to CCCD handle: 44. 
    <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Remote database, action: Update

    Liny said:
    Additionally, in the ANCS example, is the iPhone acting as the ​​GAP Central​​ (initiating connections) while its GATT layer serves as a ​​server providing ANCS service​​? And is our ble_app_ancs_cfirmware acting as a ​​Peripheral​​ but with a ​​GATT Client role​​ that discovers the ANCS service? Is this understanding correct?

    This is a misunderstanding. In the ANCS example, the nRF Acts as peripheral, not a central. However, it acts as a GATT client (GATT and GAP roles are independent, and it is also possible to act both as a GATT server and GATT client ant the same time). So the nRF advertises, and the iPhone connects to the nRF. However, the after the connection is established, the nRF acts as a GATT client and performes a service discovery etc.

    Liny said:
    Lastly, when the iPhone acts as an ANCS server, can it simultaneously function as a ​​client discovering other services​​? Essentially, is it capable of being a combined server-client device?

    This is probably a misundarstanding as well? I do not see how you could use the nRF as an ANCS server. ANCS is a custom service by apple indended for use so that other devices can get notification information from the iOS device, and the iOS device is always acting as the server. The peer device then has to act as a client in order to interface with it (as is demontraed by the example). That said, there is no problem combining ANCS with other services. ANCS is a normal service inthis regard, and combining services as well as roles is common.

Children
No Data
Related