feat: enqueueing of moisture sensor

This commit is contained in:
Elias Renman
2023-06-17 13:27:26 +02:00
parent 05da42f29f
commit d9cdcfa7f4

View File

@@ -1,18 +1,28 @@
// import Queue from "queue";
import Queue from "queue";
import { Prisma } from "@prisma/client";
import { iotClient } from "../axios/iot.axios";
import { MositureRow } from "../cron";
import { config } from "../config";
const queue = new Queue({ results: [] });
queue.start().then((result) => console.log("Successfully started queue"));
// const q = new Queue({ results: [] });
export function checkReadingAndEnqueue(rows: MositureRow[]) {
// Read config for threshold values
// Conclude which sensors need watering.
// Enqueue relevant
rows.forEach((row) => {
// Read config for threshold values
const threshold = config.config.moisture.thresholds.lower[row.name];
// Conclude which sensors need watering.
if (row.value.toNumber() >= threshold) {
console.log(`Enqueing ${row.name}`);
// Enqueue relevant sensors
queue.push(() => process(row));
}
});
}
function enqueue() {}
function process() {
function process(row: MositureRow) {
console.log("Started processing of", row.name);
// Enable water gate
// Check moisture level once per second for configured time
// If the moisture level does not increase a significant amount trigger water-empty alarm and clear queue