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
sp.on('close', function (err) { | |
console.log('port closed'); | |
}); | |
sp.on('error', function (err) { | |
console.error("error", err); | |
}); | |
sp.on('open', function () { | |
console.log('port opened...'); |
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
sp.on('data', function (data) { | |
console.log(data); | |
data = data.toString(); | |
socket.emit('receiveSerial', data); | |
}); |
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
socket.on('sendSerial', function(data) { | |
console.log("Client sent us: " + data + "to send to serial"); | |
sp.write(mbBuffer, function (err, bytesWritten) { | |
console.log('bytes written:', bytesWritten); | |
}); |
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 socket = io.connect('http://your ip address here..'); | |
socket.on('connected', function(data) { | |
console.log('Connected, this is what I received : ', data); | |
//you could then emit something here for the server to receive like socket.emit("blah", "helloworld") -hello world is a string of data you are passing the sever here.. | |
}); |
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
/* | |
* GET home page. | |
*/ | |
var fs = require('fs') | |
exports.index = function(req, res){ | |
res.writeHead(200, {'Content-Type': 'text/html'}); | |
var contents = fs.readFileSync("./public/index.html", "UTF-8"); | |
res.end(contents); | |
// res.render('index'); |
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
io.sockets.on('connection', function(socket){ | |
console.log("Socket connected"); | |
socket.emit('connected', 123); |
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
io.sockets.on('connection', function(socket){ | |
console.log("Socket connected"); | |
socket.emit('connected', 123);</pre> |
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
/** | |
* Server Code | |
*/ | |
var server = http.createServer(app).listen(app.get('port'), function(){ | |
console.log("Express server listening on port " + app.get('port')); | |
}); | |
var io = require('socket.io').listen(server); |
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
serialport = require("serialport").SerialPort; |
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
/** | |
* Serial Port Setup. | |
*/ | |
var portName = '/dev/ttyAMA0'; //This is the standard Raspberry Pi Serial port | |
var readData = ''; //Array to hold the values read in from the port | |
var sp = new serialport(portName, { | |
baudRate: 9600, |