I can't believe it was that random stack size I think at least... could be anything to be honest
79 lines
1.9 KiB
C
79 lines
1.9 KiB
C
/**
|
|
* Author: Arthur Roberts (c) 2023
|
|
*
|
|
* License: GPLv3+
|
|
*/
|
|
|
|
#include "dht22.h"
|
|
#include "esp_log.h"
|
|
#include "esp_wifi.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/projdefs.h"
|
|
#include "freertos/task.h"
|
|
#include "nvs_flash.h"
|
|
#include "portmacro.h"
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
|
|
static const char* TAG = "YASPAM";
|
|
|
|
static volatile bool run_dht = true;
|
|
static volatile bool run_pms5003 = true;
|
|
|
|
void
|
|
read_from_pms5003()
|
|
{
|
|
TickType_t xLastWakeTime;
|
|
xLastWakeTime = xTaskGetTickCount();
|
|
while (run_pms5003) {
|
|
// TODO - actually collect some data
|
|
ESP_LOGI(TAG, "Got PMS5003 data!");
|
|
vTaskDelayUntil(&xLastWakeTime,
|
|
pdMS_TO_TICKS(1000)); // TODO: make this a config check
|
|
}
|
|
}
|
|
|
|
void
|
|
read_from_dht22()
|
|
{
|
|
TickType_t xLastWakeTime;
|
|
xLastWakeTime = xTaskGetTickCount();
|
|
|
|
while (run_dht) {
|
|
// 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!");
|
|
//vTaskDelayUntil(&xLastWakeTime,
|
|
// pdMS_TO_TICKS(500)); // TODO: make this a config check
|
|
vTaskDelay(pdMS_TO_TICKS(500));
|
|
}
|
|
}
|
|
|
|
void
|
|
app_main(void)
|
|
{
|
|
esp_err_t ret = nvs_flash_init();
|
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES ||
|
|
ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
|
ret = nvs_flash_init();
|
|
}
|
|
ESP_ERROR_CHECK(ret);
|
|
|
|
xTaskCreate(read_from_dht22,
|
|
"DHT22",
|
|
4 * 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,
|
|
"PMS5003",
|
|
4 * 1024, // honestly I have _no_ idea
|
|
NULL,
|
|
5, // no idea either
|
|
NULL); // will probably change this so that I can cancel the delay
|
|
}
|