Created
June 22, 2014 19:22
-
-
Save jedahan/f7a2a0d2466064043d3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gpio = require("gpio"); | |
var gpio4 = gpio.export(4, { | |
direction: "in", | |
ready: function() { | |
console.log('gpio has been exported'); | |
} | |
}); | |
var sockets = []; | |
console.log('woohoo'); | |
var app = require('express')(); | |
var http = require('http').Server(app); | |
var io = require('socket.io')(http); | |
gpio4.on("change", function(val) { | |
console.log("CHANGE ", val); | |
for(var i = 0; i < sockets.length; i++){ | |
sockets[i].send('change', val); | |
} | |
}); | |
app.get('/', function(req, res){ | |
res.sendfile('index.html'); | |
}); | |
io.on('connection', function(socket){ | |
sockets.push(socket); | |
socket.send('hi'); | |
console.log('a user connected'); | |
}); | |
app.get('/', function(req, res){ | |
res.sendfile('index.html'); | |
}); | |
io.on('connection', function(socket){ | |
sockets.push(socket); | |
socket.send('hi'); | |
console.log('a user connected'); | |
}); | |
http.listen(3000, function(){ | |
console.log('listening on *:3000'); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment