Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sbstjn committed Apr 10, 2012
0 parents commit 72ce5a3
Show file tree
Hide file tree
Showing 53 changed files with 16,777 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
.DS_Store
node_modules
8 changes: 8 additions & 0 deletions LICENSE
@@ -0,0 +1,8 @@
The MIT License (MIT)
Copyright (c) 2012 Sebastian Müller

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 changes: 17 additions & 0 deletions README.md
@@ -0,0 +1,17 @@
Simple Node.js application for piping serial communication from your arduino to a modern web browser with WebSockets.

![arduino-socket](http://semu.mp/screenshots/arduino-socket-20120410-173825.png)

See `serial.js` for setting your serial port and needed baud rate

define(['child_process', 'serialport'], function(child, serialport) {
var serial = {
'connect': function(socket) {
board = new serialport.SerialPort('/dev/tty.usbmodem1a21', {
baudrate: 9600,
parser: serialport.parsers.readline("\n")
});
Install dependencies with `npm install`, start the application with `node app.js` and point your web browser to [http://localhost:8080](http://localhost:8080) to see your arduino's serial output…

Using Node.js, Express.js, Socket.IO, bootstrap by twitter and some more libs…
7 changes: 7 additions & 0 deletions app.js
@@ -0,0 +1,7 @@
var requirejs = require('requirejs');
requirejs.config({nodeRequire: require});

requirejs(['serial', 'web', 'socket'],function(serial, web, socket) {
serial.connect(socket);
web.listen(8080);
});
13 changes: 13 additions & 0 deletions package.json
@@ -0,0 +1,13 @@
{
"name": "arduino-websocket",
"description": "Pipe data from serial connection trough websockets to a browser",
"author": "Sebastian Müller <mail@semu.mp>",
"version": "0.1",
"dependencies": {
"requirejs": ">= 1.0.7",
"serialport": ">= 0.7.3",
"kickstart": ">= 0.0.5",
"socket.io": ">= 0.9.3"
},
"engine": "node >= 0.4.1"
}
17 changes: 17 additions & 0 deletions public/scripts/main.js
@@ -0,0 +1,17 @@
var isRunning = false;

function ISODateString(d){
function padT(n){return (n<10 ? '0'+n : n); }
function padH(n){return (n<10 ? '00'+n : (n<100 ? '0'+n : n)); }
return padT(d.getUTCHours())+':'+padT(d.getUTCMinutes())+':'+padT(d.getUTCSeconds())+'Z'+padH(d.getUTCMilliseconds());
}

require(["jquery"], function($) {
var socket = io.connect();
socket.on('msg', function (data) {
if ($("#socket li").length > 20) {
$("#socket li:nth-child(1)").remove(); }

$('#socket').append('<li>' + ISODateString(new Date()) + " " + data + '</li>');
});
});

0 comments on commit 72ce5a3

Please sign in to comment.