-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
50 lines (32 loc) · 1.02 KB
/
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
40
41
42
43
44
45
46
47
48
var express= require('express');
var app = express();
var httpServer = require("http").createServer(app);
var five = require("johnny-five"), board,led;
var io=require('socket.io')(httpServer);
var port = 3000;
app.use(express.static(__dirname + '/public'));
app.get('/', function(req, res) {
res.sendFile(__dirname + '/public/index.html');
});
httpServer.listen(port);
console.log('Server en http://localhost:' + port);
var led;
//Conexion arduino board
var board = new five.Board();
board.on("ready", function() {
console.log('Arduino connectado');
led = new five.Led(13);
});
//conexion a socket
io.on('connection', function (socket) {
console.log(socket.id);
socket.on('led:on', function (data) {
led.on();
console.log('LED ENCENDIDO RECIBIDO');
});
socket.on('led:off', function (data) {
led.off();
console.log('LED APAGADO RECIBIDO');
});
});
console.log('Esperando Conexion');