Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • eclipse/oniro-blueprints/transparent-gateway/openthread-node-zephyr
  • stefanschmidt/openthread-node-zephyr
  • pcoval/openthread-node-zephyr
  • mrfrank/openthread-node-zephyr
4 results
Show changes
Commits on Source (4)
......@@ -4,4 +4,11 @@ cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(openthread_node)
target_sources(app PRIVATE src/main.c)
target_include_directories(
app
PRIVATE
${ZEPHYR_BASE}/subsys/net/ip
)
FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
......@@ -20,3 +20,73 @@ flashing is the easiest option:
```
$ west build -p auto -b arduino_nano_33_ble . && west flash
```
## How to setup a static network setting between Linux and zephyr for development
For development and testing purpose it might be useful to configure a static
thread link between Linux and zephyr without the involvement of any
commissioning process. This setup will use a networkkey that is hardcoded into
the Zephyr firmware, which make this guide suitable for development purpose
only. Do *not* use this in production.
### Zephyr: building and flashing with static network config overlay
When using the overlay-static.conf overlay file in the build the
joiner/commissioner functionality is disabled and a static networkkey and
setting configured.
```
$ west build -b arduino_nano_33_ble -- -DCONF_FILE="prj.conf overlay-static.conf" .
$ west flash
```
### Linux: build and flash OT RCP on Zephyr onto Arduino Nano 33 BLE:
On the Linux side we need 3 steps to setup.
Build a OpenThread radio co-processor firmware for a second Arduino Nano (this
one will act as a Thread radio for the Linux host). This is building a sample
that lives within the main Zephyr tree.
```
$ west build -b arduino_nano_33_ble -- -DCONF_FILE="prj.conf overlay-rcp.conf overlay-usb-nrf-br.conf" -DDTC_OVERLAY_FILE="usb.overlay" -DCONFIG_OPENTHREAD_THREAD_VERSION_1_2=y samples/net/openthread/coprocessor/
$ west flash
```
### Build and run ot-daemon:
After flashing the ready we need to build the OpenThread daemon that runs on the
Linux host and uses the radio to interact with a Thread network.
When using the radio co-processor firmware on top of Zephyr we need to ensure that ot-daemon does handle USB reset properly. The compile flag -DOT_SPINEL_RESET_CONNECTION=ON, as well as, the runtime parameter &uart-reset is taking care of the reset handling.
But there is still the underlying problem that during after a USB reset the
/dev/ttyACM0 device will come back as /dev/ttyACM1 for example. So instead of
using the ttyACMx device name we will use a serial/by-id lookup device name.
When you first attach the Ardunio to the Linux host, after flashing the radio
co-processor firmware, check the name in /dev/serial/by-id/ and not it down for
later use. (It's the one that points to the current /dev/ttyACMx device and has
Zephyr in its name). This device name will stay stable over USB reset so we no
longer need to worry about device names changing underneath our daemon process.
```
git clone https://github.com/openthread/openthread.git
cd openthread
./bootstrap
./script/cmake-build posix -DOT_SPINEL_RESET_CONNECTION=ON -DOT_THREAD_VERSION=1.2 -DOT_DAEMON=ON
sudo build/posix/src/posix/ot-daemon -v 'spinel+hdlc+uart:///dev/serial/by-id/usb-ZEPHYR_OpenThread_CoProcessor_NRF_E96CD39E53C49869-if00?uart-baudrate=115200&uart-reset'
```
### Configure the static Thread network settings on Linux
th the radio connected and ot-daemon running we can start the configuration
script from another shell. It does use the ot-ctl commandline tool to configure
the static Thread network to match the zephyr version.
```
sudo ./static-openthread-configuration.sh
```
The first device started should act as the Thread network leader and the second
one joining as child and being promoted to a router over time. IPv6 connectivity
between the two devices is working now and opens the floor for transport and
application layer protocols to use it.
# This configuration uses a hardcoded network key and is not suitable for
# usage besides debugging and development.
# PAN ID 0x1357 to decimal 4951
CONFIG_OPENTHREAD_PANID=4951
CONFIG_OPENTHREAD_CHANNEL=26
CONFIG_OPENTHREAD_NETWORK_NAME="OniroThread"
CONFIG_OPENTHREAD_XPANID="0x11112222deadbeef"
CONFIG_OPENTHREAD_NETWORKKEY="00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff"
CONFIG_OPENTHREAD_JOINER=n
CONFIG_OPENTHREAD_JOINER_AUTOSTART=n
CONFIG_OPENTHREAD_JOINER_PSKD=""
CONFIG_OPENTHREAD_SLAAC=y
......@@ -85,5 +85,7 @@ CONFIG_OPENTHREAD_JOINER_AUTOSTART=y
CONFIG_OPENTHREAD_JOINER_PSKD="J01NU5"
CONFIG_OPENTHREAD_SLAAC=y
CONFIG_OPENTHREAD_THREAD_VERSION_1_2=y
# Enable diagnostic module, uncomment if needed
#CONFIG_OPENTHREAD_DIAG=y
......@@ -8,7 +8,8 @@
*/
#include <logging/log.h>
LOG_MODULE_REGISTER(openthreadnode, LOG_LEVEL_DBG);
LOG_MODULE_REGISTER(openthreadnode, LOG_LEVEL_INF);
#include <net/net_pkt.h>
#include <errno.h>
#include <zephyr.h>
......@@ -19,5 +20,17 @@ LOG_MODULE_REGISTER(openthreadnode, LOG_LEVEL_DBG);
void main(void)
{
struct net_if *iface;
static char buf[17];
char *idx = buf;
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(OPENTHREAD));
for (int i = 0; i < net_if_get_link_addr(iface)->len; i++) {
snprintf(idx, 3, "%02x", net_if_get_link_addr(iface)->addr[i]);
idx += 2;
}
LOG_INF(APP_BANNER);
LOG_INF("OpenThread commissioner QR code: https://dhrishi.github.io/connectedhomeip/qrcode.html?data=v=1%%26%%26eui=%s%%26%%26cc=J01NU5",buf );
}
#!/bin/sh
# SPDX-FileCopyrightText: Huawei Inc.
#
# SPDX-License-Identifier: Apache-2.0
set -e
ot-ctl thread stop
ot-ctl ifconfig down
ot-ctl dataset clear
ot-ctl dataset init new
ot-ctl dataset panid 0x1357
ot-ctl dataset extpanid 11112222deadbeef
ot-ctl dataset networkname OniroThread
ot-ctl dataset channel 26
ot-ctl dataset networkkey 00112233445566778899aabbccddeeff
ot-ctl dataset commit active
ot-ctl ifconfig up
ot-ctl thread start