Created
October 31, 2014 05:21
-
-
Save jhoughjr/5e6a2ed6d308e56779d4 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 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