fix pumps
Took 23 minutes
This commit is contained in:
parent
b5704f4359
commit
f8aa27c4ca
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
@ -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");
|
||||
|
||||
}
|
||||
|
||||
|
@ -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,15 +61,16 @@ function init(): Promise<void> {
|
||||
|
||||
return new Promise(async resolve => {
|
||||
log("Initializing...");
|
||||
setTimeout( async () => {
|
||||
await MyGPIO.setupPins();
|
||||
setTimeout(async () => {
|
||||
// Network
|
||||
await iTender.checkNetwork();
|
||||
let drinkCount = await Drink.countDocuments({});
|
||||
if (iTender.internetConnection && iTender.status == iTenderStatus.READY && drinkCount < 3 ) {
|
||||
if (iTender.internetConnection && iTender.status == iTenderStatus.READY && drinkCount < 3) {
|
||||
console.log("No drinks in the database. - Try to refresh from server...")
|
||||
await iTender.refreshFromServer();
|
||||
}
|
||||
}, 1000 * 15 ) ;
|
||||
}, 1000 * 15);
|
||||
|
||||
|
||||
// Containers
|
||||
|
@ -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: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user