mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-04 21:24:32 +02:00
Merge branch 'feature/ot_extension_command_refactor' into 'master'
openthread: ot extension command refactor See merge request espressif/esp-idf!16536
This commit is contained in:
22
examples/openthread/extension_command/CMakeLists.txt
Normal file
22
examples/openthread/extension_command/CMakeLists.txt
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
set(srcs "src/esp_ot_cli_extension.c")
|
||||||
|
|
||||||
|
if(CONFIG_OPENTHREAD_CLI_IPERF)
|
||||||
|
list(APPEND srcs "src/esp_ot_iperf.c")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CONFIG_OPENTHREAD_CLI_TCP_SOCKET)
|
||||||
|
list(APPEND srcs "src/esp_ot_tcp_socket.c")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CONFIG_OPENTHREAD_CLI_UDP_SOCKET)
|
||||||
|
list(APPEND srcs "src/esp_ot_udp_socket.c")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CONFIG_OPENTHREAD_CLI_WIFI)
|
||||||
|
list(APPEND srcs "src/esp_ot_wifi_cmd.c")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(include "include")
|
||||||
|
idf_component_register(SRCS "${srcs}"
|
||||||
|
INCLUDE_DIRS "${include}"
|
||||||
|
REQUIRES lwip openthread iperf)
|
44
examples/openthread/extension_command/Kconfig.projbuild
Normal file
44
examples/openthread/extension_command/Kconfig.projbuild
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
menu "OpenThread Extension CLI"
|
||||||
|
|
||||||
|
menuconfig OPENTHREAD_CLI_ESP_EXTENSION
|
||||||
|
depends on OPENTHREAD_FTD || OPENTHREAD_MTD
|
||||||
|
bool "Enable Espressif's extended features"
|
||||||
|
default y
|
||||||
|
help
|
||||||
|
Enable Espressif's extended features.
|
||||||
|
|
||||||
|
config OPENTHREAD_CLI_IPERF
|
||||||
|
bool "Enable iperf command"
|
||||||
|
depends on OPENTHREAD_CLI_ESP_EXTENSION
|
||||||
|
default y
|
||||||
|
|
||||||
|
config OPENTHREAD_CLI_TCP_SOCKET
|
||||||
|
bool "Enable TCP socket command"
|
||||||
|
depends on OPENTHREAD_CLI_ESP_EXTENSION
|
||||||
|
default y
|
||||||
|
|
||||||
|
config OPENTHREAD_CLI_TCP_SERVER_PORT
|
||||||
|
int "the port of TCP server"
|
||||||
|
default 12345
|
||||||
|
depends on OPENTHREAD_CLI_TCP_SOCKET
|
||||||
|
help
|
||||||
|
Set the connect port of socket
|
||||||
|
|
||||||
|
config OPENTHREAD_CLI_UDP_SOCKET
|
||||||
|
bool "Enable UDP socket command"
|
||||||
|
depends on OPENTHREAD_CLI_ESP_EXTENSION
|
||||||
|
default y
|
||||||
|
|
||||||
|
config OPENTHREAD_CLI_UDP_SERVER_PORT
|
||||||
|
int "the port of UDP server"
|
||||||
|
default 54321
|
||||||
|
depends on OPENTHREAD_CLI_UDP_SOCKET
|
||||||
|
help
|
||||||
|
Set the connect port of socket
|
||||||
|
|
||||||
|
config OPENTHREAD_CLI_WIFI
|
||||||
|
bool "Enable wifi connection command"
|
||||||
|
depends on OPENTHREAD_CLI_ESP_EXTENSION && OPENTHREAD_BORDER_ROUTER
|
||||||
|
default y
|
||||||
|
|
||||||
|
endmenu
|
131
examples/openthread/extension_command/README.md
Normal file
131
examples/openthread/extension_command/README.md
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
# Openthread Extension Commands
|
||||||
|
|
||||||
|
The ESP OpenThread examples provide a series of extension commands in addition to the standard [OpenThread CLI](https://github.com/openthread/openthread/blob/main/src/cli/README.md).
|
||||||
|
The extension commands are available in the following examples:
|
||||||
|
* [ot_cli](../ot_cli)
|
||||||
|
* [ot_br](../ot_br)
|
||||||
|
|
||||||
|
## Enabling the extension commands
|
||||||
|
|
||||||
|
To enable OpenThread extension commands, the following Kconfig option needs to be enabled:
|
||||||
|
`OpenThread Extension CLI` -> `Enable Espressif's extended features`.
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
* [iperf](#iperf)
|
||||||
|
* [tcpsockclient](#tcpsockclient)
|
||||||
|
* [tcpsockserver](#tcpsockserver)
|
||||||
|
* [udpsockclient](#udpsockclient)
|
||||||
|
* [udpsockserver](#udpsockserver)
|
||||||
|
* [wifi](#wifi)
|
||||||
|
|
||||||
|
### iperf
|
||||||
|
|
||||||
|
Iperf is a tool for performing TCP or UDP throughput on the Thread network.
|
||||||
|
|
||||||
|
For running iperf, you need to have two Thread devices on the same network.
|
||||||
|
|
||||||
|
* General Options
|
||||||
|
|
||||||
|
```bash
|
||||||
|
iperf
|
||||||
|
---iperf parameter---
|
||||||
|
-s : server mode, only receive
|
||||||
|
-u : upd mode
|
||||||
|
-V : use IPV6 address
|
||||||
|
-c <addr> : client mode, only transmit
|
||||||
|
-i <interval> : seconds between periodic bandwidth reports
|
||||||
|
-t <time> : time in seconds to transmit for (default 10 secs)
|
||||||
|
-p <port> : server port to listen on/connect to
|
||||||
|
-l <len_send_buf> : the lenth of send buffer
|
||||||
|
---example---
|
||||||
|
create a tcp server : iperf -s -i 3 -p 5001 -t 60
|
||||||
|
create a udp client : iperf -c <addr> -u -i 3 -t 60 -p 5001 -l 512
|
||||||
|
Done
|
||||||
|
```
|
||||||
|
|
||||||
|
* Typical usage
|
||||||
|
|
||||||
|
For measuring the TCP throughput, first create an iperf service on one node:
|
||||||
|
```bash
|
||||||
|
> iperf -V -s -t 20 -i 3 -p 5001
|
||||||
|
Done
|
||||||
|
```
|
||||||
|
|
||||||
|
Then create an iperf client connecting to the service on another node. Here we use `fdde:ad00:beef:0:a7c6:6311:9c8c:271b` as the example service address.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
> iperf -V -c fdde:ad00:beef:0:a7c6:6311:9c8c:271b -t 20 -i 1 -p 5001 -l 85
|
||||||
|
Done
|
||||||
|
Interval Bandwidth
|
||||||
|
0- 1 sec 0.05 Mbits/sec
|
||||||
|
1- 2 sec 0.05 Mbits/sec
|
||||||
|
2- 3 sec 0.05 Mbits/sec
|
||||||
|
3- 4 sec 0.05 Mbits/sec
|
||||||
|
4- 5 sec 0.05 Mbits/sec
|
||||||
|
...
|
||||||
|
19- 20 sec 0.05 Mbits/sec
|
||||||
|
0- 20 sec 0.05 Mbits/sec
|
||||||
|
```
|
||||||
|
|
||||||
|
For measuring the UDP throughput, first create an iperf service similarly:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
> iperf -V -u -s -t 20 -i 3 -p 5001
|
||||||
|
Done
|
||||||
|
```
|
||||||
|
|
||||||
|
Then create an iperf client:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
> iperf -V -u -c fdde:ad00:beef:0:a7c6:6311:9c8c:271b -t 20 -i 1 -p 5001 -l 85
|
||||||
|
Done
|
||||||
|
```
|
||||||
|
|
||||||
|
### tcpsockserver
|
||||||
|
|
||||||
|
Used for creating a tcp server.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
> tcpsockserver
|
||||||
|
Done
|
||||||
|
I (1310225) ot_socket: Socket created
|
||||||
|
I (1310225) ot_socket: Socket bound, port 12345
|
||||||
|
I (1310225) ot_socket: Socket listening, timeout is 30 seconds
|
||||||
|
```
|
||||||
|
|
||||||
|
### tcpsockclient
|
||||||
|
|
||||||
|
Used for creating a tcp client.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
> tcpsockclient fdde:ad00:beef:0:a7c6:6311:9c8c:271b
|
||||||
|
Done
|
||||||
|
ot_socket: Socket created, connecting to fdde:ad00:beef:0:a7c6:6311:9c8c:271b:12345
|
||||||
|
ot_socket: Successfully connected
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
### udpsockserver
|
||||||
|
|
||||||
|
Used for creating a udp server.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
> udpsockserver
|
||||||
|
Done
|
||||||
|
I (1310225) ot_socket: Socket created
|
||||||
|
I (1310225) ot_socket: Socket bound, port 12345
|
||||||
|
I (1310225) ot_socket: Socket listening, timeout is 30 seconds
|
||||||
|
```
|
||||||
|
|
||||||
|
### udpsockclient
|
||||||
|
|
||||||
|
Used for creating a udp client. Note that the client shall be connected to the same Thread network as the server.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
> udpsockclient fdde:ad00:beef:0:a7c6:6311:9c8c:271b
|
||||||
|
Done
|
||||||
|
ot_socket: Socket created, connecting to fdde:ad00:beef:0:a7c6:6311:9c8c:271b:12345
|
||||||
|
ot_socket: Successfully connected
|
||||||
|
...
|
||||||
|
```
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: CC0-1.0
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*
|
*
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: CC0
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*
|
*
|
||||||
* OpenThread Command Line Example
|
* OpenThread Command Line Example
|
||||||
*
|
*
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: CC0
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*
|
*
|
||||||
* OpenThread Command Line Example
|
* OpenThread Command Line Example
|
||||||
*
|
*
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: CC0-1.0
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*
|
*
|
||||||
@@ -20,16 +20,10 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief User command "sta" process.
|
* @brief User command "wifi" process.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void esp_ot_process_wifi_sta(void *aContext, uint8_t aArgsLength, char *aArgs[]);
|
void esp_ot_process_wifi_cmd(void *aContext, uint8_t aArgsLength, char *aArgs[]);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief User command "wifiinfo" process.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void esp_ot_process_get_wifi_info(void *aContext, uint8_t aArgsLength, char *aArgs[]);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Wifi netif init.
|
* @brief Wifi netif init.
|
@@ -17,18 +17,28 @@
|
|||||||
#include "esp_ot_iperf.h"
|
#include "esp_ot_iperf.h"
|
||||||
#include "esp_ot_tcp_socket.h"
|
#include "esp_ot_tcp_socket.h"
|
||||||
#include "esp_ot_udp_socket.h"
|
#include "esp_ot_udp_socket.h"
|
||||||
|
#include "esp_ot_wifi_cmd.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/portmacro.h"
|
#include "freertos/portmacro.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "openthread/cli.h"
|
#include "openthread/cli.h"
|
||||||
|
|
||||||
static const otCliCommand kCommands[] = {
|
static const otCliCommand kCommands[] = {
|
||||||
|
#if CONFIG_OPENTHREAD_CLI_TCP_SOCKET
|
||||||
{"tcpsockserver", esp_ot_process_tcp_server},
|
{"tcpsockserver", esp_ot_process_tcp_server},
|
||||||
{"tcpsockclient", esp_ot_process_tcp_client},
|
{"tcpsockclient", esp_ot_process_tcp_client},
|
||||||
|
#endif // CONFIG_OPENTHREAD_CLI_TCP_SOCKET
|
||||||
|
#if CONFIG_OPENTHREAD_CLI_UDP_SOCKET
|
||||||
{"udpsockserver", esp_ot_process_udp_server},
|
{"udpsockserver", esp_ot_process_udp_server},
|
||||||
{"udpsockclient", esp_ot_process_udp_client},
|
{"udpsockclient", esp_ot_process_udp_client},
|
||||||
{"mcast", esp_ot_process_mcast_group},
|
{"mcast", esp_ot_process_mcast_group},
|
||||||
{"iperf", esp_ot_process_iperf}
|
#endif // CONFIG_OPENTHREAD_CLI_UDP_SOCKET
|
||||||
|
#if CONFIG_OPENTHREAD_CLI_IPERF
|
||||||
|
{"iperf", esp_ot_process_iperf},
|
||||||
|
#endif // CONFIG_OPENTHREAD_CLI_IPERF
|
||||||
|
#if CONFIG_OPENTHREAD_CLI_WIFI
|
||||||
|
{"wifi", esp_ot_process_wifi_cmd},
|
||||||
|
#endif // CONFIG_OPENTHREAD_CLI_WIFI
|
||||||
};
|
};
|
||||||
|
|
||||||
void esp_cli_custom_command_init()
|
void esp_cli_custom_command_init()
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: CC0
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*
|
*
|
||||||
* OpenThread Command Line Example
|
* OpenThread Command Line Example
|
||||||
*
|
*
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: CC0
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*
|
*
|
||||||
* OpenThread Command Line Example
|
* OpenThread Command Line Example
|
||||||
*
|
*
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: CC0-1.0
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*
|
*
|
||||||
@@ -107,19 +107,23 @@ static void wifi_join(const char *ssid, const char *psk)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void esp_ot_process_wifi_sta(void *aContext, uint8_t aArgsLength, char *aArgs[])
|
void esp_ot_process_wifi_cmd(void *aContext, uint8_t aArgsLength, char *aArgs[])
|
||||||
{
|
{
|
||||||
char ssid[100] = "";
|
char ssid[100] = "";
|
||||||
char psk[100] = "";
|
char psk[100] = "";
|
||||||
(void)(aContext);
|
(void)(aContext);
|
||||||
if (aArgsLength == 0) {
|
if (aArgsLength == 0) {
|
||||||
otCliOutputFormat("---wifi sta parameter---\n");
|
otCliOutputFormat("---wifi parameter---\n");
|
||||||
|
otCliOutputFormat("connect\n");
|
||||||
otCliOutputFormat("-s : wifi ssid\n");
|
otCliOutputFormat("-s : wifi ssid\n");
|
||||||
otCliOutputFormat("-p : wifi psk\n");
|
otCliOutputFormat("-p : wifi psk\n");
|
||||||
otCliOutputFormat("---example---\n");
|
otCliOutputFormat("---example---\n");
|
||||||
otCliOutputFormat("join a wifi:\nssid: threadcertAP \npsk: threadcertAP : sta -s threadcertAP -p threadcertAP\n");
|
otCliOutputFormat("join a wifi:\nssid: threadcertAP \npsk: threadcertAP : wifi connect -s threadcertAP -p threadcertAP\n");
|
||||||
} else {
|
otCliOutputFormat("state : get wifi state, disconnect or connect\n");
|
||||||
for (int i = 0; i < aArgsLength; i++) {
|
otCliOutputFormat("---example---\n");
|
||||||
|
otCliOutputFormat("get wifi state : wifi state\n");
|
||||||
|
} else if (strcmp(aArgs[0], "connect") == 0) {
|
||||||
|
for (int i = 1; i < aArgsLength; i++) {
|
||||||
if (strcmp(aArgs[i], "-s") == 0) {
|
if (strcmp(aArgs[i], "-s") == 0) {
|
||||||
i++;
|
i++;
|
||||||
strcpy(ssid, aArgs[i]);
|
strcpy(ssid, aArgs[i]);
|
||||||
@@ -135,39 +139,13 @@ void esp_ot_process_wifi_sta(void *aContext, uint8_t aArgsLength, char *aArgs[])
|
|||||||
} else {
|
} else {
|
||||||
otCliOutputFormat("wifi has already connected\n");
|
otCliOutputFormat("wifi has already connected\n");
|
||||||
}
|
}
|
||||||
}
|
} else if (strcmp(aArgs[0], "state") == 0) {
|
||||||
}
|
|
||||||
|
|
||||||
void esp_ot_process_get_wifi_info(void *aContext, uint8_t aArgsLength, char *aArgs[])
|
|
||||||
{
|
|
||||||
(void)(aContext);
|
|
||||||
if (aArgsLength == 0) {
|
|
||||||
otCliOutputFormat("---get wifi informations---\n");
|
|
||||||
otCliOutputFormat("-i : get sta addr\n");
|
|
||||||
otCliOutputFormat("-s : get wifi state, disconnect or connect\n");
|
|
||||||
} else {
|
|
||||||
for (int i = 0; i < aArgsLength; i++) {
|
|
||||||
if (strcmp(aArgs[i], "-i") == 0) {
|
|
||||||
if (s_wifi_connected) {
|
|
||||||
esp_netif_ip_info_t local_ip;
|
|
||||||
char addr_str[128];
|
|
||||||
esp_netif_get_ip_info(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"), &local_ip);
|
|
||||||
ip4addr_ntoa_r((ip4_addr_t *)(&local_ip.ip), addr_str, sizeof(addr_str) - 1);
|
|
||||||
otCliOutputFormat("inet %s\n");
|
|
||||||
esp_ip6_addr_t if_ip6;
|
|
||||||
esp_netif_get_ip6_linklocal(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"), &if_ip6);
|
|
||||||
ip6addr_ntoa_r((ip6_addr_t *)(&if_ip6), addr_str, sizeof(addr_str) - 1);
|
|
||||||
otCliOutputFormat("inet6 %s\n", addr_str);
|
|
||||||
} else {
|
|
||||||
otCliOutputFormat("wifi is disconnected\n");
|
|
||||||
}
|
|
||||||
} else if (strcmp(aArgs[i], "-s") == 0) {
|
|
||||||
if (s_wifi_connected) {
|
if (s_wifi_connected) {
|
||||||
otCliOutputFormat("connected\n");
|
otCliOutputFormat("connected\n");
|
||||||
} else {
|
} else {
|
||||||
otCliOutputFormat("disconnected\n");
|
otCliOutputFormat("disconnected\n");
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
}
|
otCliOutputFormat("invalid commands\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -4,7 +4,9 @@ cmake_minimum_required(VERSION 3.5)
|
|||||||
|
|
||||||
# (Not part of the boilerplate)
|
# (Not part of the boilerplate)
|
||||||
# This example uses an extra component for common functions such as Wi-Fi and Ethernet connection.
|
# This example uses an extra component for common functions such as Wi-Fi and Ethernet connection.
|
||||||
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
|
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common
|
||||||
|
$ENV{IDF_PATH}/examples/common_components/iperf
|
||||||
|
$ENV{IDF_PATH}/examples/openthread/extension_command)
|
||||||
|
|
||||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
project(esp_ot_br)
|
project(esp_ot_br)
|
||||||
|
@@ -34,7 +34,7 @@ Enable `OPENTHREAD_BR_AUTO_START`, configure the `CONFIG_EXAMPLE_WIFI_SSID` and
|
|||||||
The device will connect to Wi-Fi and form a Thread network automatically after bootup.
|
The device will connect to Wi-Fi and form a Thread network automatically after bootup.
|
||||||
|
|
||||||
- Manual mode
|
- Manual mode
|
||||||
Disable `OPENTHREAD_BR_AUTO_START`, and use the CLI command to configure the Wi-Fi and form Thread network manually.
|
Disable `OPENTHREAD_BR_AUTO_START` and enable `OPENTHREAD_CLI_ESP_EXTENSION`. `wifi` command will be added for connecting the device to the Wi-Fi network.
|
||||||
|
|
||||||
### Build, Flash, and Run
|
### Build, Flash, and Run
|
||||||
|
|
||||||
@@ -43,57 +43,58 @@ Build the project and flash it to the board, then run monitor tool to view seria
|
|||||||
```
|
```
|
||||||
idf.py -p PORT build flash monitor
|
idf.py -p PORT build flash monitor
|
||||||
```
|
```
|
||||||
If the OPENTHREAD_BR_AUTO_START option is enabled, The device will be connected to the configured Wi-Fi and Thread network automatically then act as the border router.
|
If the `OPENTHREAD_BR_AUTO_START` option is enabled, The device will be connected to the configured Wi-Fi and Thread network automatically then act as the border router.
|
||||||
|
|
||||||
Otherwise, you need to manually configure the Wi-Fi and Thread network with CLI command.
|
Otherwise, you need to manually configure the networks with CLI commands.
|
||||||
|
|
||||||
Command `sta` is used for connecting WiFi.
|
`wifi` command can be used to configure the Wi-Fi network.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
> sta
|
> wifi
|
||||||
---wifi sta parameter---
|
--wifi parameter---
|
||||||
|
connect
|
||||||
-s : wifi ssid
|
-s : wifi ssid
|
||||||
-p : wifi psk
|
-p : wifi psk
|
||||||
---example---
|
---example---
|
||||||
join a wifi,
|
join a wifi:
|
||||||
ssid: threadcertAP
|
ssid: threadcertAP
|
||||||
psk: threadcertAP : sta -s threadcertAP -p threadcertAP
|
psk: threadcertAP : wifi connect -s threadcertAP -p threadcertAP
|
||||||
|
state : get wifi state, disconnect or connect
|
||||||
|
---example---
|
||||||
|
get wifi state : wifi state
|
||||||
Done
|
Done
|
||||||
> sta -s threadcertAP -p threadcertAP
|
|
||||||
ssid: threadcertAP
|
|
||||||
psk: threadcertAP
|
|
||||||
I (47043) wifi:wifi driver task: 3ffd05ac, prio:23, stack:6656, core=0
|
|
||||||
|
|
||||||
|
|
||||||
......
|
|
||||||
|
|
||||||
|
|
||||||
I (49263) wifi:AP's beacon interval = 102400 us, DTIM period = 1
|
|
||||||
I (50233) esp_netif_handlers: sta ip: 192.168.3.10, mask: 255.255.255.0, gw: 192.168.3.1
|
|
||||||
wifi sta is connected successfully
|
|
||||||
Done
|
|
||||||
>
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Command `wifiinfo` is used for checking the state of Wi-Fi connection and printing IP addresses.
|
To join a Wi-Fi network, please use the `wifi connect` command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
> wifiinfo
|
> wifi connect -s threadcertAP -p threadcertAP
|
||||||
---get WiFi informations---
|
ssid: threadcertAP
|
||||||
-i : get sta addr
|
psk: threadcertAP
|
||||||
-s : get wifi state, disconnect or connect
|
I (11331) wifi:wifi driver task: 3ffd06e4, prio:23, stack:6656, core=0
|
||||||
|
I (11331) system_api: Base MAC address is not set
|
||||||
|
I (11331) system_api: read default base MAC address from EFUSE
|
||||||
|
I (11341) wifi:wifi firmware version: 45c46a4
|
||||||
|
I (11341) wifi:wifi certification version: v7.0
|
||||||
|
|
||||||
|
|
||||||
|
..........
|
||||||
|
|
||||||
|
I (13741) esp_netif_handlers: sta ip: 192.168.3.10, mask: 255.255.255.0, gw: 192.168.3.1
|
||||||
|
W (13771) wifi:<ba-add>idx:0 (ifx:0, 02:0f:c1:32:3b:2b), tid:0, ssn:2, winSize:64
|
||||||
|
wifi sta is connected successfully
|
||||||
Done
|
Done
|
||||||
> wifiinfo -s
|
|
||||||
connected
|
|
||||||
Done
|
|
||||||
> wifiinfo -i
|
|
||||||
inet 192.168.3.10
|
|
||||||
inet6 FE80::7AE3:6DFF:FECD:125C
|
|
||||||
Done
|
|
||||||
>
|
|
||||||
```
|
```
|
||||||
|
|
||||||
For forming Thread network, you can refer to [ot_cli_README](../ot_cli/README.md)
|
To get the state of the Wi-Fi network:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
> wifi state
|
||||||
|
connected
|
||||||
|
Done
|
||||||
|
```
|
||||||
|
|
||||||
|
For forming the Thread network, please refer to the [ot_cli_README](../ot_cli/README.md).
|
||||||
|
|
||||||
## Example Output
|
## Example Output
|
||||||
|
|
||||||
@@ -115,7 +116,7 @@ I(8159) OPENTHREAD:[NOTE]-MLE-----: Role Detached -> Leader
|
|||||||
```
|
```
|
||||||
## Using the border agent feature
|
## Using the border agent feature
|
||||||
|
|
||||||
You need to ot-commissioner on the host machine and another Thread end device running OpenThread cli.
|
You need to build ot-commissioner on the host machine and another Thread end device running OpenThread cli.
|
||||||
|
|
||||||
You can find the guide to build and run ot-commissioner [here](https://openthread.io/guides/commissioner/build).
|
You can find the guide to build and run ot-commissioner [here](https://openthread.io/guides/commissioner/build).
|
||||||
|
|
||||||
|
@@ -1,9 +1,2 @@
|
|||||||
if(CONFIG_OPENTHREAD_BR_AUTO_START)
|
idf_component_register(SRCS "esp_ot_br.c"
|
||||||
set(srcs "esp_ot_br.c")
|
|
||||||
else()
|
|
||||||
set(srcs "esp_ot_br.c"
|
|
||||||
"esp_ot_cli_extension.c"
|
|
||||||
"esp_br_wifi_cmd.c")
|
|
||||||
endif()
|
|
||||||
idf_component_register(SRCS "${srcs}"
|
|
||||||
INCLUDE_DIRS ".")
|
INCLUDE_DIRS ".")
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: CC0-1.0
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*
|
*
|
||||||
@@ -52,7 +52,7 @@
|
|||||||
#include "openthread/tasklet.h"
|
#include "openthread/tasklet.h"
|
||||||
#include "openthread/thread.h"
|
#include "openthread/thread.h"
|
||||||
#include "openthread/thread_ftd.h"
|
#include "openthread/thread_ftd.h"
|
||||||
#include "esp_br_wifi_cmd.h"
|
#include "esp_ot_wifi_cmd.h"
|
||||||
#include "esp_ot_cli_extension.h"
|
#include "esp_ot_cli_extension.h"
|
||||||
|
|
||||||
#define TAG "esp_ot_br"
|
#define TAG "esp_ot_br"
|
||||||
|
@@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: CC0-1.0
|
|
||||||
*
|
|
||||||
* OpenThread Command Line Example
|
|
||||||
*
|
|
||||||
* This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, this
|
|
||||||
* software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
||||||
* CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "esp_openthread.h"
|
|
||||||
#include "openthread/cli.h"
|
|
||||||
#include "esp_ot_cli_extension.h"
|
|
||||||
#include "esp_br_wifi_cmd.h"
|
|
||||||
|
|
||||||
static const otCliCommand kCommands[] = {
|
|
||||||
{"sta", esp_ot_process_wifi_sta},
|
|
||||||
{"wifiinfo", esp_ot_process_get_wifi_info}
|
|
||||||
};
|
|
||||||
|
|
||||||
void esp_cli_custom_command_init()
|
|
||||||
{
|
|
||||||
otInstance *instance = esp_openthread_get_instance();
|
|
||||||
otCliSetUserCommands(kCommands, (sizeof(kCommands) / sizeof(kCommands[0])), instance);
|
|
||||||
}
|
|
@@ -2,7 +2,9 @@
|
|||||||
# in this exact order for cmake to work correctly
|
# in this exact order for cmake to work correctly
|
||||||
cmake_minimum_required(VERSION 3.5)
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/iperf)
|
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/iperf
|
||||||
|
$ENV{IDF_PATH}/examples/openthread/extension_command)
|
||||||
|
|
||||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
|
||||||
project(esp_ot_cli)
|
project(esp_ot_cli)
|
||||||
|
@@ -117,113 +117,12 @@ Done
|
|||||||
```
|
```
|
||||||
The second device has joined the Thread network as a router (or a child).
|
The second device has joined the Thread network as a router (or a child).
|
||||||
|
|
||||||
## TCP and UDP Example
|
## Extension commands
|
||||||
|
|
||||||
On the leader device, start a TCP or UDP server:
|
You can refer to the [extension command](../extension_command/README.md) about the extension commands.
|
||||||
```bash
|
|
||||||
> tcpsockserver
|
|
||||||
Done
|
|
||||||
I (1310225) ot_socket: Socket created
|
|
||||||
I (1310225) ot_socket: Socket bound, port 12345
|
|
||||||
I (1310225) ot_socket: Socket listening, timeout is 30 seconds
|
|
||||||
```
|
|
||||||
or (UDP Server)
|
|
||||||
```bash
|
|
||||||
> udpsockserver
|
|
||||||
Done
|
|
||||||
I (1339815) ot_socket: Socket created
|
|
||||||
I (1339815) ot_socket: Socket bound, port 54321
|
|
||||||
I (1339815) ot_socket: Waiting for data, timeout is 30 seconds
|
|
||||||
Done
|
|
||||||
```
|
|
||||||
|
|
||||||
On router device, start a TCP or UDP client (replace with the leader's IPv6 address):
|
The following examples are supported by `ot_cli`:
|
||||||
```bash
|
|
||||||
> tcpsockclient fdde:ad00:beef:0:a7c6:6311:9c8c:271b
|
|
||||||
Done
|
|
||||||
ot_socket: Socket created, connecting to fdde:ad00:beef:0:a7c6:6311:9c8c:271b:12345
|
|
||||||
ot_socket: Successfully connected
|
|
||||||
...
|
|
||||||
```
|
|
||||||
or (UDP Client)
|
|
||||||
```bash
|
|
||||||
> udpsockclient fdde:ad00:beef:0:a7c6:6311:9c8c:271b
|
|
||||||
Done
|
|
||||||
ot_socket: Socket created, sending to fdde:ad00:beef:0:a7c6:6311:9c8c:271b:54321
|
|
||||||
ot_socket: Message sent
|
|
||||||
...
|
|
||||||
```
|
|
||||||
|
|
||||||
### Iperf Example
|
* TCP and UDP Example
|
||||||
|
* Iperf Example
|
||||||
|
|
||||||
Print the iperf help:
|
|
||||||
```bash
|
|
||||||
iperf
|
|
||||||
---iperf parameter---
|
|
||||||
-s : server mode, only receive
|
|
||||||
-u : upd mode
|
|
||||||
-V : use IPV6 address
|
|
||||||
-c <addr> : client mode, only transmit
|
|
||||||
-i <interval> : seconds between periodic bandwidth reports
|
|
||||||
-t <time> : time in seconds to transmit for (default 10 secs)
|
|
||||||
-p <port> : server port to listen on/connect to
|
|
||||||
-l <len_send_buf> : the lenth of send buffer
|
|
||||||
---example---
|
|
||||||
create a tcp server : iperf -s -i 3 -p 5001 -t 60
|
|
||||||
create a udp client : iperf -c <addr> -u -i 3 -t 60 -p 5001 -l 512
|
|
||||||
Done
|
|
||||||
```
|
|
||||||
|
|
||||||
On the leader device, start iperf TCP or UDP server:
|
|
||||||
```bash
|
|
||||||
> iperf -V -s -i 3 -p 5001 -t 20
|
|
||||||
i:3
|
|
||||||
dp:5001
|
|
||||||
sp:5001
|
|
||||||
t:20
|
|
||||||
Done
|
|
||||||
```
|
|
||||||
or (UDP Server)
|
|
||||||
```bash
|
|
||||||
> iperf -V -s -u -i 3 -p 5001 -t 20
|
|
||||||
i:3
|
|
||||||
dp:5001
|
|
||||||
sp:5001
|
|
||||||
t:20
|
|
||||||
Done
|
|
||||||
```
|
|
||||||
|
|
||||||
On the router device, start iperf TCP or UDP client:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
> iperf -V -c fdde:ad00:beef:0:a7c6:6311:9c8c:271b -i 1 -t 5 -p 5001 -l 85
|
|
||||||
ip:fdde:ad00:beef:0:a7c6:6311:9c8c:271b
|
|
||||||
i:1
|
|
||||||
t:5
|
|
||||||
dp:5001
|
|
||||||
sp:5001
|
|
||||||
Done
|
|
||||||
Interval Bandwidth
|
|
||||||
0- 1 sec 0.05 Mbits/sec
|
|
||||||
1- 2 sec 0.05 Mbits/sec
|
|
||||||
2- 3 sec 0.05 Mbits/sec
|
|
||||||
3- 4 sec 0.05 Mbits/sec
|
|
||||||
4- 5 sec 0.05 Mbits/sec
|
|
||||||
0- 5 sec 0.05 Mbits/sec
|
|
||||||
```
|
|
||||||
or (UDP Client)
|
|
||||||
```bash
|
|
||||||
> iperf -V -c fdde:ad00:beef:0:a7c6:6311:9c8c:271b -u -i 1 -t 5 -p 5001 -l 85
|
|
||||||
ip:fdde:ad00:beef:0:a7c6:6311:9c8c:271b
|
|
||||||
i:1
|
|
||||||
t:5
|
|
||||||
dp:5001
|
|
||||||
sp:5001
|
|
||||||
Done
|
|
||||||
0- 1 sec 0.05 Mbits/sec
|
|
||||||
1- 2 sec 0.05 Mbits/sec
|
|
||||||
2- 3 sec 0.05 Mbits/sec
|
|
||||||
3- 4 sec 0.05 Mbits/sec
|
|
||||||
4- 5 sec 0.05 Mbits/sec
|
|
||||||
0- 5 sec 0.05 Mbits/sec
|
|
||||||
```
|
|
||||||
|
@@ -1,8 +1,2 @@
|
|||||||
set(srcs "esp_ot_cli.c")
|
idf_component_register(SRCS "esp_ot_cli.c"
|
||||||
|
|
||||||
if(CONFIG_OPENTHREAD_CLI_ESP_EXTENSION)
|
|
||||||
list(APPEND srcs "esp_ot_cli_extension.c" "esp_ot_tcp_socket.c" "esp_ot_udp_socket.c" "esp_ot_iperf.c")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
idf_component_register(SRCS "${srcs}"
|
|
||||||
INCLUDE_DIRS ".")
|
INCLUDE_DIRS ".")
|
||||||
|
@@ -1,23 +0,0 @@
|
|||||||
menu "OpenThread CLI Example"
|
|
||||||
|
|
||||||
config OPENTHREAD_CLI_ESP_EXTENSION
|
|
||||||
bool "Enable Espressif's extended features"
|
|
||||||
default y
|
|
||||||
help
|
|
||||||
Enable Espressif's extended features include TCP socket, UDP socket.
|
|
||||||
|
|
||||||
config OPENTHREAD_CLI_TCP_SERVER_PORT
|
|
||||||
int "the port of TCP server"
|
|
||||||
default 12345
|
|
||||||
depends on OPENTHREAD_CLI_ESP_EXTENSION
|
|
||||||
help
|
|
||||||
Set the connect port of socket
|
|
||||||
|
|
||||||
config OPENTHREAD_CLI_UDP_SERVER_PORT
|
|
||||||
int "the port of UDP server"
|
|
||||||
default 54321
|
|
||||||
depends on OPENTHREAD_CLI_ESP_EXTENSION
|
|
||||||
help
|
|
||||||
Set the connect port of socket
|
|
||||||
|
|
||||||
endmenu
|
|
@@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: CC0
|
|
||||||
*
|
|
||||||
* OpenThread Command Line Example
|
|
||||||
*
|
|
||||||
* This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, this
|
|
||||||
* software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
||||||
* CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Init the custom command.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void esp_cli_custom_command_init(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
Reference in New Issue
Block a user