Skip to content

Commit

Permalink
Merge branch 'feature/adjust_rcp_update_before_wifi_connection' into …
Browse files Browse the repository at this point in the history
…'main'

Feature/adjust rcp update before wifi connection

See merge request espressif/esp-thread-br!108
  • Loading branch information
chshu committed Feb 6, 2024
2 parents ba1114a + dc97cd3 commit c7f0103
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 41 deletions.
130 changes: 102 additions & 28 deletions docs/en/dev-guide/build_and_run.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ For any other customized settings, you can configure the project in menuconfig.

By default, it is configured as Wi-Fi based Thread Border Router.

The Wi-Fi SSID and password must be set in menuconfig. The corresponding options are ``Example Connection Configuration -> WiFi SSID`` and ``Example Connection Configuration -> WiFi Password``.
The auto start mode is disabled by default, if you want the device connects to the configured Wi-Fi and form Thread network automatically, and then act as the border router, you need to enable the menuconfig ``ESP Thread Border Router Example -> Enable the automatic start mode in Thread Border``.

The auto start mode is enabled by default, the device will connect to the configured Wi-Fi and form Thread network automatically, and then act as the border router.
When automatic start mode is enabled, the Thread dataset, Wi-Fi SSID and password must be set in menuconfig. The corresponding options are ``Component config -> OpenThread -> Thread Operational Dataset``, ``Example Connection Configuration -> WiFi SSID`` and ``Example Connection Configuration -> WiFi Password``.

.. note::

Expand Down Expand Up @@ -169,32 +169,7 @@ The default communication interface between host SoC and RCP is UART.

In order to use the SPI interface instead, the ``OPENTHREAD_RCP_SPI`` and ``OPENTHREAD_RADIO_SPINEL_SPI`` options should be enabled in ``ot_rcp`` and ``basic_thread_border_router`` example configurations, respectively. And set corresponding GPIO numbers in `esp_ot_config.h`.

2.1.3.5. Manual Mode
~~~~~~~~~~~~~~~~~~~~

Disable ``OPENTHREAD_BR_AUTO_START`` option if you want to setup the network manually. Then the following CLI commands can be used to connect Wi-Fi and form a Thread network:

.. code-block::
wifi connect -s <ssid> -p <psk>
.. code-block::
dataset init new
.. code-block::
dataset commit active
.. code-block::
ifconfig up
.. code-block::
thread start
2.1.3.6. RF External Coexistence
2.1.3.5. RF External Coexistence
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The SDK incorporates an external coexistence feature that improves transmission performance when there is RF signal interference between Wi-Fi (ESP32-S3) and 802.15.4 (ESP32-H2).
Expand Down Expand Up @@ -268,6 +243,105 @@ Ethernet Border Router:
I(4154) OPENTHREAD:[I] Settings------: ... pid:0x18954426, mlecntr:0x7da7, maccntr:0x7d1c, mliid:2874d9fa90dc8093}
I (4194) OPENTHREAD: OpenThread attached to netif
2.1.4.1. Connect the Wi-Fi and Form the Thread Network
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If enable ``OPENTHREAD_BR_AUTO_START`` option, just skip this step.

If disable ``OPENTHREAD_BR_AUTO_START`` option, you need to setup the network manually. The following CLI commands can be used to connect Wi-Fi and form a Thread network:

.. code-block::
wifi connect -s <ssid> -p <psk>
.. code-block::
dataset init new
.. code-block::
dataset commit active
.. code-block::
ifconfig up
.. code-block::
thread start
The BR device will connect to the Wi-Fi and then form a Thread network.

.. code-block::
> wifi connect -s mywifi -p espressif
ssid: mywifi
psk: espressif
I (5241) pp: pp rom version: e7ae62f
I (5241) net80211: net80211 rom version: e7ae62f
I (5251) wifi:wifi driver task: 3fcbe1a0, prio:23, stack:6144, core=0
I (5251) wifi:wifi firmware version: 0016c4d
I (5251) wifi:wifi certification version: v7.0
I (5251) wifi:config NVS flash: enabled
I (5251) wifi:config nano formating: enabled
I (5251) wifi:Init data frame dynamic rx buffer num: 32
I (5251) wifi:Init static rx mgmt buffer num: 5
I (5251) wifi:Init management short buffer num: 32
I (5251) wifi:Init dynamic tx buffer num: 32
I (5251) wifi:Init static tx FG buffer num: 2
I (5251) wifi:Init static rx buffer size: 1600
I (5251) wifi:Init static rx buffer num: 10
I (5251) wifi:Init dynamic rx buffer num: 32
I (5251) wifi_init: rx ba win: 6
I (5251) wifi_init: tcpip mbox: 32
I (5251) wifi_init: udp mbox: 6
I (5251) wifi_init: tcp mbox: 6
I (5251) wifi_init: tcp tx win: 5760
I (5251) wifi_init: tcp rx win: 5760
I (5251) wifi_init: tcp mss: 1440
I (5251) wifi_init: WiFi IRAM OP enabled
I (5251) wifi_init: WiFi RX IRAM OP enabled
I (5261) wifi:Set ps type: 0, coexist: 0
I (5261) phy_init: phy_version 640,cd64a1a,Jan 24 2024,17:28:12
I (5351) wifi:mode : null
I (5351) wifi:mode : sta (48:27:e2:14:4d:3c)
I (5351) wifi:enable tsf
I (6571) wifi:new:<11,2>, old:<1,1>, ap:<255,255>, sta:<11,2>, prof:1
I (7051) wifi:state: init -> auth (b0)
I (7051) wifi:state: auth -> assoc (0)
I (7071) wifi:state: assoc -> run (10)
I (7351) wifi:connected with mywifi, aid = 2, channel 11, 40D, bssid = 94:d9:b3:1d:d4:37
I (7351) wifi:security: WPA2-PSK, phy: bgn, rssi: -26
I (7351) wifi:pm start, type: 0
I (7361) wifi:dp: 1, bi: 102400, li: 3, scale listen interval from 307200 us to 307200 us
I (7361) wifi:set rx beacon pti, rx_bcn_pti: 0, bcn_timeout: 25000, mt_pti: 0, mt_time: 10000
I (7411) wifi:<ba-add>idx:0 (ifx:0, 94:d9:b3:1d:d4:37), tid:0, ssn:3, winSize:64
I (7441) wifi:AP's beacon interval = 102400 us, DTIM period = 1
I (8361) esp_netif_handlers: sta ip: 192.168.1.100, mask: 255.255.255.0, gw: 192.168.1.1
I (8501) ot_ext_cli: Got IPv6 event: Interface "sta" address: fe80:0000:0000:0000:4a27:e2ff:fe14:4d3c
I(8501) OPENTHREAD:[N] RoutingManager: No valid /48 BR ULA prefix found in settings, generating new one
I(8511) OPENTHREAD:[N] RoutingManager: BR ULA prefix: fd8f:e9a2:bfcc::/48 (generated)
I(8511) OPENTHREAD:[N] RoutingManager: Local on-link prefix: fdde:ad00:beef:cafe::/64
wifi sta is connected successfully
Done
> dataset init new
Done
> dataset commit active
Done I (12401) OPENTHREAD: NAT64 ready
> ifconfig up
I (15451) OPENTHREAD: Platform UDP bound to port 49153
Done
I (15451) OT_STATE: netif up
> thread start
I(18201) OPENTHREAD:[N] Mle-----------: Role disabled -> detached
Done
> I(18521) OPENTHREAD:[N] Mle-----------: Attach attempt 1, AnyPartition reattaching with Active Dataset
I(25141) OPENTHREAD:[N] RouterTable---: Allocate router id 11
I(25141) OPENTHREAD:[N] Mle-----------: RLOC16 fffe -> 6c00
I(25151) OPENTHREAD:[N] Mle-----------: Role detached -> leader
I(25151) OPENTHREAD:[N] Mle-----------: Partition ID 0x82de096
I (25161) OPENTHREAD: Platform UDP bound to port 49154
2.1.5. Build and Run the Thread CLI Device
------------------------------------------
Expand Down
15 changes: 3 additions & 12 deletions examples/basic_thread_border_router/main/esp_ot_br.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
#include "esp_ot_wifi_cmd.h"
#include "esp_spiffs.h"
#include "esp_vfs_eventfd.h"
#include "esp_wifi.h"
#include "mdns.h"
#include "nvs_flash.h"
#include "protocol_examples_common.h"
#include "driver/uart.h"
#include "freertos/FreeRTOS.h"

Expand Down Expand Up @@ -86,19 +84,12 @@ void app_main(void)
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());

#if CONFIG_EXAMPLE_CONNECT_WIFI
#if CONFIG_OPENTHREAD_BR_AUTO_START
ESP_ERROR_CHECK(example_connect());
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE));
esp_openthread_set_backbone_netif(get_example_netif());
#else
#if CONFIG_EXAMPLE_CONNECT_WIFI && !CONFIG_OPENTHREAD_BR_AUTO_START
esp_ot_wifi_netif_init();
esp_openthread_set_backbone_netif(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"));
#endif // CONFIG_OPENTHREAD_BR_AUTO_START
#elif CONFIG_EXAMPLE_CONNECT_ETHERNET
ESP_ERROR_CHECK(example_connect());
esp_openthread_set_backbone_netif(get_example_netif());
#else

#if !CONFIG_EXAMPLE_CONNECT_WIFI && !CONFIG_EXAMPLE_CONNECT_ETHERNET
#error No backbone netif!
#endif // CONFIG_EXAMPLE_CONNECT_WIFI

Expand Down
2 changes: 1 addition & 1 deletion examples/common/thread_border_router/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(requires esp_ot_cli_extension openthread vfs)
set(requires esp_ot_cli_extension openthread protocol_examples_common vfs esp_wifi)

if(CONFIG_OPENTHREAD_CLI_OTA)
list(APPEND requires esp_http_client esp_br_http_ota)
Expand Down
12 changes: 12 additions & 0 deletions examples/common/thread_border_router/src/border_router_launch.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
#include "openthread/tasklet.h"
#include "openthread/thread_ftd.h"

#if CONFIG_OPENTHREAD_BR_AUTO_START
#include "esp_wifi.h"
#include "protocol_examples_common.h"
#endif

#define TAG "esp_ot_br"
#define RCP_VERSION_MAX_SIZE 100

Expand Down Expand Up @@ -111,6 +116,13 @@ static void ot_task_worker(void *ctx)
ESP_ERROR_CHECK(esp_netif_set_default_netif(openthread_netif));
esp_cli_custom_command_init();
#if CONFIG_OPENTHREAD_BR_AUTO_START
esp_openthread_lock_release();
ESP_ERROR_CHECK(example_connect());
#if CONFIG_EXAMPLE_CONNECT_WIFI
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE));
#endif
esp_openthread_lock_acquire(portMAX_DELAY);
esp_openthread_set_backbone_netif(get_example_netif());
ESP_ERROR_CHECK(esp_openthread_border_router_init());
otOperationalDatasetTlvs dataset;
otError error = otDatasetGetActiveTlvs(esp_openthread_get_instance(), &dataset);
Expand Down

0 comments on commit c7f0103

Please sign in to comment.