-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Esp insights library support #7566
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
0116e1d
ESP Insights: Added library support
sanketwadekar 87d179e
ESP Insights: Added Examples
sanketwadekar 48a6b7b
ESP Insights: Added custom partitions file
sanketwadekar 2456199
ESP Insights: Added API documentation.
sanketwadekar 76977d1
Added recipe and script to create Insights package
sanketwadekar 87accc0
Merge branch 'master' into esp_insights
me-no-dev 86e0600
Fix postobjcopy script on UNIX
me-no-dev 10f7c9a
Fix VariablesClass::deinitNetworkVariables not returning
me-no-dev 227b36a
Updated ESP Insights examples.
sanketwadekar 0bd1a16
Changed Insights Firmware package output directory
sanketwadekar c139bab
Added Insights partition scheme to more boards.
sanketwadekar f059e15
Changed license to include SPDX license
sanketwadekar 98ae75c
Added newline at the end of files
sanketwadekar 6dcea99
Small script fixes
me-no-dev 82620a0
Merge branch 'master' into esp_insights
me-no-dev 8e7c562
Fix Insights package for Windows
me-no-dev d273cbb
Updated .exe of insights script
sanketwadekar edfd14f
Added coredump partition to all schemes
sanketwadekar c501198
Updated header files of Insights diagnostics
sanketwadekar d9d344e
Added example to insights doc
sanketwadekar 595da64
hotfix: Added elf-sha256-offset flag in elf2bin
sanketwadekar edc9b09
Merge branch 'master' into esp_insights
sanketwadekar 14d9c41
Update API to be more Arduino-like and partitions offsets
me-no-dev ca0b512
Revert adding insights partitions
me-no-dev 07b985e
Fix docs
me-no-dev a4d6a40
minor fixed of example and docs
me-no-dev fb38f84
Update DiagnosticsSmokeTest.ino
me-no-dev b1a36ba
Update Insights.cpp
me-no-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,274 @@ | ||
############ | ||
ESP Insights | ||
############ | ||
|
||
About | ||
----- | ||
|
||
ESP Insights is a remote diagnostics solution that allows users to remotely monitor the health of ESP devices in the field. | ||
|
||
Developers normally prefer debugging issues by physically probing them using gdb or observing the logs. This surely helps debug issues, but there are often cases wherein issues are seen only in specific environments under specific conditions. Even things like casings and placement of the product can affect the behaviour. A few examples are | ||
|
||
- Wi-Fi disconnections for a smart switch concealed in a wall. | ||
- Smart speakers crashing during some specific usage pattern. | ||
- Appliance frequently rebooting due to power supply issues. | ||
|
||
Additional information about ESP Insights can be found `here <https://insights.espressif.com/>`__. | ||
|
||
ESP Insights Agent API | ||
---------------------- | ||
|
||
Insights.begin | ||
************** | ||
|
||
This initializes the ESP Insights agent. | ||
|
||
.. code-block:: arduino | ||
|
||
bool begin(const char *auth_key, const char *node_id = NULL, uint32_t log_type = 0xFFFFFFFF, bool alloc_ext_ram = false); | ||
|
||
* ``auth_key`` Auth key generated using Insights dashboard | ||
* ``log_type`` Type of logs to be captured (value can be a mask of ESP_DIAG_LOG_TYPE_ERROR, ESP_DIAG_LOG_TYPE_WARNING and ESP_DIAG_LOG_TYPE_EVENT) | ||
|
||
This function will return | ||
|
||
1. true : On success | ||
2. false in case of failure | ||
|
||
Insights.send | ||
************* | ||
|
||
Read insights data from buffers and send it to the cloud. Call to this function is asynchronous, it may take some time to send the data. | ||
|
||
.. code-block:: arduino | ||
|
||
bool sendData() | ||
|
||
This function will return | ||
|
||
1. true : On success | ||
2. false in case of failure | ||
|
||
Insights.end | ||
************ | ||
|
||
Deinitialize ESP Insights. | ||
|
||
.. code-block:: arduino | ||
|
||
void end(); | ||
|
||
Insights.disable | ||
**************** | ||
|
||
Disable ESP Insights. | ||
|
||
.. code-block:: arduino | ||
|
||
void disable(); | ||
|
||
ESP Insights Metrics API | ||
------------------------ | ||
|
||
`metrics` object of `Insights` class expose API's for using metrics. | ||
|
||
Insights.metrics.addX | ||
********************* | ||
|
||
Register a metric of type X, where X is one of: Bool, Int, Uint, Float, String, IPv4 or MAC | ||
|
||
.. code-block:: arduino | ||
|
||
bool addX(const char *tag, const char *key, const char *label, const char *path); | ||
|
||
* ``tag`` : Tag of metrics | ||
* ``key`` : Unique key for the metrics | ||
* ``label`` : Label for the metrics | ||
* ``path`` : Hierarchical path for key, must be separated by '.' for more than one level | ||
|
||
This function will return | ||
|
||
1. true : On success | ||
2. false in case of failure | ||
|
||
Insights.metrics.remove | ||
*********************** | ||
|
||
Unregister a diagnostics metrics | ||
|
||
.. code-block:: arduino | ||
|
||
bool remove(const char *key); | ||
|
||
* ``key`` : Key for the metrics | ||
|
||
This function will return | ||
|
||
1. true : On success | ||
2. false in case of failure | ||
|
||
Insights.metrics.removeAll | ||
************************** | ||
|
||
Unregister all previously registered metrics | ||
|
||
.. code-block:: arduino | ||
|
||
bool removeAll(); | ||
|
||
This function will return | ||
|
||
1. true : On success | ||
2. false in case of failure | ||
|
||
Insights.metrics.setX | ||
********************* | ||
|
||
Add metrics of type X to storage, where X is one of: Bool, Int, Uint, Float, String, IPv4 or MAC | ||
|
||
.. code-block:: arduino | ||
|
||
bool setX(const char *key, const void val); | ||
|
||
* ``key`` : Key of metrics | ||
* ``val`` : Value of metrics | ||
|
||
This function will return | ||
|
||
1. `ESP_OK` : On success | ||
2. Error in case of failure | ||
|
||
Insights.metrics.dumpHeap | ||
************************* | ||
|
||
Dumps the heap metrics and prints them to the console. | ||
This API collects and reports metrics value at any give point in time. | ||
|
||
.. code-block:: arduino | ||
|
||
bool dumpHeap(); | ||
|
||
This function will return | ||
|
||
1. true : On success | ||
2. false in case of failure | ||
|
||
Insights.metrics.dumpWiFi | ||
************************* | ||
|
||
Dumps the wifi metrics and prints them to the console. | ||
This API can be used to collect wifi metrics at any given point in time. | ||
|
||
.. code-block:: arduino | ||
|
||
bool dumpWiFi(); | ||
|
||
This function will return | ||
|
||
1. true : On success | ||
2. false in case of failure | ||
|
||
Insights.metrics.setHeapPeriod | ||
****************************** | ||
|
||
Reset the periodic interval | ||
By default, heap metrics are collected every 30 seconds, this function can be used to change the interval. | ||
If the interval is set to 0, heap metrics collection disabled. | ||
|
||
.. code-block:: arduino | ||
|
||
void setHeapPeriod(uint32_t period); | ||
|
||
* ``period`` : Period interval in seconds | ||
|
||
Insights.metrics.setWiFiPeriod | ||
****************************** | ||
|
||
Reset the periodic interval | ||
By default, wifi metrics are collected every 30 seconds, this function can be used to change the interval. | ||
If the interval is set to 0, wifi metrics collection disabled. | ||
|
||
.. code-block:: arduino | ||
|
||
void setHeapPeriod(uint32_t period); | ||
|
||
* ``period`` : Period interval in seconds | ||
|
||
ESP Insights Variables API | ||
-------------------------- | ||
|
||
`variables` object of `Insights` class expose API's for using variables. | ||
|
||
Insights.variables.addX | ||
*********************** | ||
|
||
Register a variable of type X, where X is one of: Bool, Int, Uint, Float, String, IPv4 or MAC | ||
|
||
.. code-block:: arduino | ||
|
||
bool addX(const char *tag, const char *key, const char *label, const char *path); | ||
|
||
* ``tag`` : Tag of variable | ||
* ``key`` : Unique key for the variable | ||
* ``label`` : Label for the variable | ||
* ``path`` : Hierarchical path for key, must be separated by '.' for more than one level | ||
|
||
This function will return | ||
|
||
1. true : On success | ||
2. false in case of failure | ||
|
||
Insights.variables.remove | ||
************************* | ||
|
||
Unregister a diagnostics variable | ||
|
||
.. code-block:: arduino | ||
|
||
bool remove(const char *key); | ||
|
||
* ``key`` : Key for the variable | ||
|
||
This function will return | ||
|
||
1. true : On success | ||
2. false in case of failure | ||
|
||
Insights.variables.removeAll | ||
**************************** | ||
|
||
Unregister all previously registered variables | ||
|
||
.. code-block:: arduino | ||
|
||
bool unregisterAll(); | ||
|
||
This function will return | ||
|
||
1. true : On success | ||
2. false in case of failure | ||
|
||
Insights.variables.setX | ||
*********************** | ||
|
||
Add variable of type X to storage, where X is one of: Bool, Int, Uint, Float, String, IPv4 or MAC | ||
|
||
.. code-block:: arduino | ||
|
||
bool setX(const char *key, const void val); | ||
|
||
* ``key`` : Key of metrics | ||
* ``val`` : Value of metrics | ||
|
||
This function will return | ||
|
||
1. true : On success | ||
2. false in case of failure | ||
|
||
Example | ||
------- | ||
|
||
To get started with Insights, you can try: | ||
|
||
.. literalinclude:: ../../../libraries/Insights/examples/MinimalDiagnostics/MinimalDiagnostics.ino | ||
:language: arduino |
97 changes: 97 additions & 0 deletions
97
libraries/Insights/examples/DiagnosticsSmokeTest/DiagnosticsSmokeTest.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#include "Insights.h" | ||
#include "WiFi.h" | ||
#include "inttypes.h" | ||
#include "esp_err.h" | ||
|
||
const char insights_auth_key[] = "<ENTER YOUR AUTH KEY>"; | ||
|
||
#define WIFI_SSID "<ENTER YOUR SSID>" | ||
#define WIFI_PASSPHRASE "<ENTER YOUR PASSWORD>" | ||
|
||
#define MAX_CRASHES 5 | ||
#define MAX_PTRS 30 | ||
#define TAG "sketch" | ||
|
||
RTC_NOINIT_ATTR static uint32_t s_reset_count; | ||
static void *s_ptrs[MAX_PTRS]; | ||
|
||
static void smoke_test() | ||
{ | ||
int dice; | ||
int count = 0; | ||
bool allocating = false; | ||
|
||
while (1) { | ||
dice = esp_random() % 500; | ||
log_i("dice=%d", dice); | ||
if (dice > 0 && dice < 150) { | ||
log_e("[count][%d]", count); | ||
} else if (dice > 150 && dice < 300) { | ||
log_w("[count][%d]", count); | ||
} else if (dice > 300 && dice < 470) { | ||
Insights.event(TAG, "[count][%d]", count); | ||
} else { | ||
/* 30 in 500 probability to crash */ | ||
if (s_reset_count > MAX_CRASHES) { | ||
Insights.event(TAG, "[count][%d]", count); | ||
} else { | ||
log_e("[count][%d] [crash_count][%" PRIu32 "] [excvaddr][0x0f] Crashing...", count, s_reset_count); | ||
*(int *)0x0F = 0x10; | ||
} | ||
} | ||
|
||
Insights.metrics.dumpHeap(); | ||
if (count % MAX_PTRS == 0) { | ||
allocating = !allocating; | ||
log_i("Allocating:%s\n", allocating ? "true" : "false"); | ||
} | ||
if (allocating) { | ||
uint32_t size = 1024 * (esp_random() % 8); | ||
void *p = malloc(size); | ||
if (p) { | ||
memset(p, size, 'A' + (esp_random() % 26)); | ||
log_i("Allocated %" PRIu32 " bytes", size); | ||
} | ||
s_ptrs[count % MAX_PTRS] = p; | ||
} else { | ||
free(s_ptrs[count % MAX_PTRS]); | ||
s_ptrs[count % MAX_PTRS] = NULL; | ||
log_i("Freeing some memory..."); | ||
} | ||
|
||
count++; | ||
delay(1000); | ||
} | ||
} | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
WiFi.mode(WIFI_STA); | ||
WiFi.begin(WIFI_SSID, WIFI_PASSPHRASE); | ||
while (WiFi.status() != WL_CONNECTED) { | ||
delay(500); | ||
Serial.print("."); | ||
} | ||
me-no-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Serial.println(""); | ||
Serial.println("WiFi connected"); | ||
|
||
if(!Insights.begin(insights_auth_key)){ | ||
return; | ||
} | ||
Serial.println("========================================="); | ||
Serial.printf("ESP Insights enabled Node ID %s\n", Insights.nodeID()); | ||
Serial.println("========================================="); | ||
|
||
if (esp_reset_reason() == ESP_RST_POWERON) { | ||
s_reset_count = 1; | ||
} else { | ||
s_reset_count++; | ||
} | ||
} | ||
|
||
void loop() | ||
{ | ||
smoke_test(); | ||
delay(100); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pedrominatel PTAL