This project is a modified central_uart sample designed to simplify interaction with a Bluetooth® LE peripheral using a UART interface. It utilizes the Nordic UART Service (NUS) client to send and receive data between a local UART and a BLE connection.
Unlike a simple “serial-over-BLE” approach, this firmware:
- Handles text-based commands from UART,
- Allows switching between text (hex-encoded) or binary (frame-encoded) modes for data coming from BLE and forwarded to UART.
In the default text-encoding mode, you can interact with the Bluetooth peripheral using any standard serial terminal (e.g., nRF Serial Terminal, PuTTY) without additional parsing tools.
When typing commands into the UART terminal, use the following format:
<cmd> [params]\r\n
cmdis a single character (e.g.,?,r,c, etc.).paramsis optional and depends on the specific command.
Commands receive a response of the form:
! {OK | ERROR} [error description]\r\n
If any informative lines need to be printed before the final OK or ERROR, they are prefixed with #, for example:
# [information]\r\n
Issuing the scan command outputs something like:
# SCAN: F5:3F:1C:28:EB:D9 (random) (connectable: 1)
# SCAN: DD:52:5B:2A:66:61 (random) (connectable: 1)
! OK
# SCAN: ...lines are informative messages about discovered devices.- The final line
! OKindicates that the command completed successfully.
After reboot, the firmware prints basic information and a help listing of available commands:
#
# ==== REBOOT ====
#
# Available commands:
# ? - print this help
# c XX:XX:XX:XX:XX:XX - connect to BT_NUS with the specified MAC address
# d - disconnect
# s - scan for NUS services for 5 seconds
# S - scan for Ruuvi services for 5 seconds
# w XX XX ... - write bytes to the BT_NUS (XX are hexadecimal values)
# r - reboot
# b - switch to binary mode
# t - don't relay data to UART, only print logs to RTT
# In binary mode, the data received from BT_NUS will be relayed to UART as is,
# but each received packed will be framed as follows:
# 24 LL DD DD ... DD CS 0D 0A
# where LL is the length of the data, DD are data bytes, and CS is the checksum
# 0x24 ('$') is the start of the frame, 0x0D 0x0A is the end of the frame
#
-
Text Mode (Default)
- Data from BLE is forwarded to UART as ASCII-encoded hex strings (or simple text lines).
- Easy to test with common serial terminal software.
-
Binary Mode
- The raw payload from BLE is placed into frames before being sent to UART:
0x24 <Length> <Data> ... <Data> <Checksum> 0x0D 0x0A - This is useful if you need to send large amount of data from the peripheral device.
- The raw payload from BLE is placed into frames before being sent to UART:
-
Silent Mode -- In this mode data from BLE is not forwarded to UART. It is useful to measure maximum BLE transfer speed.
> c D1:EF:41:C1:60:DC
# Connect to BT_NUS with MAC address: D1:EF:41:C1:60:DC
! OK
$ E0 16 1E 52 6C C6 8B 00 6E 00 72 00 73 00 74 03 76 00 10 00 01 00 4F 1E 22 B5 19 2C 01 FF FF FF FF FF
$ E0 16 1E 52 6C C6 8B 00 6E 00 72 00 73 00 74 03 76 00 10 00 01 00 4F 1E 22 B5 1A 2C 01 FF FF FF FF FF
> w 3b 00 21 67 7f 00 00 67 7e f1 f0
! OK
$ 00 3B 20 07 20 67 7E F1 F0 1E 16 6C 52 8B C6 6E 00 72 00 73 00 74 00 76 03 10 00 01 00 4F 00 1E 22 00 00 00 00 67 7E F3 1C 1E 16 6C 52 8B C6 6E 00 72 00 73 00 74 00 76 03 10 00 01 00 4F 00 1E 22 00 00 00 00 67 7E F4 48 1E 16 6C 52 8B C6 6E 00 72 00 73 00 74 00 76 03 10 00 01 00 4F 00 1E 22 00 00 00 00 67 7E F5 74 1E 16 6C 52 8B C6 6E 00 72 00 73 00 74 00 76 03 10 00 01 00 4F 00 1E 22 00 00 00 00 67 7E F6 A0 1E 16 6C 52 8B C6 6E 00 72 00 73 00 74 00 76 03 10 00 01 00 4F 00 1E 22 00 00 00 00 67 7E F7 CC 1E 16 6C 52 8B C6 6E 00 72 00 73 00 74 00 76 03 10 00 01 00 4F 00 1E 22 00 00 00 00 67 7E F8 F8 1E 16 6C 52 8B C6 6E 00 72 00 73 00 74 00 76 03 10 00 01 00 4F 00 1E 22 00 00 00 00
$ 00 3B 20 06 20 67 7E FA 24 1E 16 6C 52 8B C6 6E 00 72 00 73 00 74 00 76 03 10 00 01 00 4F 00 1E 22 00 00 00 00 67 7E FB 50 1E 16 6C 52 8B C6 6E 00 72 00 73 00 74 00 76 03 10 00 01 00 4F 00 1E 22 00 00 00 00 67 7E FC 7C 1E 16 6C 52 8B C6 6E 00 72 00 73 00 74 00 76 03 10 00 01 00 4F 00 1E 22 00 00 00 00 67 7E FD A9 1E 16 6C 52 8B C6 6E 00 72 00 73 00 74 00 76 03 10 00 01 00 4F 00 1E 22 00 00 00 00 67 7E FE D5 1E 16 6C 52 8B C6 6E 00 72 00 73 00 74 00 76 03 10 00 01 00 4F 00 1E 22 00 00 00 00 67 7F 00 01 1E 16 6C 52 8B C6 6E 00 72 00 73 00 74 00 76 03 10 00 01 00 4F 00 1E 22 00 00 00 00
$ 00 3B 20 00 20
$ E0 16 1E 52 6C C6 8B 00 6E 00 72 00 73 00 74 03 76 00 10 00 01 00 4F 1E 22 B5 1E 2C 01 FF FF FF FF FF
> d
# DISCONNECTED
! OK
> c DB:50:4B:2A:65:6A
# Connect to BT_NUS with MAC address: DB:50:4B:2A:65:6A
! OK
$ 05 15 28 4B 0C C6 91 00 20 00 1C 04 00 A4 D6 F7 48 43
$ 05 15 2B 4B 24 C6 91 00 1C 00 14 03 FC A4 D6 F7 48 44
> w 3a 00 11 67 8b 94 92 67 8b 00 00
! OK
$ 00 31 10 67 8B 02 25 00 00 12 AA
$ 00 32 10 67 8B 02 25 00 01 8B 53
...
$ 00 30 10 67 8B 93 CB 00 00 0A 92
$ 00 3A 10 FF FF FF FF FF FF FF FF
> d
# DISCONNECTED
! OK
./build_nrf52dk.sh
west flash -d build_nrf52dk
./build_nrf52840dk.sh
west flash -d build_nrf52840dk
./build_nrf52840dongle.sh
Put the dongle in DFU mode:
- Press and hold the button on the side.
- Press the reset button briefly.
- Release the side button.
- The LED should pulse red, indicating it is in DFU/bootloader mode.
nrfutil dfu usb-serial -pkg build_nrf52840dongle/ruuvi_ble_nus_dfu.zip -p <port>
Example of port: /dev/ttyACM3
- LED1 Starts blinking after reboot on nRF82840-DK and nRF52840-Dongle until PC is connected to the Virtual COM port.
- LED1 lights up continuously after PC is connected to the Virtual COM port.
- LED2 lights up when the connection with the Bluetooth peripheral device via NUS is established.