2021-10-20 16:48:09 +08:00
|
|
|
/*
|
2025-09-16 19:39:30 +08:00
|
|
|
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
|
2021-10-20 16:48:09 +08:00
|
|
|
*
|
2021-12-21 16:53:20 +08:00
|
|
|
* SPDX-License-Identifier: CC0-1.0
|
2021-10-20 16:48:09 +08:00
|
|
|
*
|
|
|
|
* 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.
|
2021-07-30 15:55:37 +08:00
|
|
|
*/
|
2021-04-02 14:49:49 +08:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
2021-12-21 16:53:20 +08:00
|
|
|
#include <string.h>
|
2021-04-02 14:49:49 +08:00
|
|
|
|
2024-01-29 17:50:48 +08:00
|
|
|
#include "sdkconfig.h"
|
2021-04-02 14:49:49 +08:00
|
|
|
#include "esp_err.h"
|
2021-05-19 11:52:51 +08:00
|
|
|
#include "esp_event.h"
|
2021-04-02 14:49:49 +08:00
|
|
|
#include "esp_log.h"
|
|
|
|
#include "esp_netif.h"
|
2021-06-08 15:49:05 +08:00
|
|
|
#include "esp_netif_types.h"
|
2021-04-02 14:49:49 +08:00
|
|
|
#include "esp_openthread.h"
|
|
|
|
#include "esp_openthread_lock.h"
|
|
|
|
#include "esp_openthread_types.h"
|
2021-07-09 12:18:41 +08:00
|
|
|
#include "esp_ot_config.h"
|
2021-03-22 15:44:58 +08:00
|
|
|
#include "esp_vfs_eventfd.h"
|
2022-12-19 10:50:08 +08:00
|
|
|
#include "nvs_flash.h"
|
2025-09-16 19:39:30 +08:00
|
|
|
#include "ot_examples_common.h"
|
2021-04-02 14:49:49 +08:00
|
|
|
|
2024-01-29 17:50:48 +08:00
|
|
|
#if CONFIG_OPENTHREAD_STATE_INDICATOR_ENABLE
|
|
|
|
#include "ot_led_strip.h"
|
|
|
|
#endif
|
|
|
|
|
2021-07-19 16:37:56 +08:00
|
|
|
#if CONFIG_OPENTHREAD_CLI_ESP_EXTENSION
|
2021-05-25 21:13:41 +08:00
|
|
|
#include "esp_ot_cli_extension.h"
|
2021-07-19 16:37:56 +08:00
|
|
|
#endif // CONFIG_OPENTHREAD_CLI_ESP_EXTENSION
|
2021-05-25 21:13:41 +08:00
|
|
|
|
2021-04-02 14:49:49 +08:00
|
|
|
#define TAG "ot_esp_cli"
|
|
|
|
|
|
|
|
void app_main(void)
|
|
|
|
{
|
2021-06-08 18:12:53 +08:00
|
|
|
// Used eventfds:
|
|
|
|
// * netif
|
2021-07-09 12:18:41 +08:00
|
|
|
// * ot task queue
|
2021-06-08 18:12:53 +08:00
|
|
|
// * radio driver
|
2021-06-08 15:49:05 +08:00
|
|
|
esp_vfs_eventfd_config_t eventfd_config = {
|
2021-07-09 12:18:41 +08:00
|
|
|
.max_fds = 3,
|
2021-06-08 15:49:05 +08:00
|
|
|
};
|
|
|
|
|
2022-12-19 10:50:08 +08:00
|
|
|
ESP_ERROR_CHECK(nvs_flash_init());
|
2021-05-19 11:52:51 +08:00
|
|
|
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
2021-03-22 15:44:58 +08:00
|
|
|
ESP_ERROR_CHECK(esp_netif_init());
|
2021-06-08 15:49:05 +08:00
|
|
|
ESP_ERROR_CHECK(esp_vfs_eventfd_register(&eventfd_config));
|
2025-09-16 19:39:30 +08:00
|
|
|
|
|
|
|
#if CONFIG_OPENTHREAD_CLI
|
|
|
|
ot_console_start();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
esp_openthread_platform_config_t config = {
|
|
|
|
.radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG(),
|
|
|
|
.host_config = ESP_OPENTHREAD_DEFAULT_HOST_CONFIG(),
|
|
|
|
.port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(),
|
|
|
|
};
|
|
|
|
|
|
|
|
ESP_ERROR_CHECK(esp_openthread_start(&config));
|
|
|
|
#if CONFIG_OPENTHREAD_CLI_ESP_EXTENSION
|
|
|
|
esp_cli_custom_command_init();
|
|
|
|
#endif
|
|
|
|
#if CONFIG_OPENTHREAD_NETWORK_AUTO_START
|
|
|
|
ot_network_auto_start();
|
|
|
|
#endif
|
2021-04-02 14:49:49 +08:00
|
|
|
}
|