61 esp_openthread_platform_config_t config = {
64 .radio_mode = RADIO_MODE_NATIVE,
65 .radio_uart_config = {},
76 .storage_partition_name =
"nvs",
77 .netif_queue_size = 10,
78 .task_queue_size = 10,
84 ESP_ERROR_CHECK(esp_openthread_init(&config));
86#if CONFIG_OPENTHREAD_STATE_INDICATOR_ENABLE
87 ESP_ERROR_CHECK(esp_openthread_state_indicator_init(esp_openthread_get_instance()));
90#if CONFIG_OPENTHREAD_LOG_LEVEL_DYNAMIC
92 (void) otLoggingSetLevel(CONFIG_LOG_DEFAULT_LEVEL);
95#if CONFIG_OPENTHREAD_CLI
96 esp_openthread_cli_init();
99 esp_netif_t *openthread_netif;
101 openthread_netif = init_openthread_netif(&config);
102 esp_netif_set_default_netif(openthread_netif);
104#if CONFIG_OPENTHREAD_CLI_ESP_EXTENSION
105 esp_cli_custom_command_init();
109#if CONFIG_OPENTHREAD_CLI
110 esp_openthread_cli_create_task();
112 ESP_LOGI(TAG,
"Activating dataset...");
113 otOperationalDatasetTlvs dataset = {};
115#ifndef USE_OPENTHREAD_FORCE_DATASET
117 otError error = otDatasetGetActiveTlvs(esp_openthread_get_instance(), &dataset);
118 if (error != OT_ERROR_NONE) {
122 ESP_LOGI(TAG,
"Found OpenThread-managed dataset, ignoring esphome configuration");
123 ESP_LOGI(TAG,
"(set force_dataset: true to override)");
127#ifdef USE_OPENTHREAD_TLVS
128 if (dataset.mLength == 0) {
130 size_t len = (
sizeof(USE_OPENTHREAD_TLVS) - 1) / 2;
131 if (
len >
sizeof(dataset.mTlvs)) {
132 ESP_LOGW(TAG,
"TLV buffer too small, truncating");
133 len =
sizeof(dataset.mTlvs);
135 parse_hex(USE_OPENTHREAD_TLVS,
sizeof(USE_OPENTHREAD_TLVS) - 1, dataset.mTlvs,
len);
136 dataset.mLength =
len;
141 ESP_ERROR_CHECK(esp_openthread_auto_start(dataset.mLength > 0 ? &dataset :
nullptr));
143 esp_openthread_launch_mainloop();
146 esp_openthread_deinit();
147 esp_openthread_netif_glue_deinit();
148 esp_netif_destroy(openthread_netif);
150 esp_vfs_eventfd_unregister();
size_t parse_hex(const char *str, size_t length, uint8_t *data, size_t count)
Parse bytes from a hex-encoded string into a byte array.