Created some tasks

This commit is contained in:
2023-10-25 19:18:26 +01:00
parent 5efca6b3c0
commit bef67215cb
2 changed files with 92 additions and 20 deletions

14
main/Kconfig.projbuild Normal file
View File

@@ -0,0 +1,14 @@
menu "Project Configuration"
config WIFI_SSID
string "WiFi SSID"
default "myssid"
help
Network Name (SSID) of the WIFI to connect to.
config WIFI_PASSWORD
string "WiFi PASSWORD"
default "hunter2"
help
Password of the WiFi network to connect to.
endmenu

View File

@@ -4,40 +4,98 @@
* License: GPLv3+ * License: GPLv3+
*/ */
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
//#include "freertos/projdefs.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "dht22.h" #include "dht22.h"
#include "esp_log.h" #include "esp_log.h"
#include "esp_wifi.h" #include "esp_wifi.h"
#include "portmacro.h"
static const char *TAG = "YASPAM"; static const char *TAG = "YASPAM";
struct air_monitor_data { static EventGroupHandle_t s_monitor_event_group;
static volatile bool run_dht = true;
static volatile bool run_pms5003 = true;
#ifdef CONFIG_DHT22_DATA_GPIO #ifdef CONFIG_DHT22_DATA_GPIO
deci_percent dht22_relative_humidity; #define SENSOR_DHT22_BIT (1 << 0)
deci_degrees_c dht22_temperature; #else
#define SENSOR_DHT22_BIT 0
#endif /* CONFIG_DHT22_DATA_GPIO */ #endif /* CONFIG_DHT22_DATA_GPIO */
#ifdef CONFIG_PMS5003_DATA_GPIO #ifdef CONFIG_PMS5003_ENABLED
// TODO #define SENSOR_PMS5003_BIT (1 << 1)
#endif /* CONFIG_PMS5003_DATA_GPIO */ #else
int64_t time; // TODO think about how best to store this. #define SENSOR_PMS5003_BIT 0
}; #endif /* CONFIG_PMS5003_ENABLED */
void app_main(void) #define SENSOR_ALL SENSOR_DHT22_BIT | SENSOR_PMS5003_BIT
{
#ifdef CONFIG_DHT22_DATA_GPIO
int ret = dht22_read();
#endif /* CONFIG_DHT22_DATA_GPIO */
// 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) {
for (int i = 10; i >= 0; i--) { deci_percent rh = dht22_relative_humidity();
printf("Restarting in %d seconds...\n", i); deci_degrees_c temp = dht22_temperature();
vTaskDelay(1000 / portTICK_PERIOD_MS); // TODO - think about how to actually store this somewhere (for pushing and/or pulling)
// and what sort of structures I could use
} }
printf("Restarting now.\n"); if (bits & SENSOR_PMS5003_BIT) {
fflush(stdout); // TODO
}
}
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();
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
}
}
void read_from_dht22() {
while (run_dht) {
// Data reading is based on time spent high, 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
}
}
void app_main(void) {
xTaskCreate(read_from_dht22,
"READ 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",
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(); esp_restart();
} }