Skip to content

Commit 6e3bca5

Browse files
committed
Merge branch 'feature/cmd_resp_framework' into 'main'
Added command-response interface See merge request app-frameworks/esp-insights!163
2 parents f3a0750 + b045030 commit 6e3bca5

21 files changed

+1177
-28
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 24-Jul-2024 (Command Response Framework and Components update)
2+
- Added support for command response framework
3+
- To demonstrate this, a simple reboot command has been added. Admins can trigger this command from the Insights dashboard (under Node's Settings tab) to reboot the device.
4+
- This feature is currently supported only for nodes claimed from the RainMaker CLI and when MQTT transport is enabled.
5+
- Updated components:
6+
- Updated the rmaker_common submodule.
7+
- Bumped up the component versions for `esp_diagnostics` and `esp_insights`.
8+
19
## 23-Feb-2024 (Added support for new metadata structure 2.0)
210

311
- This change has been introduced for better management of metrics and variables hierarchy

FEATURES.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Below are some of the features offered by ESP Insights:
88
- [Transport Sharing](#transport-sharing)
99
- [Optimising Device-Cloud Communication](#optimising-device-cloud-communication)
1010
- [Group Analytics](#group-analytics)
11+
- [Command Response](#command-response)
1112

1213
### Core Dump
1314
In case of a firmware crash, the Insights agent captures the core dump information into the flash memory and reports it to the ESP Insights cloud in the subsequent boot-up. This allows you to look at all the crash logs that the devices may be generating in the field.
@@ -123,7 +124,7 @@ esp_diag_wifi_metrics_dump();
123124
```
124125

125126
#### Custom Metrics
126-
It is fairly simple to register your own metrics as well. This can be done as:
127+
It is fairly simple to register your own metrics as well. This can be done as:
127128

128129
```
129130
/* Register a metrics to track room temperature */
@@ -180,7 +181,7 @@ As you may notice, every variable has some metadata associated with it. Some exp
180181
### Transport Sharing
181182
The Insights agent supports sending data to the cloud using HTTPS or MQTT (TLS) transport.
182183

183-
Creating a separate TLS session on the device could add to the memory consumption on the device.
184+
Creating a separate TLS session on the device could add to the memory consumption on the device.
184185
To avoid this, the Insights agent shares the transport (MQTT) with your cloud agent.
185186
Currently the RainMaker cloud agent is supported.
186187
This ensures that we reuse the socket/TLS connection without adding a connection memory overhead on your device.
@@ -222,3 +223,7 @@ You can change the interval to hour or aggregate to week or a month interval.
222223
![Group Analytics 5](docs/_static/group_analytics_5.png)
223224

224225
- List of top nodes having the most number of events and can be drilled down to category level
226+
227+
### Command Response
228+
ESP Insights leverages RainMaker's command response feature to enable the device to be controllable from the Insights dashboard.
229+
- When enabled, this feature lists options under the Node's Settings tab. These interactive options can be used to control the device. For example, an admin can remotely reboot the device, enable or disable diagnostics collection, or granularly choose to enable or disable features such as Metrics and Variables.

components/esp_diagnostics/idf_component.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "1.1.0"
1+
version: "1.2.0"
22
description: Diagnostics component used in ESP Insights, which is a remote diagnostics solution to monitor the health of ESP devices in the field.
33
url: https://github.com/espressif/esp-insights/tree/main/components/esp_diagnostics
44
repository: https://github.com/espressif/esp-insights.git

components/esp_diagnostics/include/esp_diagnostics.h

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ typedef enum {
104104
ESP_DIAG_DATA_TYPE_STR, /*!< Data type string */
105105
ESP_DIAG_DATA_TYPE_IPv4, /*!< Data type IPv4 address */
106106
ESP_DIAG_DATA_TYPE_MAC, /*!< Data type MAC address */
107+
ESP_DIAG_DATA_TYPE_NULL, /*!< No type */
108+
ESP_DIAG_DATA_TYPE_MAX, /*!< Max type */
107109
} esp_diag_data_type_t;
108110

109111
/**

components/esp_insights/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set(srcs "src/esp_insights.c"
33
"src/esp_insights_transport.c"
44
"src/esp_insights_client_data.c"
55
"src/esp_insights_encoder.c"
6+
"src/esp_insights_cmd_resp.c"
67
"src/esp_insights_cbor_decoder.c"
78
"src/esp_insights_cbor_encoder.c")
89

components/esp_insights/Kconfig

+10
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ menu "ESP Insights"
4141

4242
endchoice
4343

44+
config ESP_INSIGHTS_CMD_RESP_ENABLED
45+
depends on (ESP_INSIGHTS_ENABLED && ESP_INSIGHTS_TRANSPORT_MQTT)
46+
bool "Enable command response module"
47+
default n
48+
help
49+
Enabling this option adds control of certain insights options remotely.
50+
When enabled, the available configurations, should be shown on the dashboard
51+
and controllable from there.
52+
Please note, the feature is only available with RainMaker MQTT nodes for now.
53+
4454
config ESP_INSIGHTS_TRANSPORT_HTTPS_HOST
4555
depends on ESP_INSIGHTS_TRANSPORT_HTTPS
4656
string "Insights https host"

components/esp_insights/idf_component.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "1.1.0"
1+
version: "1.2.0"
22
description: Firmware agent for ESP Insights, which is a remote diagnostics solution to monitor the health of ESP devices in the field.
33
url: https://github.com/espressif/esp-insights/tree/main/components/esp_insights
44
repository: https://github.com/espressif/esp-insights.git
@@ -13,7 +13,7 @@ dependencies:
1313
version: "~1.0"
1414
override_path: '../esp_diag_data_store/'
1515
espressif/esp_diagnostics:
16-
version: "~1.1"
16+
version: ">=1.2.0"
1717
override_path: '../esp_diagnostics/'
1818
espressif/cbor:
1919
version: "~0.6"

components/esp_insights/include/esp_insights.h

+48
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#pragma once
8+
89
#include <stdint.h>
910
#include <esp_err.h>
1011
#include <esp_event_base.h>
@@ -200,6 +201,53 @@ void esp_insights_disable(void);
200201
* @return Pointer to a NULL terminated Node ID string.
201202
*/
202203
const char *esp_insights_get_node_id(void);
204+
205+
/**
206+
* @brief Check if insights reporting is enabled
207+
*
208+
* @return true reporting is on
209+
* @return false reporting is off
210+
*/
211+
bool esp_insights_is_reporting_enabled(void);
212+
213+
/**
214+
* @brief Turn on the Insights reporting
215+
*
216+
* @return esp_err_t ESP_OK on success, apt error otherwise
217+
*/
218+
esp_err_t esp_insights_reporting_enable();
219+
220+
/**
221+
* @brief Turn off the Insights repoting
222+
*
223+
* @return esp_err_t ESP_OK on success, apt error otherwise
224+
* @note meta message if changed and the boot message will still be
225+
* sent as this information is critical for Insights working with the
226+
* cloud. You may disable insight completely using esp_insights_disable
227+
*/
228+
esp_err_t esp_insights_reporting_disable();
229+
230+
/**
231+
* @brief Encode and parse the command directly using esp-insight's parser
232+
*
233+
* This tests only if the parser is working as expected.
234+
*/
235+
esp_err_t esp_insights_test_cmd_handler();
236+
237+
/**
238+
* @brief Enable esp-insights command-response module
239+
*
240+
* This API registers esp-insights command parser which when data is received,
241+
* parses it to filter out insights specific data, modifies configs accordingly,
242+
* and prepares and gives response data to the module
243+
*
244+
* The \ref esp_insights_init takes care of initializing command response and
245+
* enabling the same. In cases where, only esp_insights_enable is called, e.g.,
246+
* ESP Rainmaker's app_insights module, user needs to call this API, before or
247+
* after \ref esp_insights_enable
248+
*/
249+
esp_err_t esp_insights_cmd_resp_enable(void);
250+
203251
#ifdef __cplusplus
204252
}
205253
#endif

0 commit comments

Comments
 (0)