diff --git a/examples/common/app_insights/CMakeLists.txt b/examples/common/app_insights/CMakeLists.txt new file mode 100644 index 000000000..3e89c706e --- /dev/null +++ b/examples/common/app_insights/CMakeLists.txt @@ -0,0 +1,16 @@ +# App Insights + +if(CONFIG_ESP_MATTER_ENABLE_INSIGHTS) + set(srcs app_insights.c) +endif() + +idf_component_register(SRCS ${srcs} + INCLUDE_DIRS . + PRIV_REQUIRES ) + +if(CONFIG_ESP_MATTER_ENABLE_INSIGHTS) + idf_component_get_property(esp_insights_lib esp_insights COMPONENT_LIB) + idf_component_get_property(esp_diag_lib esp_diagnostics COMPONENT_LIB) + target_link_libraries(${COMPONENT_LIB} PRIVATE ${esp_insights_lib}) + target_link_libraries(${COMPONENT_LIB} PRIVATE ${esp_diag_lib}) +endif() diff --git a/examples/common/app_insights/Kconfig b/examples/common/app_insights/Kconfig new file mode 100644 index 000000000..55f0fcf4b --- /dev/null +++ b/examples/common/app_insights/Kconfig @@ -0,0 +1,12 @@ +menu "ESP Matter Insights" + + config ESP_MATTER_ENABLE_INSIGHTS + bool "ESP Matter Enable Insights" + default n + select ESP_INSIGHTS_ENABLED + help + Enable the ESP Matter Insights service. + ESP Insights is a remote diagnostics solution that allows users to + remotely monitor the devices in the field. + +endmenu diff --git a/examples/common/app_insights/app_insights.c b/examples/common/app_insights/app_insights.c new file mode 100644 index 000000000..b0d3e603f --- /dev/null +++ b/examples/common/app_insights/app_insights.c @@ -0,0 +1,22 @@ +/* + 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. +*/ + +#include +#include + +esp_err_t app_insights_enable(const char *auth_key) +{ + // Sync the time with the NTP server + esp_rmaker_time_sync_init(NULL); + + esp_insights_config_t config = { + .log_type = ESP_DIAG_LOG_TYPE_ERROR | ESP_DIAG_LOG_TYPE_WARNING, + .auth_key = auth_key, + }; + return esp_insights_init(&config); +} diff --git a/examples/common/app_insights/app_insights.h b/examples/common/app_insights/app_insights.h new file mode 100644 index 000000000..b5d2ac8ad --- /dev/null +++ b/examples/common/app_insights/app_insights.h @@ -0,0 +1,29 @@ +/* + 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. +*/ +#pragma once + +#if __cplusplus +extern "C" { +#endif + +#if CONFIG_ESP_MATTER_ENABLE_INSIGHTS + +/** + * @brief Initialize the app insights in matter example + * + * @param[in] auth_key The app insights auth key + * + * @return ESP_OK on success, appropriate error code otherwise + */ +esp_err_t app_insights_enable(const char *auth_key); + +#endif // CONFIG_ESP_MATTER_ENABLE_INSIGHTS + +#if __cplusplus +} +#endif diff --git a/examples/common/app_insights/idf_component.yml b/examples/common/app_insights/idf_component.yml new file mode 100644 index 000000000..43210f225 --- /dev/null +++ b/examples/common/app_insights/idf_component.yml @@ -0,0 +1,20 @@ +## IDF Component Manager Manifest File +dependencies: + idf: + version: ">=4.4.0" + + rtc_store: + path: components/rtc_store + git: https://github.com/espressif/esp-insights.git + + esp_diagnostics: + path: components/esp_diagnostics + git: https://github.com/espressif/esp-insights.git + + rmaker_common: + path: ./ + git: https://github.com/espressif/esp-rainmaker-common.git + + esp_insights: + path: components/esp_insights + git: https://github.com/espressif/esp-insights.git diff --git a/examples/light/main/CMakeLists.txt b/examples/light/main/CMakeLists.txt index b9a2c8e4b..b3725c3ae 100644 --- a/examples/light/main/CMakeLists.txt +++ b/examples/light/main/CMakeLists.txt @@ -1,4 +1,4 @@ -set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_qrcode app_reset esp_matter_ota) +set(PRIV_REQUIRES_LIST device esp_matter esp_matter_console route_hook app_qrcode app_reset esp_matter_ota app_insights) idf_component_register(SRC_DIRS "." PRIV_INCLUDE_DIRS "." diff --git a/examples/light/main/app_main.cpp b/examples/light/main/app_main.cpp index 2ca037137..d03d27465 100644 --- a/examples/light/main/app_main.cpp +++ b/examples/light/main/app_main.cpp @@ -17,6 +17,15 @@ #include #include +#include + +#if CONFIG_ESP_MATTER_ENABLE_INSIGHTS +/* + * Please check the below link to obtain the ESP Insights Auth Key + * https://github.com/espressif/esp-insights/tree/4bc3b0685223a75df0ce71c73af70014f4dd1633/examples#set-up-esp-insights-account + */ +const char * INSIGHTS_AUTH_KEY = ""; +#endif static const char *TAG = "app_main"; int light_endpoint_id = 0; @@ -94,4 +103,8 @@ extern "C" void app_main() #if CONFIG_ENABLE_OTA_REQUESTOR esp_matter_ota_requestor_init(); #endif + +#if CONFIG_ESP_MATTER_ENABLE_INSIGHTS + app_insights_enable(INSIGHTS_AUTH_KEY); +#endif }