-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·41 lines (28 loc) · 799 Bytes
/
app.js
File metadata and controls
executable file
·41 lines (28 loc) · 799 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
31
32
33
34
35
36
37
38
39
40
41
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/tty.wchusbserialfa1410',{
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('lights',function(data){
console.log( data );
port.write( data.status );
});
});
app.listen(3000);