|
|
|
@ -11,7 +11,6 @@ const { ReadlineParser } = require('@serialport/parser-readline')
|
|
|
|
|
const sport = new SerialPort({ path: '/dev/ttyACM0', baudRate: 115200 })
|
|
|
|
|
|
|
|
|
|
const parser = sport.pipe(new ReadlineParser({ delimiter: '\r\n' }))
|
|
|
|
|
//parser.on('data', console.log)
|
|
|
|
|
|
|
|
|
|
server.listen(port, () => {
|
|
|
|
|
console.log("Server is listening at port %d", port);
|
|
|
|
@ -19,14 +18,11 @@ server.listen(port, () => {
|
|
|
|
|
|
|
|
|
|
app.use(express.static(path.join(__dirname, "public")));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var io = require('socket.io')(server);
|
|
|
|
|
|
|
|
|
|
//here we are listening to the data coming in from the modules, it's called node-data in the html
|
|
|
|
|
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]);
|
|
|
|
@ -37,13 +33,6 @@ var io = require('socket.io')(server);
|
|
|
|
|
console.log("Blink event received!");
|
|
|
|
|
io.emit("blink"); // Emit the "blink" event to all connected clients
|
|
|
|
|
});
|
|
|
|
|
// socket.on("message", (message) => {
|
|
|
|
|
// console.log("Received message:", message);
|
|
|
|
|
// if (message === "blink") {
|
|
|
|
|
// console.log("Blink event received!");
|
|
|
|
|
// io.emit("blink"); // Trigger the blink event to all connected clients
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
socket.on('chat message', (msg) => {
|
|
|
|
|
console.log('[user][' + socket.id + '][' + msg + ']');
|
|
|
|
@ -54,6 +43,4 @@ var io = require('socket.io')(server);
|
|
|
|
|
socket.to('expo').emit(socket.id, msg);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|