Took 1 hour 17 minutes
This commit is contained in:
2023-01-30 11:40:11 +01:00
parent 8f3e62f70e
commit 3e1d88a0e5
13 changed files with 92 additions and 41 deletions

View File

@ -13,6 +13,7 @@ import {IJob} from "../../database/IJob";
import {SensorHelper} from "../../SensorHelper";
import {IContainer} from "../../database/IContainer";
import {Mixer} from "../../Mixer";
import {ArduinoProxy} from "../../ArduinoProxy";
const express = require('express');
const router = express.Router();
@ -168,32 +169,44 @@ router.ws('/', async (ws, req, next) => {
"ambient_color": string
}
await SensorHelper.clearAllRawMeasurements();
let content: { error: boolean, msg: string } = {
error: false,
msg: ""
let content: { success: boolean, msg: string } = {
success: true,
msg: "Prüfung erfolgreich."
};
// Check config
/// Check Proxy
if (Settings.get("arduino_proxy_enabled") == true) {
if (conf["arduino_proxy_enabled"]) {
try {
await ArduinoProxy.connect();
} catch (e) {
content.success = false;
content.msg = "Bei der Kommunikation mit dem Arduino Proxy ist ein Fehler aufgetreten.<br>Technische Details: " + e;
return WebSocketHandler.answerRequest(msg.data["type"] as RequestType, content);
}
}
// Check measurements
await SensorHelper.measureAllRaw();
try {
await SensorHelper.measureAllRaw();
} catch (e) {
content.success = false;
content.msg = e + "<br>Überprüfe die Einstellungen der Sensoren-Pins.";
return WebSocketHandler.answerRequest(msg.data["type"] as RequestType, content);
}
for (let c of await Container.find()) {
if (c.sensorType != SensorType.NONE && c.rawData == -1) {
content.error = true;
content.success = false;
content.msg = "Container " + (c.slot + 1) + " weist Fehler im Sensor auf.<br>Überprüfe die Einstellungen der Sensoren-Pins.";
return WebSocketHandler.answerRequest(msg.data["type"] as RequestType, content);
}
}
return WebSocketHandler.answerRequest(msg.data["type"] as RequestType, content);
break;
}
case RequestType.TARE: {
@ -208,6 +221,8 @@ router.ws('/', async (ws, req, next) => {
}
}
let timeouts: NodeJS.Timer[] = [];
async function measureAndSafe() {
try {
await SensorHelper.measureAllRaw();
@ -220,13 +235,15 @@ router.ws('/', async (ws, req, next) => {
// { success: boolean, msg: string }
WebSocketHandler.answerRequest(type, {success: false, msg: e});
success = false;
for (let t of timeouts)
clearTimeout(t);
}
}
setTimeout(measureAndSafe, 500);
setTimeout(measureAndSafe, 1000);
setTimeout(measureAndSafe, 2000);
setTimeout(measureAndSafe, 3000);
timeouts.push(setTimeout(measureAndSafe, 500));
timeouts.push(setTimeout(measureAndSafe, 1000));
timeouts.push(setTimeout(measureAndSafe, 2000));
timeouts.push(setTimeout(measureAndSafe, 3000));
setTimeout(async () => {
if (success) {