OpenThread: Difference between revisions

From Variscite Wiki
(Undo revision 28925 by Bruno (talk))
Tag: Undo
No edit summary
Line 15: Line 15:
--> {{#vardefine:EVKB|{{#var:MACHINE_NAME}}-b}} <!--
--> {{#vardefine:EVKB|{{#var:MACHINE_NAME}}-b}} <!--
-->{{DocImage|category1=Yocto|category2=Debian}}[[Category:VAR-SOM-MX93]] __toc__
-->{{DocImage|category1=Yocto|category2=Debian}}[[Category:VAR-SOM-MX93]] __toc__
{{#ifexpr: {{#var:KERNEL_VER}} < 6.6.52
|
{{#vardefine:OT_CLI_CMD|ot-ctl}}
|
{{#vardefine:OT_CLI_CMD|ot-client-iwxxx-spi}}
{{#vardefine:OT_EXTRA_CMD|true}}
{{#vardefine:OT_EXTRA_ARGS|' dataset '}}
}}


= {{#var:HARDWARE_NAME}} OpenThread Overview =
= {{#var:HARDWARE_NAME}} OpenThread Overview =
Line 43: Line 52:
  systemctl disable variscite-ot
  systemctl disable variscite-ot


= Managing OpenThread using ot-ctl =
= Managing OpenThread using {{#var:OT_CLI_CMD}} =


'''ot-ctl''' uses the ot-daemon UNIX socket and can be used to manage OpenThread. It requires that ot-daemon is first running. As a reminder, the variscite-ot service starts this by default.
'''{{#var:OT_CLI_CMD}}''' uses the ot-daemon UNIX socket and can be used to manage OpenThread. It requires that ot-daemon is first running. As a reminder, the variscite-ot service starts this by default.


For example, you can read the extended MAC address of your device:
For example, you can read the extended MAC address of your device:


  # ot-ctl extaddr
  # {{#var:OT_CLI_CMD}} extaddr
  52fc4e6d3cd98e30
  52fc4e6d3cd98e30
  Done
  Done
Line 55: Line 64:
The following sections demonstrate how to create a network on '''{{#var:EVKA}}''' and connect to the network on '''{{#var:EVKB}}'''.
The following sections demonstrate how to create a network on '''{{#var:EVKA}}''' and connect to the network on '''{{#var:EVKB}}'''.


== Create OpenThread network using ot-ctl ==
== Create OpenThread network using {{#var:OT_CLI_CMD}} ==


Reset to factory settings:
Reset to factory settings:
  root@{{#var:EVKA}}:~# ot-ctl factoryreset && sleep 2
  root@{{#var:EVKA}}:~# {{#var:OT_CLI_CMD}} factoryreset && sleep 2
 
{{#ifeq: {{#var:OT_EXTRA_CMD}}|true|
Initialize a new operational dataset:
root@{{#var:EVKA}}:~# {{#var:OT_CLI_CMD}}{{#var:OT_EXTRA_ARGS}}init new
Done
|}}


Set Channel to 26:
Set Channel to 26:
  root@{{#var:EVKA}}:~# ot-ctl channel 26
  root@{{#var:EVKA}}:~# {{#var:OT_CLI_CMD}}{{#var:OT_EXTRA_ARGS}}channel 26
  Done
  Done


Set PAN ID to 0x1234:
Set PAN ID to 0x1234:
  root@{{#var:EVKA}}:~# ot-ctl panid 0x1234
  root@{{#var:EVKA}}:~# {{#var:OT_CLI_CMD}}{{#var:OT_EXTRA_ARGS}}panid 0x1234
  Done
  Done


Set Extended PAN ID:
Set Extended PAN ID:
  root@{{#var:EVKA}}:~# ot-ctl extpanid dead00beef00cafe
  root@{{#var:EVKA}}:~# {{#var:OT_CLI_CMD}}{{#var:OT_EXTRA_ARGS}}extpanid dead00beef00cafe
  Done
  Done


Generate a new networkkey (this will change everytime):
Generate a new networkkey (this will change everytime):
  root@{{#var:EVKA}}:~# ot-ctl networkkey
  root@{{#var:EVKA}}:~# {{#var:OT_CLI_CMD}}{{#var:OT_EXTRA_ARGS}}networkkey
  c9ca829c5a194f86e141a8721f1f38aa
  c9ca829c5a194f86e141a8721f1f38aa
  Done
  Done


Set Network Name to "ThreadTest":
Set Network Name to "ThreadTest":
  root@{{#var:EVKA}}:~# ot-ctl networkname ThreadTest
  root@{{#var:EVKA}}:~# {{#var:OT_CLI_CMD}}{{#var:OT_EXTRA_ARGS}}networkname ThreadTest
Done
 
{{#ifeq: {{#var:OT_EXTRA_CMD}}|true|
Activate the dataset:
root@{{#var:EVKA}}:~# {{#var:OT_CLI_CMD}}{{#var:OT_EXTRA_ARGS}}commit active
  Done
  Done
|}}


Enable Network Interface:
Enable Network Interface:
  root@{{#var:EVKA}}:~# ot-ctl ifconfig up
  root@{{#var:EVKA}}:~# {{#var:OT_CLI_CMD}} ifconfig up
  Done
  Done


Start Thread:
Start Thread:
  root@{{#var:EVKA}}:~# ot-ctl thread start
  root@{{#var:EVKA}}:~# {{#var:OT_CLI_CMD}} thread start
  Done
  Done


Print the State:
Print the State:
  root@{{#var:EVKA}}:~# ot-ctl state
  root@{{#var:EVKA}}:~# {{#var:OT_CLI_CMD}} state
  detached
  detached
  ...wait a few seconds...
  ...wait a few seconds...
  root@{{#var:EVKA}}:~# ot-ctl state
  root@{{#var:EVKA}}:~# {{#var:OT_CLI_CMD}} state
  leader
  leader


Line 105: Line 126:
  Network key c9ca829c5a194f86e141a8721f1f38aa saved to /tmp/ot-wpan0.key
  Network key c9ca829c5a194f86e141a8721f1f38aa saved to /tmp/ot-wpan0.key


== Connect to OpenThread network using ot-ctl ==
== Connect to OpenThread network using {{#var:OT_CLI_CMD}} ==


Reset to factory defaults:
Reset to factory defaults:
  root@{{#var:EVKB}}:~# ot-ctl factoryreset && sleep 2
  root@{{#var:EVKB}}:~# {{#var:OT_CLI_CMD}} factoryreset && sleep 2


Set Channel to 26:
Set Channel to 26:
  root@{{#var:EVKB}}:~# ot-ctl channel 26
  root@{{#var:EVKB}}:~# {{#var:OT_CLI_CMD}} channel 26
  Done
  Done


Set PAN ID to 0x1234:
Set PAN ID to 0x1234:
  root@{{#var:EVKB}}:~# ot-ctl panid 0x1234
  root@{{#var:EVKB}}:~# {{#var:OT_CLI_CMD}} panid 0x1234
  Done
  Done


Set Extended PAN ID:
Set Extended PAN ID:
  root@{{#var:EVKB}}:~# ot-ctl extpanid dead00beef00cafe
  root@{{#var:EVKB}}:~# {{#var:OT_CLI_CMD}} extpanid dead00beef00cafe
  Done
  Done


Use the Network Key printed by the server:
Use the Network Key printed by the server:
  root@{{#var:EVKB}}:~# ot-ctl networkkey c9ca829c5a194f86e141a8721f1f38aa
  root@{{#var:EVKB}}:~# {{#var:OT_CLI_CMD}} networkkey c9ca829c5a194f86e141a8721f1f38aa
  Done
  Done


Set Network Name to "ThreadTest":
Set Network Name to "ThreadTest":
  root@{{#var:EVKB}}:~# ot-ctl networkname ThreadTest
  root@{{#var:EVKB}}:~# {{#var:OT_CLI_CMD}} networkname ThreadTest
  Done
  Done


Enable Network Interface:
Enable Network Interface:
  root@{{#var:EVKB}}:~# ot-ctl ifconfig up
  root@{{#var:EVKB}}:~# {{#var:OT_CLI_CMD}} ifconfig up
  Done
  Done


Start Thread:
Start Thread:
  root@{{#var:EVKB}}:~# ot-ctl thread start
  root@{{#var:EVKB}}:~# {{#var:OT_CLI_CMD}} thread start
  Done
  Done


Set Client Mode to "Router Eligible" (rn):
Set Client Mode to "Router Eligible" (rn):
  root@{{#var:EVKB}}:~# ot-ctl mode rn
  root@{{#var:EVKB}}:~# {{#var:OT_CLI_CMD}} mode rn


Scan for available networks:
Scan for available networks:
  root@{{#var:EVKB}}:~# ot-ctl scan
  root@{{#var:EVKB}}:~# {{#var:OT_CLI_CMD}} scan
  | PAN  | MAC Address      | Ch | dBm | LQI |
  | PAN  | MAC Address      | Ch | dBm | LQI |
  +------+------------------+----+-----+-----+
  +------+------------------+----+-----+-----+
Line 149: Line 170:


Print the State:
Print the State:
  root@{{#var:EVKA}}:~# ot-ctl state
  root@{{#var:EVKA}}:~# {{#var:OT_CLI_CMD}} state
  detached
  detached
  ...wait a few seconds...
  ...wait a few seconds...
  root@{{#var:EVKA}}:~# ot-ctl state
  root@{{#var:EVKA}}:~# {{#var:OT_CLI_CMD}} state
  child
  child


Line 175: Line 196:


Print '''{{#var:EVKB}}'s''' Extended MAC Address:
Print '''{{#var:EVKB}}'s''' Extended MAC Address:
  root@{{#var:EVKB}}:~# ot-ctl eui64
  root@{{#var:EVKB}}:~# {{#var:OT_CLI_CMD}} eui64
  5affa2feffef2650
  5affa2feffef2650
  Done
  Done


Print '''{{#var:EVKA}}'s''' neighbor table:
Print '''{{#var:EVKA}}'s''' neighbor table:
  root@{{#var:EVKA}}:~# ot-ctl neighbor table
  root@{{#var:EVKA}}:~# {{#var:OT_CLI_CMD}} neighbor table
  | Role | RLOC16 | Age | Avg RSSI | Last RSSI |R|D|N| Extended MAC    | Version |
  | Role | RLOC16 | Age | Avg RSSI | Last RSSI |R|D|N| Extended MAC    | Version |
  +------+--------+-----+----------+-----------+-+-+-+------------------+---------+
  +------+--------+-----+----------+-----------+-+-+-+------------------+---------+
Line 188: Line 209:


Print '''{{#var:EVKA}}'s''' child table:
Print '''{{#var:EVKA}}'s''' child table:
  root@{{#var:EVKA}}:~# ot-ctl child table
  root@{{#var:EVKA}}:~# {{#var:OT_CLI_CMD}} child table
  | ID  | RLOC16 | Timeout    | Age        | LQ In | C_VN |R|D|N|Ver|CSL|QMsgCnt| Extended MAC    |
  | ID  | RLOC16 | Timeout    | Age        | LQ In | C_VN |R|D|N|Ver|CSL|QMsgCnt| Extended MAC    |
  +-----+--------+------------+------------+-------+------+-+-+-+---+---+-------+------------------+
  +-----+--------+------------+------------+-------+------+-+-+-+---+---+-------+------------------+
Line 200: Line 221:


'''{{#var:EVKA}}''':
'''{{#var:EVKA}}''':
  root@{{#var:EVKA}}:~# ot-ctl ipaddr
  root@{{#var:EVKA}}:~# {{#var:OT_CLI_CMD}} ipaddr
  fdde:ad00:beef:0:0:ff:fe00:fc00  # Leader's Anycast Locator (ALOC)
  fdde:ad00:beef:0:0:ff:fe00:fc00  # Leader's Anycast Locator (ALOC)
  fdde:ad00:beef:0:0:ff:fe00:0  # Routing Locator (RLOC)
  fdde:ad00:beef:0:0:ff:fe00:0  # Routing Locator (RLOC)
Line 207: Line 228:


'''{{#var:EVKB}}''':
'''{{#var:EVKB}}''':
  root@{{#var:EVKA}}:~# ot-ctl ipaddr
  root@{{#var:EVKA}}:~# {{#var:OT_CLI_CMD}} ipaddr
  fdde:ad00:beef:0:0:ff:fe00:1  # Routing Locator (RLOC)
  fdde:ad00:beef:0:0:ff:fe00:1  # Routing Locator (RLOC)
  fdde:ad00:beef:0:c177:ef1:a128:7d09  # Mesh-Local EID (ML-EID)
  fdde:ad00:beef:0:c177:ef1:a128:7d09  # Mesh-Local EID (ML-EID)
Line 214: Line 235:


Then, ping '''{{#var:EVKA}}''' (Leader) from '''{{#var:EVKB}}''' (Child) using the mesh-local address:
Then, ping '''{{#var:EVKA}}''' (Leader) from '''{{#var:EVKB}}''' (Child) using the mesh-local address:
  root@{{#var:EVKB}}:~# ot-ctl ping fdde:ad00:beef:0:0:ff:fe00:0
  root@{{#var:EVKB}}:~# {{#var:OT_CLI_CMD}} ping fdde:ad00:beef:0:0:ff:fe00:0
  16 bytes from fdde:ad00:beef:0:0:ff:fe00:0: icmp_seq=8 hlim=64 time=17ms
  16 bytes from fdde:ad00:beef:0:0:ff:fe00:0: icmp_seq=8 hlim=64 time=17ms
  1 packets transmitted, 1 packets received. Packet loss = 0.0%. Round-trip min/avg/max = 17/17.0/17 ms.
  1 packets transmitted, 1 packets received. Packet loss = 0.0%. Round-trip min/avg/max = 17/17.0/17 ms.

Revision as of 18:16, 26 February 2025

Warning: This page is designed to be used with a 'release' URL parameter.

This page is using the default release mx93-yocto-langdale-6.1.1_1.0.1-v1.2.
To view this page for a specific Variscite SoM and software release, please follow these steps:

  1. Visit variwiki.com
  2. Select your SoM
  3. Select the software release
802.15.4 OpenThread


VAR-SOM-MX93 OpenThread Overview

VAR-SOM-MX93 SoMs ordered with the WBE option feature an IW612 based tri-radio module that supports Wi-Fi 6, Bluetooth/Bluetooth Low Energy 5.2, and 802.15.4.

The 802.15.4 radio coprocessor is managed by OpenThread. Thread is an IPv6-based networking protocol designed for low-power Internet of Things devices in an IEEE802.15.4-2015 wireless mesh network. OpenThread released by Google is an open-source implementation of Thread.

The OpenThread core runs on the host processor (mx93) and communicates with the 802.15.4 coprocessor via OpenThread Daemon (ot-daemon) using SPI. Clients can connect to the ot-daemon UNIX socket and communicate using OpenThread CLI as a protocol.

Configuring ot-daemon

ot-daemon is started with the following command:

ot-daemon "spinel+spi:///dev/spidev1.0?gpio-int-device=4&gpio-int-line=29&gpio-reset-device=4_&gpio-reset-line=4_&spi-mode=0&spi-speed=1000000&spi-reset-delay=500" &

This is done automatically on boot by Variscite's ot-service and the scripts in /etc/openthread on boot. The service can be managed using systemd:

systemctl <start|stop|restart|status|enable|disable> variscite-ot.service

For example, you can stop and disable the service:

# Stop the service
systemctl stop variscite-ot

# Start the service
systemctl disable variscite-ot

Managing OpenThread using ot-ctl

ot-ctl uses the ot-daemon UNIX socket and can be used to manage OpenThread. It requires that ot-daemon is first running. As a reminder, the variscite-ot service starts this by default.

For example, you can read the extended MAC address of your device:

# ot-ctl extaddr
52fc4e6d3cd98e30
Done

The following sections demonstrate how to create a network on imx93-var-som-a and connect to the network on imx93-var-som-b.

Create OpenThread network using ot-ctl

Reset to factory settings:

root@imx93-var-som-a:~# ot-ctl factoryreset && sleep 2


Set Channel to 26:

root@imx93-var-som-a:~# ot-ctlchannel 26
Done

Set PAN ID to 0x1234:

root@imx93-var-som-a:~# ot-ctlpanid 0x1234
Done

Set Extended PAN ID:

root@imx93-var-som-a:~# ot-ctlextpanid dead00beef00cafe
Done

Generate a new networkkey (this will change everytime):

root@imx93-var-som-a:~# ot-ctlnetworkkey
c9ca829c5a194f86e141a8721f1f38aa
Done

Set Network Name to "ThreadTest":

root@imx93-var-som-a:~# ot-ctlnetworkname ThreadTest
Done


Enable Network Interface:

root@imx93-var-som-a:~# ot-ctl ifconfig up
Done

Start Thread:

root@imx93-var-som-a:~# ot-ctl thread start
Done

Print the State:

root@imx93-var-som-a:~# ot-ctl state
detached
...wait a few seconds...
root@imx93-var-som-a:~# ot-ctl state
leader

Variscite provides an example script in /etc/openthread/variscite-ot-server to create an OpenThread network. It is only meant to be an example to accelerate the development process. For example:

root@# /etc/openthread/variscite-ot-server start
State is detached, waiting for state=leader
State is detached, waiting for state=leader
State is detached, waiting for state=leader
State is leader
Network key c9ca829c5a194f86e141a8721f1f38aa saved to /tmp/ot-wpan0.key

Connect to OpenThread network using ot-ctl

Reset to factory defaults:

root@imx93-var-som-b:~# ot-ctl factoryreset && sleep 2

Set Channel to 26:

root@imx93-var-som-b:~# ot-ctl channel 26
Done

Set PAN ID to 0x1234:

root@imx93-var-som-b:~# ot-ctl panid 0x1234
Done

Set Extended PAN ID:

root@imx93-var-som-b:~# ot-ctl extpanid dead00beef00cafe
Done

Use the Network Key printed by the server:

root@imx93-var-som-b:~# ot-ctl networkkey c9ca829c5a194f86e141a8721f1f38aa
Done

Set Network Name to "ThreadTest":

root@imx93-var-som-b:~# ot-ctl networkname ThreadTest
Done

Enable Network Interface:

root@imx93-var-som-b:~# ot-ctl ifconfig up
Done

Start Thread:

root@imx93-var-som-b:~# ot-ctl thread start
Done

Set Client Mode to "Router Eligible" (rn):

root@imx93-var-som-b:~# ot-ctl mode rn

Scan for available networks:

root@imx93-var-som-b:~# ot-ctl scan
| PAN  | MAC Address      | Ch | dBm | LQI |
+------+------------------+----+-----+-----+
| 1234 | 12c8abdf0f9fe7ee | 26 | -45 | 137 |
Done

Print the State:

root@imx93-var-som-a:~# ot-ctl state
detached
...wait a few seconds...
root@imx93-var-som-a:~# ot-ctl state
child

Variscite provides an example script in /etc/openthread/variscite-ot-client to connect to an OpenThread network. It is only meant to be an example to accelerate the development process. For example:

root@imx93-var-som-b:~# /etc/openthread/variscite-ot-client start c9ca829c5a194f86e141a8721f1f38aa
Scanning for available networks:
| PAN  | MAC Address      | Ch | dBm | LQI |
+------+------------------+----+-----+-----+
| 1234 | 962ba3d53bbc9bb6 | 26 | -46 | 133 |
Done
State is detached, waiting to connect to the network
State is detached, waiting to connect to the network
State is detached, waiting to connect to the network
State is child, connected to the network

Verify to OpenThread connection

Print neighbor and child tables

Once connected, you can see imx93-var-som-b in imx93-var-som-a's neighbor table:

Print imx93-var-som-b's Extended MAC Address:

root@imx93-var-som-b:~# ot-ctl eui64
5affa2feffef2650
Done

Print imx93-var-som-a's neighbor table:

root@imx93-var-som-a:~# ot-ctl neighbor table
| Role | RLOC16 | Age | Avg RSSI | Last RSSI |R|D|N| Extended MAC     | Version |
+------+--------+-----+----------+-----------+-+-+-+------------------+---------+
|   C  | 0x8401 |   0 |      -22 |         0 |1|0|1| 56c65fbdfa6e4a80 |       3 |
Done

Print imx93-var-som-a's child table:

root@imx93-var-som-a:~# ot-ctl child table
| ID  | RLOC16 | Timeout    | Age        | LQ In | C_VN |R|D|N|Ver|CSL|QMsgCnt| Extended MAC     |
+-----+--------+------------+------------+-------+------+-+-+-+---+---+-------+------------------+
|   3 | 0x8403 |        240 |        186 |     3 |   15 |1|0|1|  3| 0 |     0 | 56c65fbdfa6e4a80 |
Done

Ping imx93-var-som-a from imx93-var-som-b

First, print the IP Addresses of imx93-var-som-a and imx93-var-som-b.

imx93-var-som-a:

root@imx93-var-som-a:~# ot-ctl ipaddr
fdde:ad00:beef:0:0:ff:fe00:fc00  # Leader's Anycast Locator (ALOC)
fdde:ad00:beef:0:0:ff:fe00:0  # Routing Locator (RLOC)
fdde:ad00:beef:0:f5f2:aaeb:8a8c:a9fc  # Mesh-Local EID (ML-EID)
fe80:0:0:0:1442:b824:c762:fa70  # Link-Local Address (LLA)

imx93-var-som-b:

root@imx93-var-som-a:~# ot-ctl ipaddr
fdde:ad00:beef:0:0:ff:fe00:1  # Routing Locator (RLOC)
fdde:ad00:beef:0:c177:ef1:a128:7d09  # Mesh-Local EID (ML-EID)
fe80:0:0:0:54c6:5fbd:fa6e:4a80  # Link-Local Address (LLA)


Then, ping imx93-var-som-a (Leader) from imx93-var-som-b (Child) using the mesh-local address:

root@imx93-var-som-b:~# ot-ctl ping fdde:ad00:beef:0:0:ff:fe00:0
16 bytes from fdde:ad00:beef:0:0:ff:fe00:0: icmp_seq=8 hlim=64 time=17ms
1 packets transmitted, 1 packets received. Packet loss = 0.0%. Round-trip min/avg/max = 17/17.0/17 ms.
Done