-
Notifications
You must be signed in to change notification settings - Fork 0
/
remote.js
34 lines (29 loc) · 905 Bytes
/
remote.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
var io = require('socket.io').listen(8001),
LightArray = require('./lib/lightarray'),
mdns = require('mdns'),
exec = require('child_process').exec,
RPiGPIO = require('./lib/rpi-gpio');
var lightArray = new LightArray({
'serialPort': '/dev/ttyACM0',
'debug': false,
'sockets': {},
'device': 'arduino'
});
var rPi = new RPiGPIO();
var ad;
lightArray.on('ready', function(){
rPi.setup();
io.sockets.on('connection', function (socket) {
rPi.writeLed2(0);
console.log('connection from host');
socket.on('updateAll', function (data) {
lightArray.writeToArduino(data.values);
});
socket.on('disconnect', function(){
rPi.writeLed2(1);
});
});
ad = mdns.createAdvertisement(new mdns.ServiceType('lightarray', 'tcp'), 8001);
ad.start();
console.log('remote listening on 8001');
});