-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
39 lines (28 loc) · 771 Bytes
/
app.js
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
31
32
33
34
35
36
37
38
39
var http = require('http');
var fs = require('fs');
var index = fs.readFileSync('index.html');
var SerialPort = require('serialport');
const parsers = SerialPort.parsers;
const parser = new parsers.Readline({
delimiter: '\r\n'
});
var port = new SerialPort('/dev/cu.usbserial-A50285BI', {
baudRate: 9600,
dataBits: 8,
parity: 'none',
stopBits: 1,
flowControl: false
});
port.pipe(parser);
var app = http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(index);
});
var io = require('socket.io').listen(app);
io.on('connection', function (socket) {
socket.on('smarties', function (data) {
console.log(data);
port.write(data.status);
});
});
app.listen(3000);