diff --git a/examples/all_device_types_app/CMakeLists.txt b/examples/all_device_types_app/CMakeLists.txt index 755d89d58..f94dcfbc6 100644 --- a/examples/all_device_types_app/CMakeLists.txt +++ b/examples/all_device_types_app/CMakeLists.txt @@ -17,6 +17,8 @@ if(NOT DEFINED ENV{ESP_MATTER_DEVICE_PATH}) set(ENV{ESP_MATTER_DEVICE_PATH} $ENV{ESP_MATTER_PATH}/device_hal/device/esp32c2_devkit_m) elseif("${IDF_TARGET}" STREQUAL "esp32c6") set(ENV{ESP_MATTER_DEVICE_PATH} $ENV{ESP_MATTER_PATH}/device_hal/device/esp32c6_devkit_c) + elseif("${IDF_TARGET}" STREQUAL "esp32s3") + set(ENV{ESP_MATTER_DEVICE_PATH} $ENV{ESP_MATTER_PATH}/device_hal/device/esp32s3_devkit_c) else() message(FATAL_ERROR "Unsupported IDF_TARGET") endif() diff --git a/examples/all_device_types_app/README.md b/examples/all_device_types_app/README.md index aefc71348..38d003871 100644 --- a/examples/all_device_types_app/README.md +++ b/examples/all_device_types_app/README.md @@ -21,6 +21,32 @@ On boot-up esp-idf console starts. In order to create a device user have to use - To delete existing device perform `matter device factoryreset`. - To add new device, say fan or any other device type use `create --device_type=fan`. +Setup OTBR for a device + +- Please use the [OTBR board](https://github.com/espressif/esp-thread-br#hardware-platforms) as the harware platform running this example. +- The sdkconfig file `sdkconfig.defaults.otbr` is provided to enable the OTBR feature on the device. Build and flash the example with the sdkconfig file 'sdkconfig.defaults.otbr' +``` +idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults.otbr" set-target esp32s3 build +idf.py -p erase-flash flash monitor + +``` +- After pairing the device via ble-wifi method with chip-tool command, you can initialize a new Thread network dataset and commit it as the active one, user should use console command to do the below operation. +``` +matter esp ot_cli dataset init new +matter esp ot_cli dataset commit active +matter esp ot_cli ifconfig up +matter esp ot_cli thread start +``` +- Get the operational dataset TLV-encoded string command +``` +matter esp ot_cli dataset active -x + +Done +0e080000000000010000000300000d35060004001fffe00208c62a4c5f80346de00708fd9ae261c39015460510874e399792fcb276c571dee6f71c260a030f4f70656e5468726561642d3861363301028a630410a6676a0f60ca6dd3af116bdefd2a21270c0402a0f7f8 +Done + +``` + You can simulate changing an attribute value locally using the command - Command to set attribute value: `matter esp attribute set ` diff --git a/examples/all_device_types_app/main/CMakeLists.txt b/examples/all_device_types_app/main/CMakeLists.txt index 1fa311502..5a22601ec 100644 --- a/examples/all_device_types_app/main/CMakeLists.txt +++ b/examples/all_device_types_app/main/CMakeLists.txt @@ -1,8 +1,10 @@ -set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console app_reset console fatfs hal) - +set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console esp_matter_thread_br app_reset console fatfs hal) +set(ldfragments linker.lf) idf_component_register(SRC_DIRS "." PRIV_INCLUDE_DIRS "." "${ESP_MATTER_PATH}/examples/common/utils" - PRIV_REQUIRES ${PRIV_REQUIRES_LIST}) + PRIV_REQUIRES ${PRIV_REQUIRES_LIST} + LDFRAGMENTS "${ldfragments}" +) set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17) target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H") diff --git a/examples/all_device_types_app/main/app_main.cpp b/examples/all_device_types_app/main/app_main.cpp index e1f0903c8..208d34e40 100644 --- a/examples/all_device_types_app/main/app_main.cpp +++ b/examples/all_device_types_app/main/app_main.cpp @@ -27,6 +27,11 @@ #if CHIP_DEVICE_CONFIG_ENABLE_THREAD #include #endif +#if CONFIG_OPENTHREAD_BORDER_ROUTER +#include +#include +#endif // CONFIG_OPENTHREAD_BORDER_ROUTER + static const char *TAG = "app_main"; @@ -108,6 +113,20 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg) ESP_LOGI(TAG, "Fabric is committed"); break; + case chip::DeviceLayer::DeviceEventType::kESPSystemEvent: + if (event->Platform.ESPSystemEvent.Base == IP_EVENT && + event->Platform.ESPSystemEvent.Id == IP_EVENT_STA_GOT_IP) { +#if CONFIG_OPENTHREAD_BORDER_ROUTER + 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_LOGI(TAG, "init thread br"); + esp_matter::thread_br_init(&config); +#endif + } + break; default: break; @@ -145,7 +164,7 @@ extern "C" void app_main() // node handle can be used to add/modify other endpoints. node_t *node = node::create(&node_config, app_attribute_update_cb, app_identification_cb); ABORT_APP_ON_FAILURE(node != nullptr, ESP_LOGE(TAG, "Failed to create Matter node")); - + uint8_t device_type_index; if(esp_matter::nvs_helpers::get_device_type_from_nvs(&device_type_index) != ESP_OK) { semaphoreHandle = xSemaphoreCreateBinary(); @@ -181,5 +200,9 @@ extern "C" void app_main() esp_matter::console::diagnostics_register_commands(); esp_matter::console::wifi_register_commands(); esp_matter::console::init(); +#if CONFIG_OPENTHREAD_BORDER_ROUTER && CONFIG_OPENTHREAD_CLI + esp_matter::console::thread_br_cli_register_command(); +#endif // CONFIG_OPENTHREAD_BORDER_ROUTER && CONFIG_OPENTHREAD_CLI + #endif } diff --git a/examples/all_device_types_app/main/app_priv.h b/examples/all_device_types_app/main/app_priv.h index 075f606e5..ce931e7f2 100644 --- a/examples/all_device_types_app/main/app_priv.h +++ b/examples/all_device_types_app/main/app_priv.h @@ -7,6 +7,7 @@ */ #pragma once +#include "sdkconfig.h" #if CHIP_DEVICE_CONFIG_ENABLE_THREAD #include "esp_openthread_types.h" @@ -24,6 +25,74 @@ #define ESP_OPENTHREAD_DEFAULT_PORT_CONFIG() \ { \ - .storage_partition_name = "ot_storage", .netif_queue_size = 10, .task_queue_size = 10, \ + .storage_partition_name = "nvs", .netif_queue_size = 10, .task_queue_size = 10, \ } #endif + +#if CONFIG_OPENTHREAD_BORDER_ROUTER +#include "esp_openthread_types.h" + +#if CONFIG_OPENTHREAD_RADIO_NATIVE +#define ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG() \ + { \ + .radio_mode = RADIO_MODE_NATIVE, \ + } +#elif CONFIG_OPENTHREAD_RADIO_SPINEL_UART +#define ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG() \ + { \ + .radio_mode = RADIO_MODE_UART_RCP, \ + .radio_uart_config = { \ + .port = UART_NUM_1, \ + .uart_config = \ + { \ + .baud_rate = 460800, \ + .data_bits = UART_DATA_8_BITS, \ + .parity = UART_PARITY_DISABLE, \ + .stop_bits = UART_STOP_BITS_1, \ + .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, \ + .rx_flow_ctrl_thresh = 0, \ + .source_clk = UART_SCLK_DEFAULT, \ + }, \ + .rx_pin = GPIO_NUM_17, \ + .tx_pin = GPIO_NUM_18, \ + }, \ + } +#else +#define ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG() \ + { \ + .radio_mode = RADIO_MODE_SPI_RCP, \ + .radio_spi_config = { \ + .host_device = SPI2_HOST, \ + .dma_channel = 2, \ + .spi_interface = \ + { \ + .mosi_io_num = 11, \ + .sclk_io_num = 12, \ + .miso_io_num = 13, \ + }, \ + .spi_device = \ + { \ + .cs_ena_pretrans = 2, \ + .input_delay_ns = 100, \ + .mode = 0, \ + .clock_speed_hz = 2500 * 1000, \ + .spics_io_num = 10, \ + .queue_size = 5, \ + }, \ + .intr_pin = 8, \ + }, \ + } +#endif // CONFIG_OPENTHREAD_RADIO_SPINEL_UART OR CONFIG_OPENTHREAD_RADIO_SPINEL_SPI + +#define HOST_BAUD_RATE 115200 + +#define ESP_OPENTHREAD_DEFAULT_HOST_CONFIG() \ + { \ + .host_connection_mode = HOST_CONNECTION_MODE_NONE, \ + } + +#define ESP_OPENTHREAD_DEFAULT_PORT_CONFIG() \ + { \ + .storage_partition_name = "nvs", .netif_queue_size = 10, .task_queue_size = 10, \ + } +#endif // CONFIG_OPENTHREAD_BORDER_ROUTER diff --git a/examples/all_device_types_app/main/linker.lf b/examples/all_device_types_app/main/linker.lf new file mode 100644 index 000000000..bdf426b5f --- /dev/null +++ b/examples/all_device_types_app/main/linker.lf @@ -0,0 +1,16 @@ +[mapping:CHIP] +archive: libCHIP.a +entries: + if ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY = y: + * (extram_bss) + else: + * (default) + +[mapping:esp_matter] +archive: libesp_matter.a +entries: + if ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY = y: + * (extram_bss) + else: + * (default) + diff --git a/examples/all_device_types_app/sdkconfig.defaults.esp32s3 b/examples/all_device_types_app/sdkconfig.defaults.esp32s3 new file mode 100644 index 000000000..bac5e61b0 --- /dev/null +++ b/examples/all_device_types_app/sdkconfig.defaults.esp32s3 @@ -0,0 +1,5 @@ +CONFIG_IDF_TARGET="esp32s3" + +# use for otbr option +CONFIG_LWIP_IPV6_NUM_ADDRESSES=8 + diff --git a/examples/all_device_types_app/sdkconfig.defaults.otbr b/examples/all_device_types_app/sdkconfig.defaults.otbr new file mode 100644 index 000000000..ad74bff3b --- /dev/null +++ b/examples/all_device_types_app/sdkconfig.defaults.otbr @@ -0,0 +1,76 @@ +# Default to 115200 baud when monitoring device +CONFIG_ESPTOOLPY_MONITOR_BAUD=115200 +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y + +# Enable Openthread Border Router, but don't run matter over Thread +CONFIG_OPENTHREAD_ENABLED=y +CONFIG_OPENTHREAD_LOG_LEVEL_DYNAMIC=n +CONFIG_OPENTHREAD_LOG_LEVEL_NOTE=y +CONFIG_OPENTHREAD_BORDER_ROUTER=y +CONFIG_ENABLE_MATTER_OVER_THREAD=n + +#enable BT +CONFIG_BT_ENABLED=y +CONFIG_BT_NIMBLE_ENABLED=y + +#LwIP config for OpenThread +CONFIG_LWIP_IPV6_AUTOCONFIG=y +CONFIG_LWIP_IPV6_NUM_ADDRESSES=8 +CONFIG_LWIP_MULTICAST_PING=y +CONFIG_LWIP_IPV6_FORWARD=y +CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y +CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y +CONFIG_LWIP_NETIF_STATUS_CALLBACK=y + +# mbedTLS +CONFIG_MBEDTLS_HARDWARE_AES=y +CONFIG_MBEDTLS_HARDWARE_MPI=y +CONFIG_MBEDTLS_HARDWARE_SHA=y +CONFIG_MBEDTLS_CMAC_C=y +CONFIG_MBEDTLS_KEY_EXCHANGE_ECJPAKE=y +CONFIG_MBEDTLS_ECJPAKE_C=y +CONFIG_MBEDTLS_SSL_PROTO_DTLS=y +CONFIG_MBEDTLS_HKDF_C=y + +# MDNS platform +CONFIG_USE_MINIMAL_MDNS=n +CONFIG_ENABLE_EXTENDED_DISCOVERY=y +CONFIG_MDNS_MULTIPLE_INSTANCE=y + +# Enable chip shell +CONFIG_ENABLE_CHIP_SHELL=y +CONFIG_ESP_MATTER_CONSOLE_TASK_STACK=4096 +CONFIG_CHIP_SHELL_CMD_LINE_BUF_MAX_LENGTH=512 + +# Increase Stack size +CONFIG_CHIP_TASK_STACK_SIZE=15360 +CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192 + +# Wi-Fi Settings +CONFIG_ENABLE_WIFI_STATION=y +CONFIG_ENABLE_WIFI_AP=n + +# Disable chip test build +CONFIG_BUILD_CHIP_TESTS=n + +# Use compact attribute storage mode +CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y + +# Disable route hook for matter since OTBR has already initialize the route hook +CONFIG_ENABLE_ROUTE_HOOK=n + +# Use USB Jtag Console +CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y + +# SPIRAM +CONFIG_SPIRAM=y +CONFIG_SPIRAM_SPEED_80M=y +CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=512 +CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=8192 +CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y +CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y + +# Disable OTA Requestor +CONFIG_ENABLE_OTA_REQUESTOR=n + +CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=y