From e0383376f63810dd88ef73a7a14bab2ee5c259ff Mon Sep 17 00:00:00 2001 From: louisa Date: Thu, 15 Jun 2023 15:31:52 +0200 Subject: [PATCH] osc in node.js --- app.js | 23 +++++++++++++++++++++++ public/index.html | 1 + 2 files changed, 24 insertions(+) diff --git a/app.js b/app.js index e35ca4e..d295f55 100644 --- a/app.js +++ b/app.js @@ -5,11 +5,28 @@ var app = express(); var path = require('path'); var server = http.createServer(app); var port = 8000; +const osc = require('osc'); const { SerialPort } = require('serialport') const { ReadlineParser } = require('@serialport/parser-readline') const sport = new SerialPort({ path: '/dev/ttyACM0', baudRate: 115200 }) + +// Create an OSC server and specify the port +const oscPort = new osc.UDPPort({ + localAddress: '0.0.0.0', // Listen on all network interfaces + localPort: 8080 // Specify your desired OSC port number +}); + +// Start the OSC server +oscPort.open(); + +// Handle incoming OSC messages +oscPort.on('message', (oscMessage) => { + console.log('Received OSC message:', oscMessage); + // Handle the OSC message here and trigger the desired actions +}); + const parser = sport.pipe(new ReadlineParser({ delimiter: '\r\n' })) server.listen(port, () => { @@ -18,6 +35,12 @@ server.listen(port, () => { app.use(express.static(path.join(__dirname, "public"))); +// Start the HTTP server +const port = 3000; // Specify your desired HTTP port number +http.listen(port, () => { + console.log(`Server is running on port ${port}`); +}); + var io = require('socket.io')(server); io.on('connection', function(socket) { diff --git a/public/index.html b/public/index.html index 7c4eb7f..c6b5a2e 100644 --- a/public/index.html +++ b/public/index.html @@ -6,6 +6,7 @@ +