Created
January 18, 2012 22:10
-
-
Save dansteingart/1636134 to your computer and use it in GitHub Desktop.
Simple Data Logger in Node.Js
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 http = require("http"); //HTTP Server | |
var url = require("url"); // URL Handling | |
var fs = require('fs'); // Filesystem Access (writing files) | |
var express = require('express'), //App Framework (similar to web.py abstraction) | |
app = express.createServer(); | |
app.use(express.bodyParser()); | |
app.use(app.router); | |
io = require('socket.io').listen(app); //Socket Creations | |
io.set('log level', 1) | |
var serialport = require("serialport") //Serial Port Creation | |
var SerialPort = require("serialport").SerialPort | |
var serialPort = new SerialPort("/dev/tty.usbserial",{baudrate:2400}); | |
app.use("/socket.io", express.static(__dirname + '/node_modules/socket.io/lib')); | |
app.get('/', function(req, res){ | |
indexer = fs.readFileSync('index.html').toString() | |
res.send(indexer); | |
}); | |
app.listen(8888); | |
console.log('Express server started on port %s', app.address().port); | |
data_log = [] | |
serialPort.on("data", function (data) { | |
data_log.push(data) | |
console.log(data) | |
io.sockets.emit('new_data',{'mm_data':data}) | |
if (data_log.length == 14) | |
{ | |
out = "" | |
for (var i = 0; i < data_log.length;i++) | |
{ | |
out += data_log[i].toString().charCodeAt(0)+" " | |
} | |
console.log(out) | |
data_log = [] | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment