diff --git a/src/ArduinoProxy.ts b/src/ArduinoProxy.ts index b4fc67b..d9ce88c 100644 --- a/src/ArduinoProxy.ts +++ b/src/ArduinoProxy.ts @@ -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(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)"); diff --git a/src/RequestType.ts b/src/RequestType.ts index 08f507f..19f3de6 100644 --- a/src/RequestType.ts +++ b/src/RequestType.ts @@ -8,4 +8,5 @@ export enum RequestType { DOWNLOAD_DRINKS = "DOWNLOAD_DRINKS", TARE = "TARE", CHECK = "CHECK", + UPDATE = "UPDATE", } \ No newline at end of file diff --git a/src/routes/ws/websocketRoute.ts b/src/routes/ws/websocketRoute.ts index 75c4cd2..25e54a5 100644 --- a/src/routes/ws/websocketRoute.ts +++ b/src/routes/ws/websocketRoute.ts @@ -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.
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; } diff --git a/src/web/Setup.ts b/src/web/Setup.ts index 49430c2..1d831ac 100644 --- a/src/web/Setup.ts +++ b/src/web/Setup.ts @@ -203,8 +203,8 @@ Dort werden die Behälter definiert, welche in den iTender gestellt werden.
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!
${answer.data["msg"]}`; await errorModal.open(); return; diff --git a/src/web/WebWebSocketHandler.ts b/src/web/WebWebSocketHandler.ts index b454d46..3cd4b39 100644 --- a/src/web/WebWebSocketHandler.ts +++ b/src/web/WebWebSocketHandler.ts @@ -224,7 +224,7 @@ export class WebWebSocketHandler { }); WebWebSocketHandler.send(new WebSocketPayload(WebSocketEvent.REQUEST, { type: type, - content: content + data: content })); }); }