Skip to content

Instantly share code, notes, and snippets.

@codejoust
Created April 7, 2012 22:51
Show Gist options
  • Save codejoust/2332680 to your computer and use it in GitHub Desktop.
Save codejoust/2332680 to your computer and use it in GitHub Desktop.
serial_arduino
var express = require('express'),
socketio = require('socket.io'),
app = express.createServer(),
serialport = require('serialport'),
serial_term = new serialport.SerialPort('/dev/tty.usbmodem1d11'),
sio = socketio.listen(app);
var databuf = '';
sio.sockets.on('connection', function(socket){
socket.emit('notify', {buf: databuf});
});
serial_term.on('data', function(data){
console.log(['Serial Data:',data.toString()]);
databuf += data.toString();
sio.emit('serial_dat', data.toString());
});
app.use(express.static(__dirname + '/public'));
app.use(express.logger());
process.on('SIGINT', function(){
console.log('Closing Serial Port');
serial_term.close();
});
app.listen(3343);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment