diff --git a/examples/openthread/ot_br/main/esp_ot_br.c b/examples/openthread/ot_br/main/esp_ot_br.c index bf887803a9..206f0de977 100644 --- a/examples/openthread/ot_br/main/esp_ot_br.c +++ b/examples/openthread/ot_br/main/esp_ot_br.c @@ -48,6 +48,16 @@ #include "ot_led_strip.h" #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" #if CONFIG_EXTERNAL_COEX_ENABLE @@ -93,47 +103,62 @@ static void ot_task_worker(void *aContext) 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 - ESP_ERROR_CHECK(example_connect()); - ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_MAX_MODEM)); -#if CONFIG_ESP_COEX_SW_COEXIST_ENABLE && CONFIG_OPENTHREAD_RADIO_NATIVE - ESP_ERROR_CHECK(esp_coex_wifi_i154_enable()); +#if CONFIG_EXAMPLE_CONNECT_WIFI || CONFIG_EXAMPLE_CONNECT_ETHERNET + bool wifi_or_ethernet_connected = false; #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 ot_br_external_coexist_init(); #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_hostname_set("esp-ot-br")); - // Initialize border routing features esp_openthread_lock_acquire(portMAX_DELAY); #if CONFIG_OPENTHREAD_STATE_INDICATOR_ENABLE ESP_ERROR_CHECK(esp_openthread_state_indicator_init(esp_openthread_get_instance())); #endif - #if CONFIG_OPENTHREAD_BR_AUTO_START - ESP_ERROR_CHECK(esp_openthread_border_router_init()); - otOperationalDatasetTlvs dataset; - otError error = otDatasetGetActiveTlvs(esp_openthread_get_instance(), &dataset); - ESP_ERROR_CHECK(esp_openthread_auto_start((error == OT_ERROR_NONE) ? &dataset : NULL)); + if (wifi_or_ethernet_connected) { + esp_openthread_set_backbone_netif(get_example_netif()); + ESP_ERROR_CHECK(esp_openthread_border_router_init()); +#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 - esp_openthread_lock_release(); vTaskDelete(NULL); } diff --git a/examples/openthread/ot_br/main/idf_component.yml b/examples/openthread/ot_br/main/idf_component.yml index b6a0a80c2f..bf43f391cb 100644 --- a/examples/openthread/ot_br/main/idf_component.yml +++ b/examples/openthread/ot_br/main/idf_component.yml @@ -1,10 +1,12 @@ ## IDF Component Manager Manifest File dependencies: espressif/esp_ot_cli_extension: - version: "~1.1.0" + version: "~1.2.0" espressif/mdns: "^1.0.3" ## Required IDF version idf: version: ">=5.0" + protocol_examples_common: + path: ${IDF_PATH}/examples/common_components/protocol_examples_common ot_led: path: ${IDF_PATH}/examples/openthread/ot_common_components/ot_led diff --git a/examples/openthread/ot_cli/main/idf_component.yml b/examples/openthread/ot_cli/main/idf_component.yml index 3f1f6778d2..06b75f0c81 100644 --- a/examples/openthread/ot_cli/main/idf_component.yml +++ b/examples/openthread/ot_cli/main/idf_component.yml @@ -1,7 +1,7 @@ ## IDF Component Manager Manifest File dependencies: espressif/esp_ot_cli_extension: - version: "~1.1.0" + version: "~1.2.0" idf: version: ">=4.1.0" ot_led: