-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
65 lines (41 loc) · 1.39 KB
/
Copy pathindex.js
File metadata and controls
65 lines (41 loc) · 1.39 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var express = require('express');
var app = express();
var httpServer = require("http").createServer(app);
var five = require("johnny-five");
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 available at http://localhost:' + port);
var led;
//Arduino board connection
var board = new five.Board();
board.on("ready", function() {
console.log('Arduino connected');
//led = new five.Led(2);
var temperature = new five.Thermometer({
controller: "LM35",
pin: "A0"
});
//Socket connection handler
io.on('connection', function (socket) {
temperature.on("data", function() {
var currTemp = {"celsius":this.celsius,"fahrenheit": this.fahrenheit}
socket.emit('data', currTemp);
//console.log(this.celsius + "°C", this.fahrenheit + "°F");
});
console.log(socket.id);
/* socket.on('led:on', function (data) {
led.on();
console.log('LED ON RECEIVED');
});
socket.on('led:off', function (data) {
led.off();
console.log('LED OFF RECEIVED');
});*/
});
});
console.log('Waiting for connection');