Bluetooth: Peripheral CTS client
The Peripheral CTS client sample demonstrates how to use the GATT Current Time Service (CTS) Client.
Requirements
The sample supports the following development kits:
Hardware platforms |
PCA |
Board name |
|
|---|---|---|---|
nRF54LV10 DK |
PCA10188 |
|
|
PCA10184 |
|
||
nRF54LC10 DK |
PCA10226 |
nrf54lc10dk |
|
PCA10156 |
|
||
PCA10156 |
|
||
PCA10156 |
|
||
PCA10175 |
|
||
PCA10095 |
|
||
PCA10040 |
|
||
PCA10056 |
|
For more security, it is recommended to use the */ns variant of the board target.
When built for this variant, the sample is configured to compile and run as a non-secure application using security by separation.
Therefore, it automatically includes Trusted Firmware-M that prepares the required peripherals and secure services to be available for the application.
The sample also requires a device running a CTS Server to connect with (for example, a Bluetooth® Low Energy dongle and the Bluetooth Low Energy app).
Overview
The CTS client sample implements a Current Time Service client. It uses the Current Time Service to read the current time. The time received is printed on the UART.
User interface
- LED 1:
Blinks, toggling on/off every second, when the main loop is running and the device is advertising.
- LED 2:
Lit when connected.
- Button 1:
Read the current time.
- LED 0:
Blinks, toggling on/off every second, when the main loop is running and the device is advertising.
- LED 1:
Lit when connected.
- Button 0:
Read the current time.
Building and running
This sample can be found under samples/bluetooth/peripheral_cts_client in the nRF Connect SDK folder structure.
For more security, it is recommended to use the */ns variant of the board target (see the Requirements section above.)
When built for this variant, the sample is configured to compile and run as a non-secure application using security by separation.
Therefore, it automatically includes Trusted Firmware-M that prepares the required peripherals and secure services to be available for the application.
To build the sample, follow the instructions in Building an application for your preferred building environment. See also Programming an application for programming steps and Testing and optimization for general information about testing and debugging in the nRF Connect SDK.
Note
When building repository applications in the SDK repositories, building with sysbuild is enabled by default.
If you work with out-of-tree freestanding applications, you need to manually pass the --sysbuild parameter to every build command or configure west to always use it.
Testing
After programming the sample to your development kit, you can test it with the Bluetooth Low Energy app by performing the following steps.
Connect to the kit that runs this sample with a terminal emulator (for example, the Serial Terminal app). See Testing and optimization for the required settings and steps.
Reset the kit.
Start nRF Connect for Desktop
Open the Bluetooth Low Energy app and select the connected dongle that is used for communication.
Open the SERVER SETUP tab. Click the dongle configuration and select Load setup. Load the
cts_central.ncsfile that is located undersamples/bluetooth/peripheral_cts_clientin the nRF Connect SDK folder structure.Click Apply to device.
Open the CONNECTION MAP tab. Click the dongle configuration and select Security parameters. Check Perform Bonding and Enable LE Secure Connection pairing, and click Apply.
Set the value of Current Time Service > Current Time to
C2 07 0B 0F 0C 22 38 06 80 02and click Write.Connect to the device from the app. The device is advertising as “Nordic_CTS”.
Wait until the bond is established. Verify that the UART data is received as follows:
Connected xx:xx:xx:xx:xx:xx (random) The discovery procedure succeeded Security changed: xx:xx:xx:xx:xx:xx (random) level 2 Pairing completed: xx:xx:xx:xx:xx:xx (random), bonded: 1
Press Button 1 on the kit. Verify that the current time printed on the UART matches the time that was input in the Current Time characteristic (UUID 0x2A2B):
Current Time: Date: Day of week Saturday Day of month 15 Month of year November Year 1986 Time: Hours 12 Minutes 34 Seconds 56 Fractions 128/256 of a second Adjust Reason: Daylight savings 0 Time zone 0 External update 1 Manual update 0
Change the value of Current Time Service > Current Time to
C2 07 0B 0F 0D 25 2A 06 FE 08. It generates a notification. Verify that the current time printed on the UART matches the time that was input:Current Time: Date: Day of week Saturday Day of month 15 Month of year November Year 1986 Time: Hours 13 Minutes 37 Seconds 42 Fractions 254/256 of a second Adjust Reason: Daylight savings 1 Time zone 0 External update 0 Manual update 0
Disconnect the device in the app.
As bond information is preserved by the app, you can immediately reconnect to the device by clicking the Connect button again.
Connect to the kit that runs this sample with a terminal emulator (for example, the Serial Terminal app). See Testing and optimization for the required settings and steps.
Reset the kit.
Start nRF Connect for Desktop
Open the Bluetooth Low Energy app and select the connected dongle that is used for communication.
Open the SERVER SETUP tab. Click the dongle configuration and select Load setup. Load the
cts_central.ncsfile that is located undersamples/bluetooth/peripheral_cts_clientin the nRF Connect SDK folder structure.Click Apply to device.
Open the CONNECTION MAP tab. Click the dongle configuration and select Security parameters. Check Perform Bonding and Enable LE Secure Connection pairing, and click Apply.
Set the value of Current Time Service > Current Time to
C2 07 0B 0F 0C 22 38 06 80 02and click Write.Connect to the device from the app. The device is advertising as “Nordic_CTS”.
Wait until the bond is established. Verify that the UART data is received as follows:
Connected xx:xx:xx:xx:xx:xx (random) The discovery procedure succeeded Security changed: xx:xx:xx:xx:xx:xx (random) level 2 Pairing completed: xx:xx:xx:xx:xx:xx (random), bonded: 1
Press Button 0 on the kit. Verify that the current time printed on the UART matches the time that was input in the Current Time characteristic (UUID 0x2A2B):
Current Time: Date: Day of week Saturday Day of month 15 Month of year November Year 1986 Time: Hours 12 Minutes 34 Seconds 56 Fractions 128/256 of a second Adjust Reason: Daylight savings 0 Time zone 0 External update 1 Manual update 0
Change the value of Current Time Service > Current Time to
C2 07 0B 0F 0D 25 2A 06 FE 08. It generates a notification. Verify that the current time printed on the UART matches the time that was input:Current Time: Date: Day of week Saturday Day of month 15 Month of year November Year 1986 Time: Hours 13 Minutes 37 Seconds 42 Fractions 254/256 of a second Adjust Reason: Daylight savings 1 Time zone 0 External update 0 Manual update 0
Disconnect the device in the app.
As bond information is preserved by the app, you can immediately reconnect to the device by clicking the Connect button again.
Dependencies
This sample uses the following nRF Connect SDK libraries:
In addition, it uses the following Zephyr libraries:
include/zephyr/types.hlib/libc/minimal/include/errno.hinclude/sys/printk.hAPI:
include/bluetooth/bluetooth.hinclude/bluetooth/conn.hinclude/bluetooth/uuid.hinclude/bluetooth/gatt.h
The sample also uses the following secure firmware component: