mirror of
https://github.com/eliasrenman/gardentron.git
synced 2026-03-16 20:46:07 +01:00
feat: enqueueing of moisture sensor
This commit is contained in:
@@ -1,18 +1,28 @@
|
|||||||
// import Queue from "queue";
|
import Queue from "queue";
|
||||||
|
|
||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "@prisma/client";
|
||||||
import { iotClient } from "../axios/iot.axios";
|
import { iotClient } from "../axios/iot.axios";
|
||||||
import { MositureRow } from "../cron";
|
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[]) {
|
export function checkReadingAndEnqueue(rows: MositureRow[]) {
|
||||||
// Read config for threshold values
|
rows.forEach((row) => {
|
||||||
// Conclude which sensors need watering.
|
// Read config for threshold values
|
||||||
// Enqueue relevant
|
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
|
// Enable water gate
|
||||||
// Check moisture level once per second for configured time
|
// 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
|
// If the moisture level does not increase a significant amount trigger water-empty alarm and clear queue
|
||||||
|
|||||||
Reference in New Issue
Block a user