Nordic UART Service (NUS)

The BLE GATT Nordic UART Service is a custom service that receives and writes data and serves as a bridge to the UART interface.

The NUS Service is used in the Bluetooth: Peripheral UART sample.

Service UUID

The 128-bit vendor-specific service UUID is 6E400001-B5A3-F393-E0A9-E50E24DCCA9E (16-bit offset: 0x0001).

Characteristics

This service has two characteristics.

RX Characteristic (6E400002-B5A3-F393-E0A9-E50E24DCCA9E)

Write or Write Without Response
Write data to the RX Characteristic to send it on to the UART interface.

TX Characteristic (6E400003-B5A3-F393-E0A9-E50E24DCCA9E)

Notify
Enable notifications for the TX Characteristic to receive data from the application. The application transmits all data that is received over UART as notifications.

API documentation

Header file: include/nus.h
Source file: subsys/bluetooth/services/nus.c
group bt_gatt_nus

Nordic UART (NUS) GATT Service API.

Defines

NUS_UUID_SERVICE

UUID of the NUS Service.

NUS_UUID_NUS_TX_CHAR

UUID of the TX Characteristic.

NUS_UUID_NUS_RX_CHAR

UUID of the RX Characteristic.

BT_UUID_NUS_SERVICE
BT_UUID_NUS_RX
BT_UUID_NUS_TX

Typedefs

typedef void (*nus_received_cb_t)(struct bt_conn *conn, const u8_t *const data, u16_t len)

Callback type for data received.

typedef void (*nus_sent_cb_t)(struct bt_conn *conn)

Callback type for data sent.

Functions

int bt_gatt_nus_init(struct bt_gatt_nus_cb *callbacks)

Initialize the service.

This function registers a BLE service with two characteristics, TX and RX. A BLE unit that is connected to this service can send data to the RX Characteristic. When the BLE unit enables notifications, it is notified when data is sent to the TX Characteristic.

Parameters
  • callbacks: Struct with function pointers to callbacks for service events. If no callbacks are needed, this parameter can be NULL.
Return Value
  • 0: If initialization is successful. Otherwise, a negative value is returned.

int bt_gatt_nus_send(struct bt_conn *conn, const u8_t *data, u16_t len)

Send data.

This function sends data from the BLE unit that runs this service to another BLE unit that is connected to it.

Parameters
  • conn: Pointer to connection Object.
  • data: Pointer to a data buffer.
  • len: Length of the data in the buffer.
Return Value
  • 0: If the data is sent. Otherwise, a negative value is returned.

static u32_t bt_gatt_nus_max_send(struct bt_conn *conn)

Get maximum data length that can be used for bt_gatt_nus_send.

Return
Maximum data length.
Parameters
  • conn: Pointer to connection Object.

struct bt_gatt_nus_cb
#include <nus.h>

Pointers to the callback functions for service events.

Public Members

nus_received_cb_t received_cb

Callback for data received.

nus_sent_cb_t sent_cb

Callback for data sent.