Skip to content

Instantly share code, notes, and snippets.

@jhoughjr
Created October 31, 2014 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhoughjr/5e6a2ed6d308e56779d4 to your computer and use it in GitHub Desktop.
Save jhoughjr/5e6a2ed6d308e56779d4 to your computer and use it in GitHub Desktop.
var app = require('http').createServer(handler);
var io = require('socket.io').listen(app);
var fs = require('fs');
var bb = require('bonescript');
var htmlpage = '../html/diag.html';
app.listen(8080);
function handler(req, res){
fs.readFile(htmlPage,
function (err, data){
if(err) {
res.writeHead(500);
return res.end('Error loading file : ' + htmlpage);
}
res.writeHead(200);
res.end(data);
});
}
function onConnect() {
socket.on('digitalWrite', handleDigitalWrite);
}
function handleDigitalWrite() {
var data = JSON.parse(message);
bb.pinMode(data.pin, bb.OUTPUT);
bb.digitalWrite(data.pin, data.value);
}
io.sockets.on('connect', onConnect);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment