-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.js
More file actions
30 lines (27 loc) · 899 Bytes
/
run.js
File metadata and controls
30 lines (27 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Init the dependencies
const SerialPort = require('serialport')
const Readline = SerialPort.parsers.Readline
const express = require('express');
const socketio = require('socket.io');
// Setup the app and listen on the port
const app = express();
app.use(express.static(__dirname + '/public'));
const expressServer = app.listen(8082);
const io = socketio(expressServer);
//Connection of throught the SerialPort
const serialPort = new SerialPort('/dev/ttyACM0', {
baudRate: 9600
})
const parser = new Readline()
serialPort.pipe(parser)
//Simple socket.io connection
parser.on('data', function (data) {
// Here console log the received data from the hardware
console.log('data received: ' + data)
//socket emit data
io.sockets.emit('map', data);
})
// console log if the connection was established succesfully
serialPort.on('open', function () {
console.log('Communication is on!')
})