mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-04 13:14:32 +02:00
openthread: ot extension command refactor
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
|
191
examples/openthread/extension_command/README.md
Normal file
191
examples/openthread/extension_command/README.md
Normal file
@@ -0,0 +1,191 @@
|
||||
# Openthread Extension Command
|
||||
|
||||
The Openthread Extension Command is a series of command lines extended from [OpenThread CLI](https://github.com/openthread/openthread/blob/main/src/cli/README.md).
|
||||
Openthread Extension Command doesn't run alone, it needs to be used in conjunction with these examples:
|
||||
* [ot_cli](../ot_cli)
|
||||
* [ot_br](../ot_br)
|
||||
|
||||
## How to use the example
|
||||
|
||||
Run the configuration command `idf.py menuconfig` to enable the operations you need for your example: `OpenThread Extension CLI` -> `Enable Espressif's extended features`.
|
||||
|
||||
## OT Extension Command Line List
|
||||
|
||||
* [iperf](#iperf)
|
||||
* [tcpsockclient](#tcpsockclient)
|
||||
* [tcpsockserver](#tcpsockserver)
|
||||
* [udpsockclient](#udpsockclient)
|
||||
* [udpsockserver](#udpsockserver)
|
||||
* [wifi](#wifi)
|
||||
|
||||
### iperf
|
||||
|
||||
Iperf is a tool for active measurements of the maximum achievable bandwidth on Thread network, which is based TCP and UDP.
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
Create an iperf TCP service for 20 seconds, with printing logs for each 3 seconds, at the port 5001:
|
||||
```bash
|
||||
> iperf -V -s -t 20 -i 3 -p 5001
|
||||
Done
|
||||
```
|
||||
|
||||
For UDP service:
|
||||
```bash
|
||||
> iperf -V -u -s -t 20 -i 3 -p 5001
|
||||
Done
|
||||
```
|
||||
|
||||
|
||||
Create an iperf TCP client connecting to `fdde:ad00:beef:0:a7c6:6311:9c8c:271b`(the iperf server address) for 30 seconds, with printing logs for each second, at the port 5001, with 85 length of each packets:
|
||||
```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 UDP client:
|
||||
```bash
|
||||
> iperf -V -u -c fdde:ad00:beef:0:a7c6:6311:9c8c:271b -t 20 -i 1 -p 5001 -l 85
|
||||
Done
|
||||
```
|
||||
|
||||
### 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
|
||||
...
|
||||
```
|
||||
|
||||
### 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
|
||||
```
|
||||
|
||||
### udpsockclient
|
||||
|
||||
Used for creating a udp client.
|
||||
|
||||
```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
|
||||
...
|
||||
```
|
||||
|
||||
### 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
|
||||
```
|
||||
|
||||
### wifi
|
||||
|
||||
Get help for wifi command:
|
||||
|
||||
```bash
|
||||
> wifi
|
||||
---wifi parameter---
|
||||
connect
|
||||
-s : wifi ssid
|
||||
-p : wifi psk
|
||||
---example---
|
||||
join a wifi:
|
||||
ssid: threadcertAP
|
||||
psk: threadcertAP : wifi connect -s threadcertAP -p threadcertAP
|
||||
state : get wifi state, disconnect or connect
|
||||
---example---
|
||||
get wifi state : wifi state
|
||||
Done
|
||||
```
|
||||
|
||||
Join a wifi with ssid: threadcertAP and psk: threadcertAP:
|
||||
|
||||
```bash
|
||||
> wifi connect -s threadcertAP -p threadcertAP
|
||||
ssid: threadcertAP
|
||||
psk: threadcertAP
|
||||
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
|
||||
```
|
||||
|
||||
Get the state of the WiFi:
|
||||
|
||||
```bash
|
||||
> wifi state
|
||||
connected
|
||||
Done
|
||||
```
|
||||
|
||||
## Extension command example
|
||||
|
||||
### TCP and UDP Example
|
||||
|
||||
Before running this example, a thread network with a Leader and a router( or child) needs to be set up.
|
||||
|
||||
On the leader device, start a TCP or UDP server, on router device, start a TCP or UDP client.
|
||||
|
||||
(note: replace the parameter of the `tcpsockclient` or `udpsockclient` with the leader's IPv6 address)
|
||||
|
||||
### Iperf Example
|
||||
|
||||
Example for using iperf:
|
||||
|
||||
Before running iperf, a thread network with a Leader and a router( or child) needs to be set up.
|
||||
|
||||
On the leader device, start iperf TCP or UDP server, on the router device, start iperf TCP or UDP client.
|
||||
|
@@ -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
|
||||
*
|
@@ -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
|
||||
*
|
@@ -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
|
||||
*
|
@@ -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
|
||||
*
|
||||
@@ -20,16 +20,10 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief User command "sta" process.
|
||||
* @brief User command "wifi" process.
|
||||
*
|
||||
*/
|
||||
void esp_ot_process_wifi_sta(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[]);
|
||||
void esp_ot_process_wifi_cmd(void *aContext, uint8_t aArgsLength, char *aArgs[]);
|
||||
|
||||
/**
|
||||
* @brief Wifi netif init.
|
@@ -17,18 +17,28 @@
|
||||
#include "esp_ot_iperf.h"
|
||||
#include "esp_ot_tcp_socket.h"
|
||||
#include "esp_ot_udp_socket.h"
|
||||
#include "esp_ot_wifi_cmd.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/portmacro.h"
|
||||
#include "freertos/task.h"
|
||||
#include "openthread/cli.h"
|
||||
|
||||
static const otCliCommand kCommands[] = {
|
||||
#if CONFIG_OPENTHREAD_CLI_TCP_SOCKET
|
||||
{"tcpsockserver", esp_ot_process_tcp_server},
|
||||
{"tcpsockclient", esp_ot_process_tcp_client},
|
||||
#endif // CONFIG_OPENTHREAD_CLI_TCP_SOCKET
|
||||
#if CONFIG_OPENTHREAD_CLI_UDP_SOCKET
|
||||
{"udpsockserver", esp_ot_process_udp_server},
|
||||
{"udpsockclient", esp_ot_process_udp_client},
|
||||
{"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()
|
@@ -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
|
||||
*
|
@@ -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
|
||||
*
|
@@ -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
|
||||
*
|
||||
@@ -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 psk[100] = "";
|
||||
(void)(aContext);
|
||||
if (aArgsLength == 0) {
|
||||
otCliOutputFormat("---wifi sta parameter---\n");
|
||||
otCliOutputFormat("---wifi parameter---\n");
|
||||
otCliOutputFormat("connect\n");
|
||||
otCliOutputFormat("-s : wifi ssid\n");
|
||||
otCliOutputFormat("-p : wifi psk\n");
|
||||
otCliOutputFormat("---example---\n");
|
||||
otCliOutputFormat("join a wifi:\nssid: threadcertAP \npsk: threadcertAP : sta -s threadcertAP -p threadcertAP\n");
|
||||
} else {
|
||||
for (int i = 0; i < aArgsLength; i++) {
|
||||
otCliOutputFormat("join a wifi:\nssid: threadcertAP \npsk: threadcertAP : wifi connect -s threadcertAP -p threadcertAP\n");
|
||||
otCliOutputFormat("state : get wifi state, disconnect or connect\n");
|
||||
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) {
|
||||
i++;
|
||||
strcpy(ssid, aArgs[i]);
|
||||
@@ -135,39 +139,13 @@ void esp_ot_process_wifi_sta(void *aContext, uint8_t aArgsLength, char *aArgs[])
|
||||
} else {
|
||||
otCliOutputFormat("wifi has already connected\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
otCliOutputFormat("connected\n");
|
||||
} else {
|
||||
otCliOutputFormat("disconnected\n");
|
||||
}
|
||||
}
|
||||
} else if (strcmp(aArgs[0], "state") == 0) {
|
||||
if (s_wifi_connected) {
|
||||
otCliOutputFormat("connected\n");
|
||||
} else {
|
||||
otCliOutputFormat("disconnected\n");
|
||||
}
|
||||
} else {
|
||||
otCliOutputFormat("invalid commands\n");
|
||||
}
|
||||
}
|
@@ -4,7 +4,9 @@ cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
# (Not part of the boilerplate)
|
||||
# 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)
|
||||
project(esp_ot_br)
|
||||
|
@@ -47,53 +47,8 @@ If the OPENTHREAD_BR_AUTO_START option is enabled, The device will be connected
|
||||
|
||||
Otherwise, you need to manually configure the Wi-Fi and Thread network with CLI command.
|
||||
|
||||
Command `sta` is used for connecting WiFi.
|
||||
|
||||
```bash
|
||||
> sta
|
||||
---wifi sta parameter---
|
||||
-s : wifi ssid
|
||||
-p : wifi psk
|
||||
---example---
|
||||
join a wifi,
|
||||
ssid: threadcertAP
|
||||
psk: threadcertAP : sta -s threadcertAP -p threadcertAP
|
||||
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.
|
||||
|
||||
```bash
|
||||
> wifiinfo
|
||||
---get WiFi informations---
|
||||
-i : get sta addr
|
||||
-s : get wifi state, disconnect or connect
|
||||
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)
|
||||
For connecting to Wi-Fi, you can refer to [extension_command](../extension_command/README.md) about `wifi` command.
|
||||
For forming Thread network, you can refer to [ot_cli_README](../ot_cli/README.md).
|
||||
|
||||
## Example Output
|
||||
|
||||
|
@@ -1,9 +1,2 @@
|
||||
if(CONFIG_OPENTHREAD_BR_AUTO_START)
|
||||
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 ".")
|
||||
idf_component_register(SRCS "esp_ot_br.c"
|
||||
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
|
||||
*
|
||||
@@ -52,7 +52,7 @@
|
||||
#include "openthread/tasklet.h"
|
||||
#include "openthread/thread.h"
|
||||
#include "openthread/thread_ftd.h"
|
||||
#include "esp_br_wifi_cmd.h"
|
||||
#include "esp_ot_wifi_cmd.h"
|
||||
#include "esp_ot_cli_extension.h"
|
||||
|
||||
#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
|
||||
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)
|
||||
|
||||
project(esp_ot_cli)
|
||||
|
@@ -117,113 +117,12 @@ Done
|
||||
```
|
||||
The second device has joined the Thread network as a router (or a child).
|
||||
|
||||
## TCP and UDP Example
|
||||
## Extension command example
|
||||
|
||||
On the leader device, start a TCP or UDP 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
|
||||
```
|
||||
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
|
||||
```
|
||||
You can refer to [extension command](../extension_command/README.md) for how to use the extension commands.
|
||||
|
||||
On router device, start a TCP or UDP client (replace with the leader's IPv6 address):
|
||||
```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
|
||||
...
|
||||
```
|
||||
these examples are supported by ot_cli:
|
||||
|
||||
### 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")
|
||||
|
||||
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}"
|
||||
idf_component_register(SRCS "esp_ot_cli.c"
|
||||
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