diff --git a/examples/networking/misc/openthread/Makefile b/examples/networking/misc/openthread/Makefile index cd5ac9cdf1ec..fef12da3333a 100644 --- a/examples/networking/misc/openthread/Makefile +++ b/examples/networking/misc/openthread/Makefile @@ -20,6 +20,7 @@ BOARD_WHITELIST := \ openmote-cc2538 \ nrf52840dk \ nrf52840-mdk \ + adafruit-feather-nrf52840-sense \ reel \ # diff --git a/examples/networking/misc/openthread/README.md b/examples/networking/misc/openthread/README.md index 0854debc67c4..1015f53b78c7 100644 --- a/examples/networking/misc/openthread/README.md +++ b/examples/networking/misc/openthread/README.md @@ -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. @@ -40,13 +40,13 @@ make BOARD= clean all flash OPENTHREAD_TYPE=mtd make BOARD= 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 @@ -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 diff --git a/examples/networking/misc/openthread/main.c b/examples/networking/misc/openthread/main.c index fc397a9d9abb..ee8dd0cb16df 100644 --- a/examples/networking/misc/openthread/main.c +++ b/examples/networking/misc/openthread/main.c @@ -12,6 +12,8 @@ #include +#include "shell.h" + #include "ot.h" #include "openthread/thread.h" @@ -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; } diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index cfc84f7fbe4c..82be1d001222 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -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 diff --git a/pkg/openthread/Makefile b/pkg/openthread/Makefile index 3ca66d08bb0f..94a841b64c46 100644 --- a/pkg/openthread/Makefile +++ b/pkg/openthread/Makefile @@ -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) diff --git a/pkg/openthread/Makefile.dep b/pkg/openthread/Makefile.dep index a1079c2ec503..fe48da111d6e 100644 --- a/pkg/openthread/Makefile.dep +++ b/pkg/openthread/Makefile.dep @@ -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 diff --git a/pkg/openthread/contrib/netdev/openthread_netdev.c b/pkg/openthread/contrib/netdev/openthread_netdev.c index c815f1f93877..d561eda2bcd0 100644 --- a/pkg/openthread/contrib/netdev/openthread_netdev.c +++ b/pkg/openthread/contrib/netdev/openthread_netdev.c @@ -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; diff --git a/pkg/openthread/include/ot.h b/pkg/openthread/include/ot.h index e77bdbe08b23..08532b4bea8d 100644 --- a/pkg/openthread/include/ot.h +++ b/pkg/openthread/include/ot.h @@ -163,6 +163,11 @@ int openthread_netdev_init(char *stack, int stacksize, char priority, const char */ void ot_random_init(void); +/** + * @brief Init shell for OpenThread CLI + */ +void ot_shell_init(otInstance *aInstance); + #ifdef __cplusplus } #endif diff --git a/sys/shell/Makefile.dep b/sys/shell/Makefile.dep index d4ca0798b2e3..52ae38812909 100644 --- a/sys/shell/Makefile.dep +++ b/sys/shell/Makefile.dep @@ -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 diff --git a/sys/shell/cmds/openthread.c b/sys/shell/cmds/openthread.c new file mode 100644 index 000000000000..f1cbd7a60d23 --- /dev/null +++ b/sys/shell/cmds/openthread.c @@ -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 + * + * @} + */ +#include +#include + +#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); +}