home sensor prototype 140617000035 phpapp01

Upload: khedotglorya

Post on 06-Jul-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/16/2019 Home Sensor Prototype 140617000035 Phpapp01

    1/18

    Home Sensing PrototypeOn Raspberry Pi & Arduino

    With Node.JS

    June. 2014

  • 8/16/2019 Home Sensor Prototype 140617000035 Phpapp01

    2/18

    Overview

    Home Temperature & Humidity MonitorNode.JS on Arduino + Raspberry Pi

  • 8/16/2019 Home Sensor Prototype 140617000035 Phpapp01

    3/18

    Home Temp. Monitor

    eatures !based on v. ".#$ – mobile web app on

    jQuery Mobile – show current temperature – show the trend of temp. – open API for using google chart

    TO% Os – add humidity – add hypermedia API

  • 8/16/2019 Home Sensor Prototype 140617000035 Phpapp01

    4/18

    System 'on(iguration

    Arduino Nano + Raspberry Pi + )i% i *AN

  • 8/16/2019 Home Sensor Prototype 140617000035 Phpapp01

    5/18

    'ir uit 'on(iguration

    ,ses HT## sensor

    Resistance isrequired

  • 8/16/2019 Home Sensor Prototype 140617000035 Phpapp01

    6/18

    -nsta Node.JS

    Node.JS on Raspberry Pi in / min. – http://joshondesign.com/2 !"/! /2"/noderpi

    ,pdate 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 -xvz node-v0.10.2-linux-arm-pi.tar.gz node-v0.10.2-linux-arm-pi/!in/node --version

    "#$%&J'&(#)%*/home/pi/node-v0.10.2-linux-arm-pi

    +, (* +, (: "#$%&J'&(#)%/!in

    http://joshondesign.com/2013/10/23/noderpihttp://joshondesign.com/2013/10/23/noderpihttp://joshondesign.com/2013/10/23/noderpi

  • 8/16/2019 Home Sensor Prototype 140617000035 Phpapp01

    7/18

    -nsta MyS0* !#12$

    -nsta MyS0* server

    -nsta node%mys3

    'reate tab e

    sudo apt-get install m s l-server

    npm install m s l

    m s l -u root -p%nter password:m s l 3%, % $ tempsm s l 5'% temps

  • 8/16/2019 Home Sensor Prototype 140617000035 Phpapp01

    8/18

    -nsta MyS0* !212$

    'reate s 4ema

    Retrieving 5 on Node.JS – http://iamapar#$%.wordpress.com/2 !

    "/!2/!&/node'js'2'db'()*(%+(, ()A(,2(,

    3%, % , 6% temp$ata 7

    temp8d int7119 ,5 #&8" 3%)%" "# "566temp$ate datetime "# "566temp elsius de imal74 29 "# "566humidit de imal74 29 "# "566

    onstraint temp$ata&+< primar =e 7temp8d99;

    http://iamapark89.wordpress.com/2013/12/14/node-js-2-db-%EC%97%B0%EA%B2%B0/http://iamapark89.wordpress.com/2013/12/14/node-js-2-db-%EC%97%B0%EA%B2%B0/http://iamapark89.wordpress.com/2013/12/14/node-js-2-db-%EC%97%B0%EA%B2%B0/http://iamapark89.wordpress.com/2013/12/14/node-js-2-db-%EC%97%B0%EA%B2%B0/http://iamapark89.wordpress.com/2013/12/14/node-js-2-db-%EC%97%B0%EA%B2%B0/http://iamapark89.wordpress.com/2013/12/14/node-js-2-db-%EC%97%B0%EA%B2%B0/http://iamapark89.wordpress.com/2013/12/14/node-js-2-db-%EC%97%B0%EA%B2%B0/

  • 8/16/2019 Home Sensor Prototype 140617000035 Phpapp01

    9/18

    Arduino + Node

    us4ing binary wit4 Arduino - 6 – http:// playground.arduino.cc/main/- !!0ib

    -nsta node%seria port

    – https:// github.com/1oodooti#igod/node'serialport

    wget http://nodejs.org/dist/v0.10.12/node-v0.10.12-linux-arm-pi.tar.gz

    tar xv z node-v0.10.12-linux-arm-pi.tar.gzsudo mv node-v0.10.12-linux-arm-pi /opt/node/e ho >export +, (*? +, (:/opt/node/!in?> @/.!ashrsour e @/.!ashrnpm install serialport

    http://playground.arduino.cc/main/DHT11Libhttp://playground.arduino.cc/main/DHT11Libhttps://github.com/voodootikigod/node-serialporthttps://github.com/voodootikigod/node-serialporthttps://github.com/voodootikigod/node-serialporthttps://github.com/voodootikigod/node-serialporthttp://playground.arduino.cc/main/DHT11Libhttp://playground.arduino.cc/main/DHT11Lib

  • 8/16/2019 Home Sensor Prototype 140617000035 Phpapp01

    10/18

    )4y Node.JS7

    Programming server wit4 JavaS ript – a1a3cript is also famous for front'end 4client5

    Simp e & S4ort 'ode – 6o type declaration 7 implicit type con1ersion – 6o multi'threading control

    8arious open sour e ibraries on NPM – ust type 8npm install 9library name: ; to use it

    Awesome p aygrounds –

    *loud I-) such as *loud% and web itself.

  • 8/16/2019 Home Sensor Prototype 140617000035 Phpapp01

    11/18

    Node.JS 9ey on epts

    Re3uireJS – -e facto a1a3cript modulari

  • 8/16/2019 Home Sensor Prototype 140617000035 Phpapp01

    12/18

    )AS

    )eb App i ation Server – sudo npm install e=press routes

    var express * re uire7>express>9 routes *re uire7>./routes>9 user * re uire7>./routes/user>9 temperatures * re uire7>./routes/temperature>9 http *re uire7>http>9 path * re uire7>path>9;var app * express79;// E omitted E

    app.get7>/> routes.index9;app.get7>/users> user.list9;app.get7>/temperatures> temperatures.list9;

    Handles GET /users

    Handles GET/temperatures

  • 8/16/2019 Home Sensor Prototype 140617000035 Phpapp01

    13/18

    )eb Server

    Jade Temp ate 6ngine (or 6:press – sudo node install jade

    Simp i(ied HTM* tag 4ierar 4ydo t pe Fhtml

    headtitle

    meta7name*>viewport> ontent*>width*devi e-widthinitial-s ale*1>9!od

    div7data-role*>page> data-theme*>a>9h1hr

    a

  • 8/16/2019 Home Sensor Prototype 140617000035 Phpapp01

    14/18

    ,ser -nter(a e

    Responsive web design – >ses jQuery Mobile for free

    • 3ee the demo: – http://demos.j?uerymobile.com/

    !.". 'beta.!/docs/demos/

    http://demos.jquerymobile.com/1.3.0-beta.1/docs/demos/http://demos.jquerymobile.com/1.3.0-beta.1/docs/demos/http://demos.jquerymobile.com/1.3.0-beta.1/docs/demos/http://demos.jquerymobile.com/1.3.0-beta.1/docs/demos/http://demos.jquerymobile.com/1.3.0-beta.1/docs/demos/

  • 8/16/2019 Home Sensor Prototype 140617000035 Phpapp01

    15/18

    8isua i;ation

    ,sing

  • 8/16/2019 Home Sensor Prototype 140617000035 Phpapp01

    16/18

    R6ST(u )eb AP-

    HTTP ommand= ,R- & representation – P command: @) P> PB3 -)0) )

    C – >DI: non'1erb resources 7 it;s hierarchy – Depresentation : EM0 3B6 C

    AJA> operationvar xhr * new G)6(ttp3e uest79;xhr.open7>get> >/temperatures>9;xhr.onread state hange * un tion79 C // ode the event handler here

    D xhr.send7null9;

  • 8/16/2019 Home Sensor Prototype 140617000035 Phpapp01

    17/18

    'on usions

    JavaS ript 6veryw4ere – *onsider ! st class citi

  • 8/16/2019 Home Sensor Prototype 140617000035 Phpapp01

    18/18

    uture wor9s

    esign 4ypermedia AP- – Achie1e the le1el " at Dichardson Maturity 0e1el

    http:// webofthin#.tistory.com/2 esign R6ST to JavaS ript AP- (or better dev

    e opment – Ma#e the mash'up and maintenance better – Pro1ide user;s guide with Feb I-0

    Mu ti%s reen web app i ation – -esign the process how to de1elop 6'3creen A

    pps.

    http://webofthink.tistory.com/2http://webofthink.tistory.com/2http://www.w3.org/TR/WebIDL/http://www.w3.org/TR/WebIDL/http://webofthink.tistory.com/2http://webofthink.tistory.com/2