trying to undo osc

master
louisa 1 year ago
parent 28dd8fc7d1
commit bb65bd6150

@ -1,53 +1,48 @@
const osc = require('osc-min'); var http = require('http');
const dgram = require('dgram'); var fs = require('fs');
var express = require('express');
const oscHost = '127.0.0.1'; // IP address of the OSC destination var app = express();
const oscPort = 8080; // Port number of the OSC destination var path = require('path');
var server = http.createServer(app);
// Function to send the OSC message var port = 8000;
function sendOSCMessage() { // const osc = require('osc');
// Create the OSC message
const oscMessage = osc.toBuffer({ const { SerialPort } = require('serialport')
address: '/blink', const { ReadlineParser } = require('@serialport/parser-readline')
args: [1] const sport = new SerialPort({ path: '/dev/ttyACM0', baudRate: 115200 })
});
// Create a UDP socket
const udpSocket = dgram.createSocket('udp4');
// Send the OSC message const parser = sport.pipe(new ReadlineParser({ delimiter: '\r\n' }))
udpSocket.send(oscMessage, 0, oscMessage.length, oscPort, oscHost, (err) => {
if (err) {
console.error('Error sending OSC message:', err);
} else {
console.log('OSC message sent successfully');
}
// Close the UDP socket server.listen(port, () => {
udpSocket.close(); console.log("Server is listening at port %d", port);
}); });
}
const express = require('express'); app.use(express.static(path.join(__dirname, "public")));
const app = express();
const server = require('http').createServer(app); var io = require('socket.io')(server);
const io = require('socket.io')(server);
// Handle socket.io events io.on('connection', function(socket) {
io.on('connection', (socket) => { console.log("A client connected!");
console.log('A client connected!');
socket.on('blink', () => { parser.on('data', function(data) {
console.log('Blink event received!'); const msg = data.split(' ');
sendOSCMessage(); // Send the OSC message when the 'blink' event is received console.log(msg[0], msg[1]);
io.emit('blink'); // Emit the 'blink' event to all connected clients io.emit('node-data', data);
}); });
// Add other event handlers here... socket.on("blink", () => {
console.log("Blink event received!");
io.emit("blink"); // Emit the "blink" event to all connected clients
});
socket.on('chat message', (msg) => {
console.log('[user][' + socket.id + '][' + msg + ']');
});
socket.on('userposition', (msg) => {
console.log('[user][' + socket.id + '][position: ' + msg[0] + ',' + msg[1] + ']');
socket.to('expo').emit(socket.id, msg);
}); });
const port = 3000; // Specify your desired port number
server.listen(port, () => {
console.log(`Server is running on port ${port}`);
}); });

@ -0,0 +1,32 @@
// const osc = require('osc-min');
// const dgram = require('dgram');
// const oscHost = '192.168.2.1'; // IP address of the OSC destination
// const oscPort = 8080; // Port number of the OSC destination
// // Function to send the OSC message
// function sendOSCMessage() {
// // Create the OSC message
// const oscMessage = osc.toBuffer({
// address: '/blink',
// args: [1]
// });
// // Create a UDP socket
// const udpSocket = dgram.createSocket('udp4');
// // Send the OSC message
// udpSocket.send(oscMessage, 0, oscMessage.length, oscPort, oscHost, (err) => {
// if (err) {
// console.error('Error sending OSC message:', err);
// } else {
// console.log('OSC message sent successfully');
// }
// // Close the UDP socket
// udpSocket.close();
// });
// }
// // Call the function to send the OSC message
// sendOSCMessage();
Loading…
Cancel
Save