Created
June 22, 2014 19:50
-
-
Save jedahan/5ca1e7602504a7ad6e7a 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
<style> | |
body { background: #333355; } | |
body.connected { background: #620042; } | |
</style> | |
<script src="/socket.io/socket.io.js"></script> | |
<body> | |
<script> | |
var socket = io(); | |
socket.on('change', function(val){ | |
console.log('change ', val); | |
console.log('we got a change event'); | |
if(val===1){ | |
document.getElementsByTagName('body')[0].style.backgroundColor="#336633"; | |
} else { | |
document.getElementsByTagName('body')[0].style.backgroundColor="#ff00ff"; | |
} | |
}); | |
</script> | |
</body> |
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].emit('change',val); | |
} | |
}); | |
app.get('/', function(req, res){ | |
res.sendfile('index.html'); | |
}); | |
io.on('connection', function(socket){ | |
socket.on('hi',function(val){ | |
console.log(val); | |
}); | |
sockets.push(socket); | |
console.log('a user connected'); | |
socket.emit('hi','world'); | |
}); | |
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