esp_insights: Add facility to enable esp_insights in the examples

Please check out CHANGES.md as this commit may break your existing
projects' compilation.
This commit is contained in:
Piyush Shah
2021-07-02 22:29:11 +05:30
parent 948ed9db49
commit 0c84527cfb
23 changed files with 206 additions and 10 deletions

3
.gitmodules vendored
View File

@@ -10,3 +10,6 @@
[submodule "cli"]
path = cli
url = ../esp-rainmaker-cli.git
[submodule "components/esp-insights"]
path = components/esp-insights
url = ../esp-insights.git

View File

@@ -1,5 +1,32 @@
# Changes
## 02-Jul-2021 (esp_insights: Add facility to enable esp_insights in the examples)
This commit introduces a breaking change in compilation, not due to any API change,
but introduction of new components under components/esp-insights/components.
You can either choose to include these components in your projects CMakeLists.txt
as per the standard examples as given here:
```
set(EXTRA_COMPONENT_DIRS ${RMAKER_PATH}/components ${RMAKER_PATH}/examples/common ${RMAKER_PATH}/components/esp-insights/components)
```
You will also have to pull in the new esp-insights submodule by executing this command:
```
git submodule update --init --recursive
```
Another option is to exclude the common example component (app_insights) that adds these
components to the dependencies by adding this to your project's CMakeLists.txt:
```
set(EXCLUDE_COMPONENTS app_insights)
```
Check out the [esp-insights](https://github.com/espressif/esp-insights) project to understand more about this.
You can also check the docs [here](https://rainmaker.espressif.com/docs/esp-insights.html) to get started with enabling Insights in ESP RainMaker.
## 28-May-2021 (esp_rmaker_core: Add a system service for reboot/reset)
The reboot/reset API prototypes have changed from

View File

@@ -11,7 +11,7 @@ set(core_srcs "src/core/esp_rmaker_core.c"
"src/core/esp_rmaker_user_mapping.c"
"src/core/esp_rmaker_schedule.c")
set(priv_req protobuf-c json_parser json_generator wifi_provisioning nvs_flash esp_http_client app_update esp-tls mbedtls esp_https_ota console esp_local_ctrl esp_https_server mdns esp_schedule rmaker_common)
set(priv_req protobuf-c json_parser json_generator wifi_provisioning nvs_flash esp_http_client app_update esp-tls mbedtls esp_https_ota console esp_local_ctrl esp_https_server mdns esp_schedule)
if(CONFIG_ESP_RMAKER_ASSISTED_CLAIM)
@@ -53,7 +53,7 @@ set(standard_types_srcs "src/standard_types/esp_rmaker_standard_params.c"
idf_component_register(SRCS ${core_srcs} ${mqtt_srcs} ${ota_srcs} ${standard_types_srcs} ${console_srcs}
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS ${core_priv_includes} ${ota_priv_includes} ${console_priv_includes}
REQUIRES
REQUIRES rmaker_common
PRIV_REQUIRES ${priv_req})
target_add_binary_data(${COMPONENT_TARGET} "server_certs/mqtt_server.crt" TEXT)

View File

@@ -0,0 +1,3 @@
idf_component_register(SRCS "app_insights.c"
INCLUDE_DIRS "."
PRIV_REQUIRES esp_insights esp_diagnostics esp_rainmaker)

View File

@@ -0,0 +1,11 @@
menu "App Insights"
visible if ESP_INSIGHTS_ENABLED
config APP_INSIGHTS_ENABLE_LOG_TYPE_ALL
bool "Enable all diagnostics log type"
default y
help
By default this enables error and event diagnostics log types.
This config option quickly disables the capture of all these log types.
endmenu

View File

@@ -0,0 +1,62 @@
/*
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 <esp_err.h>
#include <esp_log.h>
#ifdef CONFIG_ESP_INSIGHTS_ENABLED
#include <esp_rmaker_mqtt.h>
#include <esp_insights.h>
#include <esp_diagnostics_system_metrics.h>
#if CONFIG_APP_INSIGHTS_ENABLE_LOG_TYPE_ALL
#define APP_INSIGHTS_LOG_TYPE ESP_DIAG_LOG_TYPE_ERROR \
| ESP_DIAG_LOG_TYPE_EVENT
#else
#define APP_INSIGHTS_LOG_TYPE 0
#endif /* CONFIG_APP_INSIGHTS_ENABLE_LOG_TYPE_ALL */
#endif /* CONFIG_ESP_INSIGHTS_ENABLED */
static const char *TAG = "app_insights";
esp_err_t app_insights_enable(void)
{
#ifdef CONFIG_ESP_INSIGHTS_ENABLED
#ifdef CONFIG_ESP_RMAKER_SELF_CLAIM
ESP_LOGW(TAG, "Nodes with Self Claiming may not be accessible for Insights.");
/* This is required so that the esp insights component will get correct
* node id from NVS
*/
char *node_id = esp_rmaker_get_node_id();
if (node_id) {
esp_rmaker_factory_set("node_id", node_id, strlen(node_id));
}
#endif
esp_rmaker_mqtt_config_t mqtt_config = {
.init = NULL,
.connect = NULL,
.disconnect = NULL,
.publish = esp_rmaker_mqtt_publish,
.subscribe = esp_rmaker_mqtt_subscribe,
.unsubscribe = esp_rmaker_mqtt_unsubscribe,
};
esp_insights_mqtt_setup(mqtt_config);
esp_insights_config_t config = {
.log_type = APP_INSIGHTS_LOG_TYPE,
};
esp_insights_rmaker_enable(&config);
ESP_LOGI(TAG, "App Insights Enabled.");
#ifdef CONFIG_DIAG_ENABLE_HEAP_METRICS
/* Dump heap metrics */
esp_diag_heap_metrics_dump();
#endif /* CONFIG_DIAG_ENABLE_HEAP_METRICS */
#else
ESP_LOGI(TAG, "Enable CONFIG_ESP_INSIGHTS_ENABLED to get Insights.");
#endif /* ! CONFIG_ESP_INSIGHTS_ENABLED */
return ESP_OK;
}

View File

@@ -0,0 +1,17 @@
/*
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
#include <stdint.h>
#include <esp_err.h>
/* Enable ESP Insights in the application
*
* @return ESP_OK on success.
* @return error in case of failure.
*/
esp_err_t app_insights_enable(void);

View File

@@ -0,0 +1,2 @@
COMPONENT_ADD_INCLUDEDIRS := .
COMPONENT_SRCDIRS := .

View File

@@ -2,9 +2,14 @@
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
# Add RainMaker components and other common application components
set(EXTRA_COMPONENT_DIRS ${CMAKE_CURRENT_LIST_DIR}/../../components ${CMAKE_CURRENT_LIST_DIR}/../common)
if(DEFINED ENV{RMAKER_PATH})
set(RMAKER_PATH $ENV{RMAKER_PATH})
else()
set(RMAKER_PATH ${CMAKE_CURRENT_LIST_DIR}/../..)
endif(DEFINED ENV{RMAKER_PATH})
# Add RainMaker components and other common application components
set(EXTRA_COMPONENT_DIRS ${RMAKER_PATH}/components ${RMAKER_PATH}/examples/common ${RMAKER_PATH}/components/esp-insights/components)
set(PROJECT_VER "1.0")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)

View File

@@ -19,6 +19,7 @@
#include <esp_rmaker_schedule.h>
#include <app_wifi.h>
#include <app_insights.h>
#include "app_priv.h"
@@ -99,6 +100,9 @@ void app_main()
/* Enable scheduling. */
esp_rmaker_schedule_enable();
/* Enable Insights. Requires CONFIG_ESP_INSIGHTS_ENABLED=y */
app_insights_enable();
/* Start the ESP RainMaker Agent */
esp_rmaker_start();

View File

@@ -2,8 +2,14 @@
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
if(DEFINED ENV{RMAKER_PATH})
set(RMAKER_PATH $ENV{RMAKER_PATH})
else()
set(RMAKER_PATH ${CMAKE_CURRENT_LIST_DIR}/../..)
endif(DEFINED ENV{RMAKER_PATH})
# Add RainMaker components and other common application components
set(EXTRA_COMPONENT_DIRS ${CMAKE_CURRENT_LIST_DIR}/../../components ${CMAKE_CURRENT_LIST_DIR}/../common)
set(EXTRA_COMPONENT_DIRS ${RMAKER_PATH}/components ${RMAKER_PATH}/examples/common ${RMAKER_PATH}/components/esp-insights/components)
set(PROJECT_VER "1.0")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)

View File

@@ -17,6 +17,7 @@
#include <esp_rmaker_standard_types.h>
#include <app_wifi.h>
#include <app_insights.h>
#include "app_priv.h"
@@ -85,6 +86,9 @@ void app_main()
esp_rmaker_node_add_device(node, gpio_device);
/* Enable Insights. Requires CONFIG_ESP_INSIGHTS_ENABLED=y */
app_insights_enable();
/* Start the ESP RainMaker Agent */
esp_rmaker_start();

View File

@@ -6,8 +6,14 @@ if(NOT DEFINED ENV{HOMEKIT_PATH})
message(FATAL_ERROR "Please set HOMEKIT_PATH to esp-homekit-sdk repo")
endif(NOT DEFINED ENV{HOMEKIT_PATH})
if(DEFINED ENV{RMAKER_PATH})
set(RMAKER_PATH $ENV{RMAKER_PATH})
else()
set(RMAKER_PATH ${CMAKE_CURRENT_LIST_DIR}/../..)
endif(DEFINED ENV{RMAKER_PATH})
# Add RainMaker components and other common application components
set(EXTRA_COMPONENT_DIRS $ENV{HOMEKIT_PATH}/components/homekit ${CMAKE_CURRENT_LIST_DIR}/../../components ${CMAKE_CURRENT_LIST_DIR}/../common)
set(EXTRA_COMPONENT_DIRS $ENV{HOMEKIT_PATH}/components/homekit ${RMAKER_PATH}/components ${RMAKER_PATH}/examples/common ${RMAKER_PATH}/components/esp-insights/components)
set(PROJECT_VER "1.0")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)

View File

@@ -22,6 +22,8 @@
#include <esp_rmaker_console.h>
#include <esp_rmaker_common_events.h>
#include <app_insights.h>
#include "app_wifi_with_homekit.h"
#include "app_priv.h"
@@ -159,6 +161,9 @@ void app_main()
};
esp_rmaker_ota_enable(&ota_config, OTA_USING_PARAMS);
/* Enable Insights. Requires CONFIG_ESP_INSIGHTS_ENABLED=y */
app_insights_enable();
/* Start the ESP RainMaker Agent */
esp_rmaker_start();

View File

@@ -2,8 +2,14 @@
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
if(DEFINED ENV{RMAKER_PATH})
set(RMAKER_PATH $ENV{RMAKER_PATH})
else()
set(RMAKER_PATH ${CMAKE_CURRENT_LIST_DIR}/../..)
endif(DEFINED ENV{RMAKER_PATH})
# Add RainMaker components and other common application components
set(EXTRA_COMPONENT_DIRS ${CMAKE_CURRENT_LIST_DIR}/../../components ${CMAKE_CURRENT_LIST_DIR}/../common)
set(EXTRA_COMPONENT_DIRS ${RMAKER_PATH}/components ${RMAKER_PATH}/examples/common ${RMAKER_PATH}/components/esp-insights/components)
set(PROJECT_VER "1.0")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)

View File

@@ -20,6 +20,7 @@
#include <esp_rmaker_schedule.h>
#include <app_wifi.h>
#include <app_insights.h>
#include "app_priv.h"
@@ -120,6 +121,9 @@ void app_main()
/* Enable scheduling. */
esp_rmaker_schedule_enable();
/* Enable Insights. Requires CONFIG_ESP_INSIGHTS_ENABLED=y */
app_insights_enable();
/* Start the ESP RainMaker Agent */
esp_rmaker_start();

View File

@@ -2,8 +2,14 @@
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
if(DEFINED ENV{RMAKER_PATH})
set(RMAKER_PATH $ENV{RMAKER_PATH})
else()
set(RMAKER_PATH ${CMAKE_CURRENT_LIST_DIR}/../..)
endif(DEFINED ENV{RMAKER_PATH})
# Add RainMaker components and other common application components
set(EXTRA_COMPONENT_DIRS ${CMAKE_CURRENT_LIST_DIR}/../../components ${CMAKE_CURRENT_LIST_DIR}/../common)
set(EXTRA_COMPONENT_DIRS ${RMAKER_PATH}/components ${RMAKER_PATH}/examples/common ${RMAKER_PATH}/components/esp-insights/components)
set(PROJECT_VER "1.0")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)

View File

@@ -19,6 +19,7 @@
#include <esp_rmaker_schedule.h>
#include <app_wifi.h>
#include <app_insights.h>
#include "app_priv.h"
@@ -128,6 +129,9 @@ void app_main()
/* Enable scheduling. */
esp_rmaker_schedule_enable();
/* Enable Insights. Requires CONFIG_ESP_INSIGHTS_ENABLED=y */
app_insights_enable();
/* Start the ESP RainMaker Agent */
esp_rmaker_start();

View File

@@ -2,8 +2,14 @@
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
if(DEFINED ENV{RMAKER_PATH})
set(RMAKER_PATH $ENV{RMAKER_PATH})
else()
set(RMAKER_PATH ${CMAKE_CURRENT_LIST_DIR}/../..)
endif(DEFINED ENV{RMAKER_PATH})
# Add RainMaker components and other common application components
set(EXTRA_COMPONENT_DIRS ${CMAKE_CURRENT_LIST_DIR}/../../components ${CMAKE_CURRENT_LIST_DIR}/../common)
set(EXTRA_COMPONENT_DIRS ${RMAKER_PATH}/components ${RMAKER_PATH}/examples/common ${RMAKER_PATH}/components/esp-insights/components)
set(PROJECT_VER "1.0")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)

View File

@@ -25,6 +25,7 @@
#include <esp_rmaker_common_events.h>
#include <app_wifi.h>
#include <app_insights.h>
#include "app_priv.h"
@@ -180,6 +181,9 @@ void app_main()
/* Enable scheduling. */
esp_rmaker_schedule_enable();
/* Enable Insights. Requires CONFIG_ESP_INSIGHTS_ENABLED=y */
app_insights_enable();
/* Start the ESP RainMaker Agent */
esp_rmaker_start();

View File

@@ -2,8 +2,14 @@
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
if(DEFINED ENV{RMAKER_PATH})
set(RMAKER_PATH $ENV{RMAKER_PATH})
else()
set(RMAKER_PATH ${CMAKE_CURRENT_LIST_DIR}/../..)
endif(DEFINED ENV{RMAKER_PATH})
# Add RainMaker components and other common application components
set(EXTRA_COMPONENT_DIRS ${CMAKE_CURRENT_LIST_DIR}/../../components ${CMAKE_CURRENT_LIST_DIR}/../common)
set(EXTRA_COMPONENT_DIRS ${RMAKER_PATH}/components ${RMAKER_PATH}/examples/common ${RMAKER_PATH}/components/esp-insights/components)
set(PROJECT_VER "1.0")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)

View File

@@ -18,6 +18,7 @@
#include <esp_rmaker_standard_devices.h>
#include <app_wifi.h>
#include <app_insights.h>
#include "app_priv.h"
@@ -61,6 +62,9 @@ void app_main()
temp_sensor_device = esp_rmaker_temp_sensor_device_create("Temperature Sensor", NULL, app_get_current_temperature());
esp_rmaker_node_add_device(node, temp_sensor_device);
/* Enable Insights. Requires CONFIG_ESP_INSIGHTS_ENABLED=y */
app_insights_enable();
/* Start the ESP RainMaker Agent */
esp_rmaker_start();