Skip to content

Instantly share code, notes, and snippets.

@techninja
Created December 7, 2013 18:23
Show Gist options
  • Save techninja/7846575 to your computer and use it in GitHub Desktop.
Save techninja/7846575 to your computer and use it in GitHub Desktop.
Quick node.js http "service" with low dependencies for sending serial code
var serialport = require('node-serialport');
var http = require('http');
var path = require('path');
console.log('loaded sp');
var port = '/dev/ttyO3';
console.log('opening' + port);
var sp = new serialport.SerialPort(port, {baud: 9600});
sp.on('open', function() {
console.log('opened');
http.createServer(function(req, res) {
var fileName = path.basename(req.url);
res.writeHead(200, {'Content-Type': 'text/html'});
sp.write(fileName);
res.end('WOOT - ' + fileName);
}).listen(3000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment