From 71d04271dbbcf9e67a05ffd4d71c8fc5d75ae1d9 Mon Sep 17 00:00:00 2001 From: ChK Date: Fri, 3 Apr 2026 18:40:55 +0200 Subject: [PATCH] port konfigurierbar --- .vscode/launch.json | 16 +++++++++ logs/pings.log | 10 ++++++ startRobot.js | 15 +++++--- test/WSDriver_ReceiveMsg.test.js | 60 ++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 test/WSDriver_ReceiveMsg.test.js diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..80294af --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Attach appRobotDriver (Docker)", + "type": "node", + "request": "attach", + "address": "localhost", + "port": 2081, + "localRoot": "${workspaceFolder}", + "remoteRoot": "/usr/src/app", + "restart": true, + "timeout": 10000 + } + ] +} \ No newline at end of file diff --git a/logs/pings.log b/logs/pings.log index 9bede1a..c68b7ba 100644 --- a/logs/pings.log +++ b/logs/pings.log @@ -212,3 +212,13 @@ 2026-04-01T16:09:27.471Z ::ffff:172.21.0.6: Ping 2026-04-01T16:09:32.477Z ::ffff:172.21.0.6: Ping 2026-04-01T16:09:37.480Z ::ffff:172.21.0.6: Ping +2026-04-03T16:38:27.971Z ::ffff:172.21.0.9: Ping +2026-04-03T16:38:32.978Z ::ffff:172.21.0.9: Ping +2026-04-03T16:38:37.980Z ::ffff:172.21.0.9: Ping +2026-04-03T16:38:42.965Z ::ffff:172.21.0.9: Ping +2026-04-03T16:38:47.973Z ::ffff:172.21.0.9: Ping +2026-04-03T16:38:52.968Z ::ffff:172.21.0.9: Ping +2026-04-03T16:39:19.994Z ::ffff:172.21.0.9: Ping +2026-04-03T16:39:19.995Z ::ffff:172.21.0.9: Ping +2026-04-03T16:40:19.977Z ::ffff:172.21.0.9: Ping +2026-04-03T16:40:19.980Z ::ffff:172.21.0.9: Ping diff --git a/startRobot.js b/startRobot.js index be98288..c253293 100755 --- a/startRobot.js +++ b/startRobot.js @@ -144,8 +144,11 @@ setTimeout(function(){ console.log("Works with FluidNc Base"); -port = 2095 -server.listen(port); + +const port = Number(process.env.PORT); +const listenPort = Number.isInteger(port) ? port : 2095; + +server.listen(listenPort); console.log("Listen on Port: https://localhost:" + port.toString()+ "/") @@ -192,5 +195,9 @@ const infoServer = https.createServer(httpsOptions, (req, res) => { } }); -infoServer.listen(2098); -console.log("Info server listening on https://localhost:2098/"); + +const InfPort = Number(process.env.PORT); +const listenInfoPort = Number.isInteger(InfPort) ? InfPort : 2095; + +infoServer.listen(listenInfoPort); +console.log("Info server listening on https://localhost:"+ listenInfoPort.toString() + "/"); diff --git a/test/WSDriver_ReceiveMsg.test.js b/test/WSDriver_ReceiveMsg.test.js new file mode 100644 index 0000000..323d751 --- /dev/null +++ b/test/WSDriver_ReceiveMsg.test.js @@ -0,0 +1,60 @@ +const WebSocket = require('ws'); + +const TEST_URL = "wss://localhost:2095"; + +describe("WebSocket Verbindung (appRobot_Driver)", () => { + + let ws; + + beforeAll((done) => { + // self-signed cert ignorieren (wichtig!) + process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; + + ws = new WebSocket(TEST_URL); + + ws.on('open', () => { + done(); + }); + + ws.on('error', (err) => { + done(err); + }); + }); + + afterAll(() => { + if (ws) ws.close(); + }); + + test("Ping → sollte Antwort bekommen", (done) => { + + ws.on('message', (data) => { + const msg = data.toString(); + + try { + expect(msg).toBe("Ping"); + done(); + } catch (err) { + done(err); + } + }); + + ws.send("Ping"); + }); + + test("GCode senden → sollte Antwort liefern", (done) => { + + ws.on('message', (data) => { + const msg = data.toString(); + + try { + expect(msg).toContain("X"); // M114 response enthält Positionsdaten + done(); + } catch (err) { + done(err); + } + }); + + ws.send("G1 X10 F100"); +}); + +}); \ No newline at end of file