ESp-insights not working properly

MattiaBerton
Posts: 36
Joined: Thu Aug 30, 2018 8:16 am

ESp-insights not working properly

Postby MattiaBerton » Thu Nov 10, 2022 3:31 pm

Hello,
I'm using an ESP32 with IDF 5.0-dev. I'm trying to implement the ESP_insights, but I faced some problems: I can start the esp_insights correctly in this way:

Code: Select all

	esp_rmaker_time_sync_init(NULL);

	esp_insights_config_t config = {
		.log_type = ESP_DIAG_LOG_TYPE_ERROR | ESP_DIAG_LOG_TYPE_WARNING | ESP_DIAG_LOG_TYPE_EVENT,
		.auth_key = insights_auth_key_start,
	};
	ret = esp_insights_init(&config);
	if (ret != ESP_OK) {
		ESP_LOGE(TAG, "Failed to initialize ESP Insights, err:0x%x", ret);
	}
	ESP_ERROR_CHECK(ret);

	/* Register a metrics to track room temperature */
	esp_diag_metrics_register("temp", "temp1", "Room temperature", "room", ESP_DIAG_DATA_TYPE_FLOAT);
And the log appears to approve:

Code: Select all

I (3331) esp_rmaker_work_queue: Work Queue created.
I (3336) esp_insights: =========================================
I (3342) esp_insights: Insights enabled for Node ID 34AB9553C2DC
I (3349) esp_insights: =========================================
W (3355) insights_transport: connect callback not set
I (3361) esp_rmaker_work_queue: RainMaker Work Queue task started.
However, when I try to dump into Insights, I got some problems:

Code: Select all

I (3461) esp_insights: RTC_STORE_EVENT_NON_CRITICAL_DATA_LOW_MEM
rtc_store_non_critical_data_write failed group temp, len 40, err 0x0101
I (3563) esp_insights: RTC_STORE_EVENT_NON_CRITICAL_DATA_LOW_MEM
rtc_store_non_critical_data_write failed group temp, len 40, err 0x0101
Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.

Setting breakpoint at 0x4008b7aa and returning...
The code use to dump is:

Code: Select all

void InsightTask(void * argument)
{
	
	while (1)
	{
		//esp_diag_heap_metrics_dump();
		vTaskDelay(pdMS_TO_TICKS(60000));
			/* Record a data point for room temperature */
	float room_temp = 22.2;
	esp_diag_metrics_add_float("temp1", room_temp);

	}
}
I tried to increase the RTC store data size, but with no success... If I try to overwrite non critical data (CONFIG_RTC_STORE_OVERWRITE_NON_CRITICAL_DATA = 1) I don't get a crash but a continuous
esp_insights: RTC_STORE_EVENT_NON_CRITICAL_DATA_LOW_MEM
.

Why does it happen? What should I do to avoid this Low mem error? From the ESP insight dashboard I can't see any node connected, but I see that "Billing and Usage" level keeps incrementing when I try to start the firmware, so it appears to be somehow connected. Can you help me?

Thank you,
Mattia

ESP_Vikram
Posts: 25
Joined: Fri Nov 23, 2018 12:07 pm

Re: ESp-insights not working properly

Postby ESP_Vikram » Fri Nov 11, 2022 5:30 am

Hello @MattiaBarten,

Thanks for reaching out.
LOW_MEM error is when you try to record the insights data point but cannot since the RTC buffer is full, mostly because you are not reporting the data fast enough.

Did you try examples provided by esp-insights without any change? Did those work fine?

What are the other changes you did on top of the minimal_diagnostic example?

Also, please share the top commit log from your insights repo. And do pull in the latest code, if you are on an older commit.
I am on the latest release/v5.0 of IDF branch and the example code above works fine for me. I would suggest you please check for anything breaking in your code If the minimal example works fine.

From my devcon demo, here is what I added to minimal_diagnstic example:

Code: Select all

static bool temp_metrics_enabled = false;
esp_err_t temperature_sensor_init(void)
{
#ifdef CONFIG_IDF_TARGET_ESP32S3
    temp_sensor_config_t config = TSENS_CONFIG_DEFAULT();
    config.dac_offset = TSENS_DAC_DEFAULT; // DEFAULT: range:-10℃ ~  80℃, error < 1℃.

    esp_err_t err = temp_sensor_set_config(config);
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "Failed to set temperature sensor config, err:0x%x", err);
        return err;
    }

    err = temp_sensor_start();
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "Failed to start temperature sensor, err:0x%x", err);
        return err;
    }
#endif
    return ESP_OK;
}

esp_err_t temperature_metrics_dump(void)
{
    if (temp_metrics_enabled == false) {
        // skip, the temp metrics are not enabled
        return ESP_FAIL;
    }

    float temperature;
    esp_err_t err = ESP_OK;

#ifdef CONFIG_IDF_TARGET_ESP32S3
    err = temp_sensor_read_celsius(&temperature);
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "Failed to read temperature sensor err:0x%x err_str:%s", err, esp_err_to_name(err));
        return err;
    }
#else
    temperature = rand() % 100;
#endif
    err = esp_diag_metrics_add_float(KEY_TEMP, temperature);
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "Failed to add temperature sensor metric err:0x%x err_str:%s", err, esp_err_to_name(err));
        return err;
    }

    ESP_LOGI(TAG, CONFIG_IDF_TARGET " chip temperature %f°C", temperature);
    return ESP_OK;
}

esp_err_t custom_metrics_init()
{
#ifdef CONFIG_IDF_TARGET_ESP32S3
    if (temperature_sensor_init() != ESP_OK) {
        ESP_LOGE(TAG, "Failed to init temp sensor");
        return ESP_FAIL;
    }
#endif
    // register our custom metrics
    esp_err_t err = esp_diag_metrics_register(METRICS_TAG, KEY_TEMP, "Chip tempetature in Celcius",
                                              PATH_TEMP, ESP_DIAG_DATA_TYPE_FLOAT);
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "Failed to register temperature sensor metric err:0x%x err_str:%s", err, esp_err_to_name(err));
#ifdef CONFIG_IDF_TARGET_ESP32S3
        temp_sensor_stop();
#endif
        return err;
    }
    temp_metrics_enabled = true;
    return ESP_OK;
}
I do custom_metric init and call `temperature_metrics_dump` thereafter. Hope this is useful.

MattiaBerton
Posts: 36
Joined: Thu Aug 30, 2018 8:16 am

Re: ESp-insights not working properly

Postby MattiaBerton » Fri Nov 11, 2022 11:39 am

Hello ESP_Vikram,
thank you for your prompt anwer. I tried to replicate the minimal_example, and it indeed works without any problems. Probably I didn't set anything in my configuration. I will try to replicate the setting, so I can use the Insights in my own firmware.

amitgohel
Posts: 2
Joined: Sat Dec 31, 2022 1:14 pm

Re: ESp-insights not working properly

Postby amitgohel » Sat Dec 31, 2022 1:42 pm

I am facing issue in bulding the example code and run.
It would be appreciated if anyone can help me through step by step guide to run the esp-insight code.
I am little new to ESP eco system,any help would be appreciated.

munjal
Posts: 1
Joined: Tue Jan 17, 2023 8:55 am

Re: ESp-insights not working properly

Postby munjal » Tue Jan 17, 2023 1:18 pm

amitgohel wrote:
Sat Dec 31, 2022 1:42 pm
I am facing issue in bulding the example code and run.
It would be appreciated if anyone can help me through step by step guide to run the esp-insight code.
I am little new to ESP eco system,any help would be appreciated.
Same here I am also facing issues in building the example code and run.

Who is online

Users browsing this forum: No registered users and 333 guests