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