|
|
|
var http = require('http');
|
|
|
|
var fs = require('fs');
|
|
|
|
var express = require('express');
|
|
|
|
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, () => {
|
|
|
|
console.log("Server is listening at port %d", 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) {
|
|
|
|
console.log("A client connected!");
|
|
|
|
|
|
|
|
parser.on('data', function(data) {
|
|
|
|
const msg = data.split(' ');
|
|
|
|
console.log(msg[0], msg[1]);
|
|
|
|
io.emit('node-data', data);
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|