I think I've got something working
I can't believe it was that random stack size I think at least... could be anything to be honest
This commit is contained in:
124
main/main.c
124
main/main.c
@@ -4,138 +4,74 @@
|
|||||||
* License: GPLv3+
|
* License: GPLv3+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/projdefs.h"
|
|
||||||
#include "freertos/projdefs.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"
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/projdefs.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
#include "nvs_flash.h"
|
#include "nvs_flash.h"
|
||||||
|
#include "portmacro.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
static const char *TAG = "YASPAM";
|
static const char* TAG = "YASPAM";
|
||||||
|
|
||||||
static EventGroupHandle_t s_monitor_event_group;
|
|
||||||
|
|
||||||
static volatile bool run_dht = true;
|
static volatile bool run_dht = true;
|
||||||
static volatile bool run_pms5003 = true;
|
static volatile bool run_pms5003 = true;
|
||||||
static volatile bool run_data_collection = true;
|
|
||||||
|
|
||||||
#ifdef CONFIG_DHT22_DATA_GPIO
|
void
|
||||||
#define SENSOR_DHT22_BIT (1 << 0)
|
read_from_pms5003()
|
||||||
#else
|
{
|
||||||
#define SENSOR_DHT22_BIT 0
|
|
||||||
#endif /* CONFIG_DHT22_DATA_GPIO */
|
|
||||||
|
|
||||||
#ifdef CONFIG_PMS5003_ENABLED
|
|
||||||
#define SENSOR_PMS5003_BIT (1 << 1)
|
|
||||||
#else
|
|
||||||
#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() {
|
|
||||||
TickType_t xLastWakeTime;
|
TickType_t xLastWakeTime;
|
||||||
xLastWakeTime = xTaskGetTickCount ();
|
xLastWakeTime = xTaskGetTickCount();
|
||||||
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");
|
|
||||||
xEventGroupClearBitsFromISR(s_monitor_event_group, SENSOR_DHT22_BIT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bits & SENSOR_PMS5003_BIT) {
|
|
||||||
ESP_LOGI(TAG, "Saved PMS data");
|
|
||||||
// TODO
|
|
||||||
xEventGroupClearBitsFromISR(s_monitor_event_group, SENSOR_PMS5003_BIT);
|
|
||||||
}
|
|
||||||
vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(100));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void read_from_pms5003() {
|
|
||||||
BaseType_t xHigherPriorityTaskWoken, xResult;
|
|
||||||
xHigherPriorityTaskWoken = pdFALSE;
|
|
||||||
TickType_t xLastWakeTime;
|
|
||||||
xLastWakeTime = xTaskGetTickCount ();
|
|
||||||
while (run_pms5003) {
|
while (run_pms5003) {
|
||||||
// TODO - actually collect some data
|
// TODO - actually collect some data
|
||||||
ESP_LOGI(TAG, "Got PMS5003 data! Setting PMS bit now!");
|
ESP_LOGI(TAG, "Got PMS5003 data!");
|
||||||
xResult = xEventGroupSetBitsFromISR(s_monitor_event_group, SENSOR_PMS5003_BIT, &xHigherPriorityTaskWoken);
|
vTaskDelayUntil(&xLastWakeTime,
|
||||||
if (xResult) {
|
pdMS_TO_TICKS(1000)); // TODO: make this a config check
|
||||||
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
|
|
||||||
}
|
|
||||||
vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(1000)); // TODO: make this a config check
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_from_dht22() {
|
void
|
||||||
BaseType_t xHigherPriorityTaskWoken, xResult;
|
read_from_dht22()
|
||||||
xHigherPriorityTaskWoken = pdFALSE;
|
{
|
||||||
TickType_t xLastWakeTime;
|
TickType_t xLastWakeTime;
|
||||||
xLastWakeTime = xTaskGetTickCount ();
|
xLastWakeTime = xTaskGetTickCount();
|
||||||
|
|
||||||
while (run_dht) {
|
while (run_dht) {
|
||||||
// Data reading is based on time, so need to block interrups etc
|
// Data reading is based on time, so need to block interrups etc
|
||||||
portDISABLE_INTERRUPTS();
|
portDISABLE_INTERRUPTS();
|
||||||
int ret = dht22_read();
|
int ret = dht22_read();
|
||||||
portENABLE_INTERRUPTS();
|
portENABLE_INTERRUPTS();
|
||||||
ESP_LOGI(TAG, "Got DHT22 data! Setting DHT bit now!");
|
ESP_LOGI(TAG, "Got DHT22 data!");
|
||||||
xResult = xEventGroupSetBitsFromISR(s_monitor_event_group, SENSOR_DHT22_BIT, &xHigherPriorityTaskWoken);
|
//vTaskDelayUntil(&xLastWakeTime,
|
||||||
if (xResult) {
|
// pdMS_TO_TICKS(500)); // TODO: make this a config check
|
||||||
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
|
vTaskDelay(pdMS_TO_TICKS(500));
|
||||||
}
|
|
||||||
ESP_LOGI(TAG, "Hello");
|
|
||||||
vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(500)); // TODO: make this a config check
|
|
||||||
ESP_LOGI(TAG, "hello1");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
void app_main(void) {
|
app_main(void)
|
||||||
|
{
|
||||||
esp_err_t ret = nvs_flash_init();
|
esp_err_t ret = nvs_flash_init();
|
||||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES ||
|
||||||
|
ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||||
ret = nvs_flash_init();
|
ret = nvs_flash_init();
|
||||||
}
|
}
|
||||||
ESP_ERROR_CHECK(ret);
|
ESP_ERROR_CHECK(ret);
|
||||||
|
|
||||||
s_monitor_event_group = xEventGroupCreate();
|
|
||||||
|
|
||||||
xTaskCreate(read_from_dht22,
|
xTaskCreate(read_from_dht22,
|
||||||
"DHT22",
|
"DHT22",
|
||||||
1024, // honestly I have _no_ idea
|
4 * 1024, // honestly I have _no_ idea
|
||||||
NULL,
|
NULL,
|
||||||
5, // no idea either
|
5, // no idea either
|
||||||
NULL); // will probably change this so that I can cancel the delay
|
NULL); // will probably change this so that I can cancel the delay
|
||||||
|
|
||||||
xTaskCreate(read_from_pms5003,
|
xTaskCreate(read_from_pms5003,
|
||||||
"PMS5003",
|
"PMS5003",
|
||||||
1024, // honestly I have _no_ idea
|
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(save_measurements,
|
|
||||||
"save_measurements",
|
|
||||||
4*1024, // honestly I have _no_ idea
|
|
||||||
NULL,
|
NULL,
|
||||||
5, // no idea either
|
5, // no idea either
|
||||||
NULL); // will probably change this so that I can cancel the delay
|
NULL); // will probably change this so that I can cancel the delay
|
||||||
|
|||||||
Reference in New Issue
Block a user