Merge branch 'feat/update_component_for_ot_examples' into 'master'

feat(openthread): update extension commands component for examples

See merge request espressif/esp-idf!33243
This commit is contained in:
Shu Chen 2024-09-04 17:59:54 +08:00
commit f1008faa1a
3 changed files with 53 additions and 28 deletions

View File

@ -48,6 +48,16 @@
#include "ot_led_strip.h" #include "ot_led_strip.h"
#endif #endif
#if CONFIG_OPENTHREAD_BR_AUTO_START
#include "example_common_private.h"
#include "protocol_examples_common.h"
#endif
#if !CONFIG_OPENTHREAD_BR_AUTO_START && CONFIG_EXAMPLE_CONNECT_ETHERNET
// TZ-1109: Add a menchanism for connecting ETH manually.
#error Currently we do not support a manual way to connect ETH, if you want to use ETH, please enable OPENTHREAD_BR_AUTO_START.
#endif
#define TAG "esp_ot_br" #define TAG "esp_ot_br"
#if CONFIG_EXTERNAL_COEX_ENABLE #if CONFIG_EXTERNAL_COEX_ENABLE
@ -93,47 +103,62 @@ static void ot_task_worker(void *aContext)
void ot_br_init(void *ctx) void ot_br_init(void *ctx)
{ {
#if CONFIG_EXAMPLE_CONNECT_WIFI #if CONFIG_OPENTHREAD_CLI_WIFI
ESP_ERROR_CHECK(esp_ot_wifi_config_init());
#endif
#if CONFIG_OPENTHREAD_BR_AUTO_START #if CONFIG_OPENTHREAD_BR_AUTO_START
ESP_ERROR_CHECK(example_connect()); #if CONFIG_EXAMPLE_CONNECT_WIFI || CONFIG_EXAMPLE_CONNECT_ETHERNET
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_MAX_MODEM)); bool wifi_or_ethernet_connected = false;
#if CONFIG_ESP_COEX_SW_COEXIST_ENABLE && CONFIG_OPENTHREAD_RADIO_NATIVE
ESP_ERROR_CHECK(esp_coex_wifi_i154_enable());
#else #else
#error No backbone netif!
#endif
#if CONFIG_EXAMPLE_CONNECT_WIFI
char wifi_ssid[32] = "";
char wifi_password[64] = "";
if (esp_ot_wifi_config_get_ssid(wifi_ssid) == ESP_OK) {
ESP_LOGI(TAG, "use the Wi-Fi config from NVS");
esp_ot_wifi_config_get_password(wifi_password);
} else {
ESP_LOGI(TAG, "use the Wi-Fi config from Kconfig");
strcpy(wifi_ssid, CONFIG_EXAMPLE_WIFI_SSID);
strcpy(wifi_password, CONFIG_EXAMPLE_WIFI_PASSWORD);
}
if (esp_ot_wifi_connect(wifi_ssid, wifi_password) == ESP_OK) {
wifi_or_ethernet_connected = true;
} else {
ESP_LOGE(TAG, "Fail to connect to Wi-Fi, please try again manually");
}
#endif
#if CONFIG_EXAMPLE_CONNECT_ETHERNET
ESP_ERROR_CHECK(example_ethernet_connect());
wifi_or_ethernet_connected = true;
#endif
#endif // CONFIG_OPENTHREAD_BR_AUTO_START
#if CONFIG_EXTERNAL_COEX_ENABLE #if CONFIG_EXTERNAL_COEX_ENABLE
ot_br_external_coexist_init(); ot_br_external_coexist_init();
#endif // CONFIG_EXTERNAL_COEX_ENABLE #endif // CONFIG_EXTERNAL_COEX_ENABLE
#endif
esp_openthread_set_backbone_netif(get_example_netif());
#else
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
ESP_LOGE(TAG, "ESP-Openthread has not set backbone netif");
#endif // CONFIG_EXAMPLE_CONNECT_WIFI
ESP_ERROR_CHECK(mdns_init()); ESP_ERROR_CHECK(mdns_init());
ESP_ERROR_CHECK(mdns_hostname_set("esp-ot-br")); ESP_ERROR_CHECK(mdns_hostname_set("esp-ot-br"));
// Initialize border routing features
esp_openthread_lock_acquire(portMAX_DELAY); esp_openthread_lock_acquire(portMAX_DELAY);
#if CONFIG_OPENTHREAD_STATE_INDICATOR_ENABLE #if CONFIG_OPENTHREAD_STATE_INDICATOR_ENABLE
ESP_ERROR_CHECK(esp_openthread_state_indicator_init(esp_openthread_get_instance())); ESP_ERROR_CHECK(esp_openthread_state_indicator_init(esp_openthread_get_instance()));
#endif #endif
#if CONFIG_OPENTHREAD_BR_AUTO_START #if CONFIG_OPENTHREAD_BR_AUTO_START
ESP_ERROR_CHECK(esp_openthread_border_router_init()); if (wifi_or_ethernet_connected) {
otOperationalDatasetTlvs dataset; esp_openthread_set_backbone_netif(get_example_netif());
otError error = otDatasetGetActiveTlvs(esp_openthread_get_instance(), &dataset); ESP_ERROR_CHECK(esp_openthread_border_router_init());
ESP_ERROR_CHECK(esp_openthread_auto_start((error == OT_ERROR_NONE) ? &dataset : NULL)); #if CONFIG_EXAMPLE_CONNECT_WIFI
esp_ot_wifi_border_router_init_flag_set(true);
#endif
otOperationalDatasetTlvs dataset;
otError error = otDatasetGetActiveTlvs(esp_openthread_get_instance(), &dataset);
ESP_ERROR_CHECK(esp_openthread_auto_start((error == OT_ERROR_NONE) ? &dataset : NULL));
} else {
ESP_LOGE(TAG, "Auto-start mode failed, please try to start manually");
}
#endif // CONFIG_OPENTHREAD_BR_AUTO_START #endif // CONFIG_OPENTHREAD_BR_AUTO_START
esp_openthread_lock_release(); esp_openthread_lock_release();
vTaskDelete(NULL); vTaskDelete(NULL);
} }

View File

@ -1,7 +1,7 @@
## IDF Component Manager Manifest File ## IDF Component Manager Manifest File
dependencies: dependencies:
espressif/esp_ot_cli_extension: espressif/esp_ot_cli_extension:
version: "~1.1.0" version: "~1.2.0"
espressif/mdns: "^1.0.3" espressif/mdns: "^1.0.3"
## Required IDF version ## Required IDF version
idf: idf:

View File

@ -1,7 +1,7 @@
## IDF Component Manager Manifest File ## IDF Component Manager Manifest File
dependencies: dependencies:
espressif/esp_ot_cli_extension: espressif/esp_ot_cli_extension:
version: "~1.1.0" version: "~1.2.0"
idf: idf:
version: ">=4.1.0" version: ">=4.1.0"
ot_led: ot_led: