fix pumps

Took 23 minutes
This commit is contained in:
Tobias Hopp 2022-11-28 13:48:51 +01:00
parent b5704f4359
commit f8aa27c4ca
4 changed files with 25 additions and 5 deletions

View File

@ -1,4 +1,6 @@
import GPIO from "rpi-gpio";
import Container from "./database/Container";
import {IContainer} from "./database/IContainer";
export class MyGPIO {
static setup(pin: number, direction): Promise<void> {
@ -16,8 +18,7 @@ export class MyGPIO {
static write(pin: number, state: boolean): Promise<void> {
return new Promise((resolve, reject) => {
GPIO.write(pin, state, (err) => {
if(err)
{
if (err) {
reject();
return;
}
@ -25,4 +26,19 @@ export class MyGPIO {
});
});
}
static setupPins() : Promise<void> {
return new Promise(async resolve => {
let containers = await Container.find({}) as IContainer[];
for (let c of containers) {
if (c.sensorType) {
await MyGPIO.setup(c.sensorPin1, GPIO.DIR_IN);
await MyGPIO.setup(c.sensorPin2, GPIO.DIR_IN);
}
await MyGPIO.setup(c.pumpPin, GPIO.DIR_OUT);
await MyGPIO.write(c.pumpPin, false);
}
resolve();
});
}
}

View File

@ -39,6 +39,7 @@ export class WebSocketHandler {
public static answerRequest(type: RequestType, content: any) {
WebSocketHandler.send(new WebSocketPayload(WebSocketEvent.RESPONSE, false, {type: type, content: content}));
log("Answered " + type + " request");
}

View File

@ -7,6 +7,7 @@ import {iTenderStatus} from "./iTenderStatus";
import {Utils} from "./Utils";
import {Settings} from "./Settings";
import Drink from "./database/Drink";
import {MyGPIO} from "./MyGPIO";
const log = debug("itender:server");
@ -60,6 +61,7 @@ function init(): Promise<void> {
return new Promise(async resolve => {
log("Initializing...");
await MyGPIO.setupPins();
setTimeout(async () => {
// Network
await iTender.checkNetwork();

View File

@ -117,6 +117,7 @@ router.ws('/', async (ws, req, next) => {
}
case WebSocketEvent.REQUEST: {
log("Request to " + msg.data["type"]);
switch (msg.data["type"] as RequestType) {
case RequestType.STATS: {