OpenThread provides a command-line interface (CLI) that can be useful for people new to Thread. It provides an easy way to configure a Thread device, manage a Thread network, and test communication between devices.
This article will show how to use CLI with devices running an OpenThread stack.
Tools used:
- Two Nordic development kits that support Thread
- A PC with Windows OS
- PuTTy serial terminal

Setup
Our two development kits are flashed with the Thread CLI sample provided by Nordic nRF Connect SDK. For information on building and flashing the samples, please refer to the official Nordic guides.
In this example, we refer to the two programmed development kits as Device 1 and Device 2:
- Device 1 will take the role of a Thread Router (and a Leader)
- Device 2 will join the network as an End Device (child)

The first device we configure and start the Thread protocol will take the role of a Router and elect itself to become the Leader, as there are no other devices yet in the network. If another device wants to join the network, it must configure its Channel, PAN ID, XPAN ID, and Network Name to match the target network’s. This is done using Thread Commissioning. We won’t need commissioning for this example as we can directly configure the devices using OpenThread CLI.
More information on Thread roles can be found here: https://openthread.io/guides/thread-primer/node-roles-and-types
Configure and Start Thread Using CLI
For this step, connect Device 1 and Device 2 to the PC’s USB ports. Then, open a serial terminal and connect to the devices.
Serial connection settings for PuTTy are shown in the figure below (COM port number is device-specific; change it accordingly):


Check for your serial COM port using Device Manager (on Windows platforms):

Now, we are ready to start using OpenThread CLI. The commands are specified here.
We will configure the required Thread network parameters with the following values:
- Network name: OpenThread
- PAN ID: 0xabcd
- XPAN ID: dead00beef00cafe
- Network key: 00112233445566778899aabbccddeeff
- Channel: 11
All nodes must have the same configuration to join the network.
Device 1 Configuration
When we send commands to our devices we need to indicate these are OpenThread commands. That is done by adding “ot” before each command.
Set the name of the network:
$ ot networkname OpenThread
Set the XPAN ID:
$ ot extpanid dead00beef00cafe
Set the channel:
$ ot channel 11
Set the PAN ID:
$ ot panid 0xabcd
Set the Network key:
$ ot networkkey 00112233445566778899aabbccddeeff
The configurations we have made so far are persistent. They are stored in non-volatile memory, and a power cycle or reset will not affect them.
Once we have configured the thread network parameters, we can start the Thread on our device.
Start the IPv6 interface:
$ ot ifconfig up
Start Thread protocol operation:
$ ot thread start
Get the current role of the Thread device:
$ ot state
Device 1 will be a Thread Leader, as there are no other devices yet.
Device 2 Configuration
Repeat all the steps we did for Device 1. The difference here is that when we execute “ot state” we will get a response that the device has the role of a child.
See the executed commands for both devices shown below:

Test Communication Between Two Devices
To check if both devices are on the same network, the first step is to perform a ping. To do this, we need to know their IP addresses. In the case of a Thread device, it has different IPs. The one we can use for device-to-device communication (and other Thread network communication) is the Mesh-Local IP.

Device 1 CLI
Get the list of IPv6 addresses assigned to the Thread interface:
$ ot ipaddr

Device 2 CLI
Ping Device 1 from Device 2:
$ ot ping fdde:ad00:beef:0:4b64:18b5:ff1f:f6cd

UDP communication using CLI
One of the application services that OpenThread provides is User Datagram Protocol (UDP), a Transport Layer protocol.
In this step, we will use OpenThread UDP API to pass messages between our two devices.
Device 1 CLI
Open a UDP/IPv6 socket:
$ ot udp open
Assigns unspecified IPv6 address IPv6 (::) and a port (1212) to the opened socket, which binds the socket for communication:
$ ot udp bind :: 1212
Device 2 CLI
Open a UDP/IPv6 socket:
$ ot udp open
Connect a UDP/IPv6 socket. Use the IP of Device 1 (fdde:ad00:beef:0:4b64:18b5:ff1f:f6cd) and the 1212 port:
$ ot upd connect fdde:ad00:beef:0:4b64:18b5:ff1f:f6cd 1212
Send a message to Device 1:
$ ot upd send helloworld

Leave A Comment