Home sensor prototype on Arduino & Raspberry Pi with Node.JS

6,198 views

Published on

This slide shows the steps to make home temperature & humidity sensor using two famous open source H/Ws (Arduino & Raspberry Pi) with Node.JS the server side JavaScript framework.

Published in: Technology
0 Comments
14 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,198
On SlideShare
0
From Embeds
0
Number of Embeds
2,686
Actions
Shares
0
Downloads
51
Comments
0
Likes
14
Embeds 0
No embeds

No notes for slide

Home sensor prototype on Arduino & Raspberry Pi with Node.JS

  1. 1. On Raspberry Pi & Arduino With Node.JS June. 2014
  2. 2. Home Temperature & Humidity Monitor Node.JS on Arduino + Raspberry Pi
  3. 3. Features (based on v. 0.1) – mobile web app on jQuery Mobile – show current temperature – show the trend of temp. – open API for using google chart TO-DOs – add humidity – add hypermedia API
  4. 4. Arduino Nano + Raspberry Pi + Wi-Fi LAN
  5. 5. Uses DHT11 sensor Resistance is required
  6. 6. Node.JS on Raspberry Pi in 5 min. – http://joshondesign.com/2013/10/23/noderpi Update raspbian Node & NPM Set environment sudo apt-get upgrade; sudo apt-get update wget http://nodejs.org/dist/v0.10.2/node-v0.10.2-linux-arm-pi.tar.gz tar -xvzf node-v0.10.2-linux-arm-pi.tar.gz node-v0.10.2-linux-arm- pi/bin/node --version NODE_JS_HOME=/home/pi/node-v0.10.2-linux-arm-pi PATH=$PATH:$NODE_JS_HOME/bin
  7. 7. Install MySQL server Install node-mysql Create table sudo apt-get install mysql-server npm install mysql mysql -u root -p Enter password: mysql> CREATE DB temps mysql> USE temps
  8. 8. Create schema Retrieving DB on Node.JS – http://iamapark89.wordpress.com/2013/12/1 4/node-js-2-db-%EC%97%B0%EA%B2%B0/ CREATE TABLE tempData ( tempId int(11) AUTO_INCREMENT NOT NULL, tempDate datetime NOT NULL, tempCelsius decimal(4,2) NOT NULL, humidity decimal(4,2) NOT NULL, constraint tempData_PK primary key (tempId) );
  9. 9. Flushing binary with Arduino IDE – http://playground.arduino.cc/main/DHT11Lib Install node-serialport – https://github.com/voodootikigod/node-serialport wget http://nodejs.org/dist/v0.10.12/node-v0.10.12-linux-arm- pi.tar.gz tar xvfz node-v0.10.12-linux-arm-pi.tar.gz sudo mv node-v0.10.12-linux-arm-pi /opt/node/ echo 'export PATH="$PATH:/opt/node/bin"' >> ~/.bashrc source ~/.bashrc npm install serialport
  10. 10. Programming server with JavaScript – JavaScript is also famous for front-end (client) Simple & Short Code – No type declaration & implicit type conversion – No multi-threading control Various open source libraries on NPM – Just type ‘npm install {library name}’ to use it Awesome playgrounds – Cloud IDE such as Cloud9 and web itself.
  11. 11. RequireJS – De facto JavaScript modularization • http://webofthink.tistory.com/12 Evented I/O asynchronous operation var http=require(‘http’); http.createServer(function (request, response) { // invoked asynchronously });
  12. 12. Web Application Server – sudo npm install express routes var express = require('express') , routes = require('./routes') , user = require('./routes/user') , temperatures = require('./routes/temperature') , http = require('http') , path = require('path'); var app = express(); // … omitted … app.get('/', routes.index); app.get('/users', user.list); app.get('/temperatures', temperatures.list); Handles GET /users Handles GET /temperatures
  13. 13. Jade Template Engine for Express – sudo node install jade Simplified HTML tag hierarchy doctype 5 html head title meta(name='viewport', content='width=device-width, initial-scale=1') body div(data-role='page', data-theme='a') h1 hr a
  14. 14. Responsive web design – Uses jQuery Mobile for free • See the demo: – http://demos.jquerymobile.com/ 1.3.0-beta.1/docs/demos/
  15. 15. Using Google Charts – https://developers.google.com/chart/
  16. 16. HTTP command, URI & representation – HTTP command: GET, PUT, POST, DELETE, … – URI: non-verb resources & it’s hierarchy – Representation : XML, JSON, … AJAX operation var xhr = new XMLHttpRequest(); xhr.open('get', '/temperatures'); xhr.onreadystatechange = function() { // code the event handler here } xhr.send(null);
  17. 17. JavaScript Everywhere – Consider 1st class citizen of web for all Internet of Things. Develop more APIs then Apps – App is opened to use but closed to create. – API gives the chance to mash things up. Data is just nothing without visualization – Imagine how the context can be found in data.
  18. 18. Design hypermedia API – Achieve the level 3 at Richardson Maturity Level • http://webofthink.tistory.com/2 Design REST to JavaScript API for better development – Make the mash-up and maintenance better – Provide user’s guide with Web IDL Multi-screen web application – Design the process how to develop N-Screen Apps.

×