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
Figure 1. NRF52840DK and NRF5340DK running Thread CLI sample

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)
Figure 2. Thread network with our devices

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):

Figure 4. Dev. kit recognized as COM port (Windows Device Manager)

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:

Set the XPAN ID:

Set the channel:

Set the PAN ID:

Set the Network key:

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:

Start Thread protocol operation:

Get the current role of the Thread device:

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:

Figure 5. Commands executed on Device 1 (left) and Device 2 (right)

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.

Figure 6. Example IP addresses of a Thread device

Device 1 CLI

Get the list of IPv6 addresses assigned to the Thread interface:

Figure 7. Device 1 ipaddr result

Device 2 CLI

Ping Device 1 from Device 2:

FIgue 8. Ping Device 1 from Device 2 CLI

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:

Assigns unspecified IPv6 address IPv6 (::) and a port (1212) to the opened socket, which binds the socket for communication:

Device 2 CLI

Open a UDP/IPv6 socket:

Connect a UDP/IPv6 socket. Use the IP of Device 1 (fdde:ad00:beef:0:4b64:18b5:ff1f:f6cd) and the 1212 port:

Send a message to Device 1:

Figure 9. Message sent between our devices using UDP

Was this article helpful?