Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/networking/misc/openthread/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ BOARD_WHITELIST := \
openmote-cc2538 \
nrf52840dk \
nrf52840-mdk \
adafruit-feather-nrf52840-sense \
reel \
#

Expand Down
10 changes: 5 additions & 5 deletions examples/networking/misc/openthread/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open source implementation of [Thread](https://threadgroup.org/) on RIOT.
The [Command Line Interface](https://github.com/openthread/openthread/blob/master/examples/apps/cli/README.md) of
OpenThread was ported. Please check the
[full documentation](https://github.com/openthread/openthread/blob/master/src/cli/README.md)
of the CLI for usage information.
of the CLI for usage information. Commands start with prefix 'ot'.

You can either build a FTD or MTD firmware:
- MTD: A Minimal Thread Device does not have router functionality compiled in.
Expand Down Expand Up @@ -40,13 +40,13 @@ make BOARD=<target> clean all flash OPENTHREAD_TYPE=mtd
make BOARD=<target> clean all flash OPENTHREAD_TYPE=ftd
```

2. Check the state of the node with `state`. In the beginning, it should be
2. Check the state of the node with `ot state`. In the beginning, it should be
`detached`, but after some seconds it should become `leader`

3. Start another node and check that it becomes `router`. There is only one
leader in a Thread network.

4. Get the mesh IP address of a node with `ipaddr`.
4. Get the mesh IP address of a node with `ot ipaddr`.
```
ipaddr
fdde:ad00:beef::ff:fe00:8000
Expand All @@ -59,9 +59,9 @@ ipaddr
ping fdde:ad00:beef:0:946a:c722:a5d9:848
```

6. You can try IEEE802.15.4 scan with `scan` command
6. You can try IEEE802.15.4 scan with `ot scan` command

7. You can also check other commands with `help`
7. You can also check other commands with `ot help`


## OpenThread port on RIOT status
Expand Down
5 changes: 5 additions & 0 deletions examples/networking/misc/openthread/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include <stdio.h>

#include "shell.h"

#include "ot.h"
#include "openthread/thread.h"

Expand Down Expand Up @@ -45,5 +47,8 @@ int main(void)
*/
event_post(openthread_get_evq(), &event_panid);

char line_buf[SHELL_DEFAULT_BUFSIZE];
shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);

return 0;
}
1 change: 1 addition & 0 deletions makefiles/pseudomodules.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ PSEUDOMODULES += shell_cmd_nice
PSEUDOMODULES += shell_cmd_nimble_netif
PSEUDOMODULES += shell_cmd_nimble_statconn
PSEUDOMODULES += shell_cmd_opendsme
PSEUDOMODULES += shell_cmd_openthread
PSEUDOMODULES += shell_cmd_openwsn
PSEUDOMODULES += shell_cmd_pm
PSEUDOMODULES += shell_cmd_ps
Expand Down
1 change: 1 addition & 0 deletions pkg/openthread/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@ $(PKG_BUILD_DIR)/Makefile:
-DOT_PLATFORM=NO \
-DOT_CONFIG="$(RIOTBASE)/pkg/openthread/include/platform_config.h" \
-DOT_APP_CLI=$(OT_APP_CLI) \
-DOT_CLI_TRANSPORT=CONSOLE \
-DOT_JOINER=$(OT_JOINER) \
-DOT_COAP=$(OT_COAP)
12 changes: 8 additions & 4 deletions pkg/openthread/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
USEMODULE += openthread_contrib

USEMODULE += event
USEMODULE += l2util
USEMODULE += netdev
USEMODULE += openthread_contrib
USEMODULE += openthread_contrib_netdev
USEMODULE += l2util

ifneq (,$(filter openthread-cli-%,$(USEMODULE)))
USEMODULE += shell_cmds_default
endif

USEMODULE += ztimer
USEMODULE += ztimer_msec
USEMODULE += event

FEATURES_REQUIRED += cpp
2 changes: 1 addition & 1 deletion pkg/openthread/contrib/netdev/openthread_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static void *_openthread_event_loop(void *arg)
sInstance = otInstanceInitSingle();

#if defined(MODULE_OPENTHREAD_CLI_FTD) || defined(MODULE_OPENTHREAD_CLI_MTD)
otCliUartInit(sInstance);
ot_shell_init(sInstance);
/* Init default parameters */
otPanId panid = OPENTHREAD_PANID;
uint8_t channel = OPENTHREAD_CHANNEL;
Expand Down
5 changes: 5 additions & 0 deletions pkg/openthread/include/ot.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@
/** @brief sizeof in bytes the two first members of she serial structure */
#define OPENTHREAD_SIZEOF_LENGTH_AND_FREEBUFF (4U)
/** @brief sizeof the serial buffer */
#define OPENTHREAD_SERIAL_BUFFER_SIZE OPENTHREAD_SIZEOF_LENGTH_AND_FREEBUFF + 100

Check warning on line 76 in pkg/openthread/include/ot.h

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
/** @brief sizeof the spinel payload data */
#define OPENTHREAD_SERIAL_BUFFER__PAYLOAD_SIZE OPENTHREAD_SERIAL_BUFFER_SIZE - OPENTHREAD_SIZEOF_LENGTH_AND_FREEBUFF

Check warning on line 78 in pkg/openthread/include/ot.h

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
/** @brief error when no more buffer available */
#define OPENTHREAD_ERROR_NO_EMPTY_SERIAL_BUFFER -1
/** @brief serial buffer ready to use */
Expand Down Expand Up @@ -156,13 +156,18 @@
* @return PID of OpenThread thread
* @return -EINVAL if there was an error creating the thread
*/
int openthread_netdev_init(char *stack, int stacksize, char priority, const char *name, netdev_t *netdev);

Check warning on line 159 in pkg/openthread/include/ot.h

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters

/**
* @brief Init OpenThread random
*/
void ot_random_init(void);

/**
* @brief Init shell for OpenThread CLI
*/
void ot_shell_init(otInstance *aInstance);

#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions sys/shell/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ ifneq (,$(filter shell_cmds_default,$(USEMODULE)))
ifneq (,$(filter opendsme,$(USEPKG)))
USEMODULE += shell_cmd_opendsme
endif
ifneq (,$(filter openthread-cli-%,$(USEMODULE)))
USEMODULE += shell_cmd_openthread
endif
ifneq (,$(filter openwsn,$(USEPKG)))
USEMODULE += shell_cmd_openwsn
endif
Expand Down
55 changes: 55 additions & 0 deletions sys/shell/cmds/openthread.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* SPDX-FileCopyrightText: 2025 TU Dresden
* SPDX-License-Identifier: LGPL-2.1-only
*/

/**
* @ingroup sys_shell_commands
* @{
*
* @file
* @brief Shell command implementation for OpenThread
*
* @author Moritz Voigt <[email protected]>
*
* @}
*/
#include <stdio.h>
#include <string.h>

#include "shell.h"
#include "openthread/cli.h"

static int ot_console_cb(const char *abuf, uint16_t bufsize, void *context)
{
(void) context;
if (bufsize > 0) {
printf("%.*s", bufsize, abuf);
}
return 0;
}

static int ot_cmd(int argc, char **argv)
{
/* Join all arguments after "ot" into a single space-separated string */
for (int i = 1; i < argc - 1; i++) {
char *arg = argv[i];
arg += strlen(arg);
*arg = ' ';
}

if (strlen(argv[1]) != 0) {
otCliConsoleInputLine(argv[1], strlen(argv[1]));
}
else {
otCliConsoleInputLine("help", strlen("help"));
}
return 0;
}

SHELL_COMMAND(ot, "Use commands from OpenThread CLI", ot_cmd);

void ot_shell_init(otInstance *aInstance)
{
otCliConsoleInit(aInstance, ot_console_cb, NULL);
}
Loading