From ae598ea5b9cc3159b1f504fc5110e2206f156eea Mon Sep 17 00:00:00 2001 From: Arthur Roberts Date: Wed, 25 Oct 2023 19:50:10 +0100 Subject: [PATCH] Issues with stack traces when 3 tasks running I think it could be with ISR... maybe? I'm not 100% what an interrupt actually realy is --- main/main.c | 67 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/main/main.c b/main/main.c index de8cb8c..0bd70db 100644 --- a/main/main.c +++ b/main/main.c @@ -20,6 +20,7 @@ static EventGroupHandle_t s_monitor_event_group; static volatile bool run_dht = true; static volatile bool run_pms5003 = true; +static volatile bool run_data_collection = true; #ifdef CONFIG_DHT22_DATA_GPIO #define SENSOR_DHT22_BIT (1 << 0) @@ -33,69 +34,79 @@ static volatile bool run_pms5003 = true; #define SENSOR_PMS5003_BIT 0 #endif /* CONFIG_PMS5003_ENABLED */ +#define SENSOR_PMS5003_BIT (1 << 1) + #define SENSOR_ALL SENSOR_DHT22_BIT | SENSOR_PMS5003_BIT // TODO - figure out how to continually call this, maybe make a task for it? void save_measurements() { - EventBits_t bits = xEventGroupWaitBits( - s_monitor_event_group, - SENSOR_ALL, - pdFALSE, - pdFALSE, - portMAX_DELAY); - if (bits & SENSOR_DHT22_BIT) { - - deci_percent rh = dht22_relative_humidity(); - deci_degrees_c temp = dht22_temperature(); - // TODO - think about how to actually store this somewhere (for pushing and/or pulling) - // and what sort of structures I could use - } - if (bits & SENSOR_PMS5003_BIT) { - // TODO + while (run_data_collection) { + EventBits_t bits = xEventGroupWaitBits( + s_monitor_event_group, + SENSOR_ALL, + pdFALSE, + pdFALSE, + portMAX_DELAY); + if (bits & SENSOR_DHT22_BIT) { + deci_percent rh = dht22_relative_humidity(); + deci_degrees_c temp = dht22_temperature(); + // TODO - think about how to actually store this somewhere (for pushing and/or pulling) + // and what sort of structures I could use + ESP_LOGI(TAG, "Saved DHT data"); + xEventGroupClearBits(s_monitor_event_group, SENSOR_DHT22_BIT); + } + if (bits & SENSOR_PMS5003_BIT) { + ESP_LOGI(TAG, "Saved PMS data"); + // TODO + xEventGroupClearBits(s_monitor_event_group, SENSOR_PMS5003_BIT); + } } } void read_from_pms5003() { while (run_pms5003) { - // Data reading is based on time spent high, so need to block interrups etc - portDISABLE_INTERRUPTS(); - //int ret = pms5003_read(); - portENABLE_INTERRUPTS(); + // TODO - actually collect some data ESP_LOGI(TAG, "Got PMS5003 data! Setting PMS bit now!"); - xEventGroupSetBits(s_monitor_event_group, SENSOR_DHT22_BIT); - vTaskDelay(pdMS_TO_TICKS(1000)); // TODO: make this a config check + xEventGroupSetBitsFromISR(s_monitor_event_group, SENSOR_PMS5003_BIT); + vTaskDelay(pdMS_TO_TICKS(100)); // TODO: make this a config check } } void read_from_dht22() { while (run_dht) { - // Data reading is based on time spent high, so need to block interrups etc + // Data reading is based on time, so need to block interrups etc portDISABLE_INTERRUPTS(); int ret = dht22_read(); portENABLE_INTERRUPTS(); ESP_LOGI(TAG, "Got DHT22 data! Setting DHT bit now!"); - xEventGroupSetBits(s_monitor_event_group, SENSOR_DHT22_BIT); - vTaskDelay(pdMS_TO_TICKS(2000)); // TODO: make this a config check + xEventGroupSetBitsFromISR(s_monitor_event_group, SENSOR_DHT22_BIT); + vTaskDelay(pdMS_TO_TICKS(3000)); // TODO: make this a config check } } void app_main(void) { + s_monitor_event_group = xEventGroupCreate(); + xTaskCreate(read_from_dht22, - "READ DHT22", + "DHT22", 1024, // honestly I have _no_ idea NULL, 5, // no idea either NULL); // will probably change this so that I can cancel the delay xTaskCreate(read_from_pms5003, - "READ PMS5003", + "PMS5003", 1024, // honestly I have _no_ idea NULL, 5, // no idea either NULL); // will probably change this so that I can cancel the delay - - esp_restart(); + xTaskCreate(save_measurements, + "save_measurements", + 4*1024, // honestly I have _no_ idea + NULL, + 5, // no idea either + NULL); // will probably change this so that I can cancel the delay }