Important: Before you run this example, make sure to program the SoftDevice.
The Nordic UART Service (NUS) Client Application is an example that implements the Nordic UART Service Client over BLE. In the example, the development board serves as a GAP central and a GATT client.
The application scans peripheral devices and connects to a device that advertises with the NUS UUID in its advertisement report. After connecting, the application enables notifications on the device that delivers the Nordic UART Service.
You can find the source code and the project file of the example in the following folder: <InstallFolder>\examples\ble_central\ble_app_uart_c
Button assignments: BSP BLE Button Assignments
The application uses the following UART settings:
The responsibility of connecting to the NUS server is shared between the main program and the ble_nus_c module. The main program scans and reads the advertisement packets and connects to a device that delivers the NUS. After connecting, it starts service discovery. In this way, it is possible to scan for different services without needing to start unnecessary service discoveries.
The ble_nus_c module is responsible for parsing the service scan response and passing notifications back to the main program.
The scanning parameters are set in the m_scan_params structure. Active scanning must be enabled, because the advertised service list is sent as scan response data.
The advertisement packet is parsed using the function is_uuid_present. If this function returns true, the application will connect to the device.
The following code example shows how to handle events from the ble_nus_c module:
If the TX characteristic is found, notifications are enabled. When a TX notification is received, the data is printed out to UART.
When data is received from UART, the data is split up in packets and sent using NUS. The following code example shows how to handle UART data:
Two boards are needed to perform this test:
The application running on the Peripheral board is intended to serve as a peer (for example, in the Nordic UART Service (NUS) Application role) to this NUS Client application.
Test the BLE NUS Client Example application by performing the following steps: