update
Took 23 minutes
This commit is contained in:
parent
37396858dd
commit
f2e629c01a
@ -1,4 +1,4 @@
|
|||||||
import SerialPort from "serialport";
|
import { SerialPort } from 'serialport'
|
||||||
import debug from "debug";
|
import debug from "debug";
|
||||||
import {ArduinoProxyPayload} from "./ArduinoProxyPayload";
|
import {ArduinoProxyPayload} from "./ArduinoProxyPayload";
|
||||||
import {Utils} from "./Utils";
|
import {Utils} from "./Utils";
|
||||||
@ -30,23 +30,26 @@ export class ArduinoProxy {
|
|||||||
|
|
||||||
public static connect() {
|
public static connect() {
|
||||||
return new Promise<void>(async (resolve, reject) => {
|
return new Promise<void>(async (resolve, reject) => {
|
||||||
// @ts-ignore
|
log("Connecting to arduino...");
|
||||||
let list = await SerialPort.list()
|
let list = await SerialPort.list();
|
||||||
|
|
||||||
let arduino = list.find((ele) => {
|
let arduino = list.find((ele) => {
|
||||||
return ele.manufacturer == "Arduino";
|
return ele.manufacturer == "Arduino";
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!arduino) {
|
if (!arduino) {
|
||||||
|
log("No arduino found!");
|
||||||
return reject("No arduino found. Is it plugged in?");
|
return reject("No arduino found. Is it plugged in?");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.serialPort = new SerialPort({
|
this.serialPort = new SerialPort({
|
||||||
path: arduino.path,
|
path: arduino.path,
|
||||||
baudRate: 9600,
|
baudRate: 9600,
|
||||||
autoOpen: false,
|
autoOpen: false,
|
||||||
});
|
});
|
||||||
|
log("Opening serial port...");
|
||||||
this.serialPort.open((err: Error | null | undefined) => {
|
this.serialPort.open((err: Error | null | undefined) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
log("Error whilst connecting to proxy (open serial-connection)");
|
log("Error whilst connecting to proxy (open serial-connection)");
|
||||||
|
@ -8,4 +8,5 @@ export enum RequestType {
|
|||||||
DOWNLOAD_DRINKS = "DOWNLOAD_DRINKS",
|
DOWNLOAD_DRINKS = "DOWNLOAD_DRINKS",
|
||||||
TARE = "TARE",
|
TARE = "TARE",
|
||||||
CHECK = "CHECK",
|
CHECK = "CHECK",
|
||||||
|
UPDATE = "UPDATE",
|
||||||
}
|
}
|
@ -160,7 +160,7 @@ router.ws('/', async (ws, req, next) => {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RequestType.CHECK: {
|
case RequestType.CHECK: {
|
||||||
let conf = msg.data as {
|
let conf = msg.data.data as {
|
||||||
"led_enabled": boolean,
|
"led_enabled": boolean,
|
||||||
"remote_enabled": boolean,
|
"remote_enabled": boolean,
|
||||||
"hotspot_enabled": boolean,
|
"hotspot_enabled": boolean,
|
||||||
@ -171,7 +171,6 @@ router.ws('/', async (ws, req, next) => {
|
|||||||
|
|
||||||
await SensorHelper.clearAllRawMeasurements();
|
await SensorHelper.clearAllRawMeasurements();
|
||||||
|
|
||||||
|
|
||||||
let content: { success: boolean, msg: string } = {
|
let content: { success: boolean, msg: string } = {
|
||||||
success: true,
|
success: true,
|
||||||
msg: "Prüfung erfolgreich."
|
msg: "Prüfung erfolgreich."
|
||||||
@ -180,9 +179,16 @@ router.ws('/', async (ws, req, next) => {
|
|||||||
// Check config
|
// Check config
|
||||||
/// Check Proxy
|
/// Check Proxy
|
||||||
if (conf["arduino_proxy_enabled"]) {
|
if (conf["arduino_proxy_enabled"]) {
|
||||||
|
try {
|
||||||
|
await ArduinoProxy.disconnect();
|
||||||
|
} catch( e )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
await ArduinoProxy.connect();
|
await ArduinoProxy.connect();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
log("Checkup failed");
|
||||||
content.success = false;
|
content.success = false;
|
||||||
content.msg = "Bei der Kommunikation mit dem Arduino Proxy ist ein Fehler aufgetreten.<br>Technische Details: " + e;
|
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);
|
return WebSocketHandler.answerRequest(msg.data["type"] as RequestType, content);
|
||||||
@ -259,6 +265,16 @@ router.ws('/', async (ws, req, next) => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case RequestType.UPDATE: {
|
||||||
|
/*
|
||||||
|
- git pull
|
||||||
|
- yarn install
|
||||||
|
- yarn run compile
|
||||||
|
- (arduino update?)
|
||||||
|
- reboot
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -203,8 +203,8 @@ Dort werden die Behälter definiert, welche in den iTender gestellt werden.<br>D
|
|||||||
|
|
||||||
// Check
|
// Check
|
||||||
let answer = await WebWebSocketHandler.request(RequestType.CHECK, newConf);
|
let answer = await WebWebSocketHandler.request(RequestType.CHECK, newConf);
|
||||||
|
console.log(answer);
|
||||||
if (!(answer.data as boolean)) {
|
if (!(answer.data["success"] as boolean)) {
|
||||||
ele.innerHTML = `Die Konfiguration weist Fehler auf!<br>${answer.data["msg"]}`;
|
ele.innerHTML = `Die Konfiguration weist Fehler auf!<br>${answer.data["msg"]}`;
|
||||||
await errorModal.open();
|
await errorModal.open();
|
||||||
return;
|
return;
|
||||||
|
@ -224,7 +224,7 @@ export class WebWebSocketHandler {
|
|||||||
});
|
});
|
||||||
WebWebSocketHandler.send(new WebSocketPayload(WebSocketEvent.REQUEST, {
|
WebWebSocketHandler.send(new WebSocketPayload(WebSocketEvent.REQUEST, {
|
||||||
type: type,
|
type: type,
|
||||||
content: content
|
data: content
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user