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.
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
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. 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. 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)
);
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. 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. 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. 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. Responsive web design
– Uses jQuery Mobile for free
• See the demo:
– http://demos.jquerymobile.com/
1.3.0-beta.1/docs/demos/
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. 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. 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.