Skip to content

Instantly share code, notes, and snippets.

@w4ilun
Last active August 29, 2015 14:24
Show Gist options
  • Save w4ilun/d057a3a062967f57eb3f to your computer and use it in GitHub Desktop.
Save w4ilun/d057a3a062967f57eb3f to your computer and use it in GitHub Desktop.
var groveSensor = require('jsupm_grove'); //UPM sensor
var app = require('express')(); //Express Library
var server = require('http').Server(app); //Create HTTP instance
var io = require('socket.io')(server); //Socket.IO Library
var tempSensor = new groveSensor.GroveTemp(0); //temperature sensor connected to analog pin 0
app.get('/', function(req, res) {
res.sendfile(__dirname + '/index.html'); //serve the static html file
});
io.on('connection', function(socket){
var interval = setInterval(function(){
socket.emit('temperature', { celsius: tempSensor.value() }); //read the temperature every 500ms and send the reading
}, 500);
socket.on('disconnect', function(){
clearInterval(interval);
});
});
server.listen(3000); //run on port 3000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment