How to Hack a Road Tripwith a Webcam, a GSPand Some FunStreetView+ on the cheap                           NodeMTL.        ...
Pascal DeschenesTechnologist, Nu Echo Co-Founder@pdeschenhttp://about.me/pdeschen
Outline● Background● Base Modules● Geo Storage● Real-time Layer● Web Front● Demo
Background
Stop-motionmovie of ourNewfoundlandsummer roadtrip
Base Modules
CamelotNon-BlockingWebcam FrameGrabbing andRemoteController
Process Spawningvar spawn = require(child_process).spawn;var arguments = [];arguments.push(foo);...var fswebcam = spawn(fs...
BancroftNon-BlockingGPS DaemonClient
Event Emittingvar events = require(events);.../* tap into prototype chain */sys.inherits(Bancroft, events.EventEmitter);.....
Event Handlingvar bancroft = new Bancroft();bancroft.on(connect, function () { console.log(connected);});bancroft.on(locat...
Geo Storage
CradleA high-level,caching,CouchDB client
Initvar Cradle = require(cradle);var cradle = new (Cradle.Connection)(http://127.0.0.1, 5984, {cache:false});var db = crad...
Storevar document = { timestamp : new Date().getTime(), location : bancroft.location};db.save(uuid(), document, function (...
Deletedb.view(k/coordinates, function (err, rows) {   rows.forEach(function (row) {console.log(deleting, row);db.remove(ro...
Model{    "_id": "ffdba8b3-e125-4b4e-98fe-0be027aaec40",    "_rev": "2-43d3afdb1909626bc962e44612c57150",    "timestamp": ...
Real-time Layer
Socket.IOSending binarymessages
Base64 Encoding/* server side */io.sockets.volatile.emit(frame,  { data : frame.toString(base64) });/* client side */socke...
Web Front
Expressapp.get(/map, function (req, res) { res.render(map, {   title : "Kerouac" });});
Jade Templates<?xml version="1.0" encoding="UTF-8"?>kml(xmlns="http://earth.google.com/kml/2.1")  Document    name Newfoun...
REST Handlingapp.get(/status, function (req, res) { res.header(content-type, application/json); var status = messaging.loc...
Show Time
Open Issues    for an upcoming meet-up? volunteers?How to unit test event emission?What about native c++ module?What are t...
Questions? @pdeschen
Referenceshttp://nodejs.org/docs/v0.4.9/api/child_processes.htmlhttp://nodejs.org/docs/v0.4.9/api/events.htmlhttp://blog.r...
Upcoming SlideShare
Loading in...5
×

How to Hack a Road Trip with a Webcam, a GSP and Some Fun with Node

1,643

Published on

Part of a presentation @ nodemtl meetup. Presenting Kerouac, a real-time webapp featuring a remote GPS tracking device, a webcam and a whole lot of Node.js magic covering some basics of Node.js such as: event emitters and process spawning.

Published in: Technology, Travel
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,643
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
12
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

How to Hack a Road Trip with a Webcam, a GSP and Some Fun with Node

  1. 1. How to Hack a Road Tripwith a Webcam, a GSPand Some FunStreetView+ on the cheap NodeMTL. com
  2. 2. Pascal DeschenesTechnologist, Nu Echo Co-Founder@pdeschenhttp://about.me/pdeschen
  3. 3. Outline● Background● Base Modules● Geo Storage● Real-time Layer● Web Front● Demo
  4. 4. Background
  5. 5. Stop-motionmovie of ourNewfoundlandsummer roadtrip
  6. 6. Base Modules
  7. 7. CamelotNon-BlockingWebcam FrameGrabbing andRemoteController
  8. 8. Process Spawningvar spawn = require(child_process).spawn;var arguments = [];arguments.push(foo);...var fswebcam = spawn(fswebcam, arguments);fswebcam.stderr.on(data, function (data) { console.log(stdout: + data);});fswebcam.on(exit, function (code) { ...});
  9. 9. BancroftNon-BlockingGPS DaemonClient
  10. 10. Event Emittingvar events = require(events);.../* tap into prototype chain */sys.inherits(Bancroft, events.EventEmitter);...var emitter = events.EventEmitter.call(this);...emitter.emit(location, self.location);...emitter.emit(error, error);
  11. 11. Event Handlingvar bancroft = new Bancroft();bancroft.on(connect, function () { console.log(connected);});bancroft.on(location, function (location) { console.log(got new location, location);});
  12. 12. Geo Storage
  13. 13. CradleA high-level,caching,CouchDB client
  14. 14. Initvar Cradle = require(cradle);var cradle = new (Cradle.Connection)(http://127.0.0.1, 5984, {cache:false});var db = cradle.database(kerouac);if (!db.exists()) {db.create();}
  15. 15. Storevar document = { timestamp : new Date().getTime(), location : bancroft.location};db.save(uuid(), document, function (err, res) { console.log(res); db.saveAttachment(res.id, res.rev, frame, image/png, frame, function (err, data) { ... });});
  16. 16. Deletedb.view(k/coordinates, function (err, rows) { rows.forEach(function (row) {console.log(deleting, row);db.remove(row.key._id, row.key._rev); });});
  17. 17. Model{ "_id": "ffdba8b3-e125-4b4e-98fe-0be027aaec40", "_rev": "2-43d3afdb1909626bc962e44612c57150", "timestamp": 1311513742115, "location": { "timestamp": 1311513742000, "latitude": 44.423216667, "longitude": -72.944055, "altitude": 194.7, "speed": 0, "geometries": { "type": "Point", "coordinates": [-72.944055, 44.423216667, 194.7] } }, "_attachments": { "frame": { "content_type": "image/png", "revpos": 2, "length": 142666, "stub": true } }
  18. 18. Real-time Layer
  19. 19. Socket.IOSending binarymessages
  20. 20. Base64 Encoding/* server side */io.sockets.volatile.emit(frame, { data : frame.toString(base64) });/* client side */socket.on(frame, function (frame) { var img = $(#frame); img.attr("src", data:image/png;base64, + frame.data);});
  21. 21. Web Front
  22. 22. Expressapp.get(/map, function (req, res) { res.render(map, { title : "Kerouac" });});
  23. 23. Jade Templates<?xml version="1.0" encoding="UTF-8"?>kml(xmlns="http://earth.google.com/kml/2.1") Document name Newfoundland RoadTrip description A dynamically waypoint selection from an ongoing road trip Style(id="blueLine") LineStyle color red width 4 Placemark name Blue Line styleUrl #blueLine LineString altitudeMode relative coordinates - if (coordinates.length) - coordinates.forEach(function(coordinate) { =coordinate - })
  24. 24. REST Handlingapp.get(/status, function (req, res) { res.header(content-type, application/json); var status = messaging.location; db.view(kerouac/speed_mean, function (err, rows) { if (rows[0]) { status[mean] = rows[0].value.toFixed(2); } else { status[mean] = n.a.; } var json = JSON.stringify(status); res.send(json); });});
  25. 25. Show Time
  26. 26. Open Issues for an upcoming meet-up? volunteers?How to unit test event emission?What about native c++ module?What are the best practices regarding express.js codeorganization?How to distribute Socket.io/Express behind a proxy?
  27. 27. Questions? @pdeschen
  28. 28. Referenceshttp://nodejs.org/docs/v0.4.9/api/child_processes.htmlhttp://nodejs.org/docs/v0.4.9/api/events.htmlhttp://blog.rassemblr.com/tag/nodejs/https://github.com/pdeschen/camelothttps://github.com/pdeschen/bancrofthttps://github.com/cloudhead/cradlehttp://geojson.org/http://socket.io/http://expressjs.com/http://jade-lang.com/
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×