SlideShare une entreprise Scribd logo
1  sur  28
Télécharger pour lire hors ligne
How to build a depression
predictor
(a.k.a. a belgian weather station)
using Arduino & Node.js
@stevenbeeckman #iotbe #njugbe
In short
Arduino IDE: arduino.cc/dowload
Install StandardFirmata sketch on the Arduino
npm install johnny-five
write your script.js
Run node script.js
You need a host
computer connected to
the Arduino
Let’s build a depression
predictor
(or a belgian weather station)
Things we need
A sensor
Something to gather the sensor data
Something to store the generated timeseries
A visualisation
photoresistor Arduino MacBook Browsercloud
Heroku
+
node.js
+
hapi.js
+
Tempo
DB
add-on
photoresistor Arduino Uno
Node.js
+
Johnny Five
+
request
+
forever
TempoDB
web app
ADC http httpusb
Heroku
+
node.js
+
hapi.js
+
Tempo
DB
add-on
photoresistor Arduino Uno
Node.js
+
Johnny Five
+
request
+
forever
TempoDB
web app
ADC http httpusb
MacGyver-ism: no resistors in house and
no nearby shops to buy them from -> use
a piezo as a resistor
Heroku
+
node.js
+
hapi.js
+
Tempo
DB
add-on
photoresistor Arduino Uno
Node.js
+
Johnny Five
+
request
+
forever
TempoDB
web app
ADC http httpusb
Packages you need
npm install --save johnny-five
npm install --save request
npm install -g forever
usage:
forever start script.js
forever list (to see what’s running)
https://github.com/stevenbeeckman/arduino-j5
Heroku
+
node.js
+
hapi.js
+
Tempo
DB
add-on
photoresistor Arduino Uno
Node.js
+
Johnny Five
+
request
+
forever
TempoDB
web app
ADC http httpusb
Design
Need a REST API over HTTP
(Mandatory) POST new sensor values
(Optional) GET overview of past sensor values
Store data in a time series friendly database
Packages you need
"dependencies": {
"hapi": "^6.5.1",
"moment": "^2.8.2",
"tempodb": "^1.0.0"
}
https://github.com/stevenbeeckman/iotbe-njugbe/
Hosting
This code can run on your own server or in the
cloud.
I ran it in the cloud, on Heroku and used the
free TempoDB add-on.
Some code
var Hapi = require('hapi');
var server = new Hapi.Server(process.env.PORT || 3000);
server.route({
method: 'GET'
, path: '/'
, handler: function(request, reply){
reply('Hello, Internet of Things fans!');
}
});
server.start(function(){
console.log('Server running at:' + server.info.uri);
});
heroku create
git add index.js
git commit -m “First deploy.”
git push heroku master
http://iotbe-njugbe.herokuapp.com/
Writing to your TempoDB
var TempoDBClient = require('tempodb').TempoDBClient;
var tempodb = new TempoDBClient('heroku-5e2f03bd25cf424098426a8a21db26f3', process.env.TEMPODB_API_KEY, process.env.
TEMPODB_API_SECRET, {hostname: process.env.TEMPODB_API_HOST, port: process.env.TEMPODB_API_PORT});
var moment = require('moment');
server.route({
method: 'POST'
, path: '/sensor/{sensor_id}/measurement'
, config: {
handler: function(request, reply){
var newMeasurement = new Object();
newMeasurement.t = moment().format("YYYY-MM-DDTHH:mm:ss.SSSZZ");
newMeasurement.v = request.payload.value;
var tempodb_data = new Array();
tempodb_data.push(newMeasurement);
var series_key = 'sensor-' + request.params.sensor_id;
tempodb.write_key(series_key, tempodb_data, function(error, result){
error ? reply(error) : reply(result);
});
}
}
});
Writing to your TempoDB
var TempoDBClient = require('tempodb').TempoDBClient;
var tempodb = new TempoDBClient('heroku-5e2f03bd25cf424098426a8a21db26f3', process.env.TEMPODB_API_KEY, process.env.
TEMPODB_API_SECRET, {hostname: process.env.TEMPODB_API_HOST, port: process.env.TEMPODB_API_PORT});
var moment = require('moment');
server.route({
method: 'POST'
, path: '/sensor/{sensor_id}/measurement'
, config: {
handler: function(request, reply){
var newMeasurement = new Object();
newMeasurement.t = moment().format("YYYY-MM-DDTHH:mm:ss.SSSZZ");
newMeasurement.v = request.payload.value;
var tempodb_data = new Array();
tempodb_data.push(newMeasurement);
var series_key = 'sensor-' + request.params.sensor_id;
tempodb.write_key(series_key, tempodb_data, function(error, result){
error ? reply(error) : reply(result);
});
}
}
});
Not documented: date must be formatted.
new Date() will not work as is. Use moment.js for
easy formatting.
Writing to your TempoDB
var TempoDBClient = require('tempodb').TempoDBClient;
var tempodb = new TempoDBClient('heroku-5e2f03bd25cf424098426a8a21db26f3', process.env.TEMPODB_API_KEY, process.env.
TEMPODB_API_SECRET, {hostname: process.env.TEMPODB_API_HOST, port: process.env.TEMPODB_API_PORT});
var moment = require('moment');
server.route({
method: 'POST'
, path: '/sensor/{sensor_id}/measurement'
, config: {
handler: function(request, reply){
var newMeasurement = new Object();
newMeasurement.t = moment().format("YYYY-MM-DDTHH:mm:ss.SSSZZ");
newMeasurement.v = request.payload.value;
var tempodb_data = new Array();
tempodb_data.push(newMeasurement);
var series_key = 'sensor-' + request.params.sensor_id;
tempodb.write_key(series_key, tempodb_data, function(error, result){
error ? reply(error) : reply(result);
});
}
}
});
Single key value pairs {t,v} must be wrapped in an
Array too...
Writing to your TempoDB
var TempoDBClient = require('tempodb').TempoDBClient;
var tempodb = new TempoDBClient('heroku-5e2f03bd25cf424098426a8a21db26f3', process.env.TEMPODB_API_KEY, process.env.
TEMPODB_API_SECRET, {hostname: process.env.TEMPODB_API_HOST, port: process.env.TEMPODB_API_PORT});
var moment = require('moment');
server.route({
method: 'POST'
, path: '/sensor/{sensor_id}/measurement'
, config: {
handler: function(request, reply){
var newMeasurement = new Object();
newMeasurement.t = moment().format("YYYY-MM-DDTHH:mm:ss.SSSZZ");
newMeasurement.v = request.payload.value;
var tempodb_data = new Array();
tempodb_data.push(newMeasurement);
var series_key = 'sensor-' + request.params.sensor_id;
tempodb.write_key(series_key, tempodb_data, function(error, result){
error ? reply(error) : reply(result);
});
}
}
});
Warning:
You have to pass the TempoDB database name too,
which is not documented!
Heroku
+
node.js
+
hapi.js
+
Tempo
DB
add-on
photoresistor Arduino Uno
Node.js
+
Johnny Five
+
request
+
forever
TempoDB
web app
ADC http httpusb
MacBooks crash
too
hard drive failure
References
http://arduino.cc
https://github.com/rwaldron/johnny-five
http://blog.nodejitsu.com/keep-a-nodejs-server-up-with-
forever/
http://heroku.com
http://hapijs.com
http://momentjs.com
https://tempo-db.com
Questions?
@stevenbeeckman #iotbe #njugbe

Contenu connexe

Tendances

The Ring programming language version 1.5.4 book - Part 62 of 185
The Ring programming language version 1.5.4 book - Part 62 of 185The Ring programming language version 1.5.4 book - Part 62 of 185
The Ring programming language version 1.5.4 book - Part 62 of 185Mahmoud Samir Fayed
 
Hybrid quantum classical neural networks with pytorch and qiskit
Hybrid quantum classical neural networks with pytorch and qiskitHybrid quantum classical neural networks with pytorch and qiskit
Hybrid quantum classical neural networks with pytorch and qiskitVijayananda Mohire
 
倒计时优化点滴
倒计时优化点滴倒计时优化点滴
倒计时优化点滴j5726
 
Qsam simulator in IBM Quantum Lab cloud
Qsam simulator in IBM Quantum Lab cloudQsam simulator in IBM Quantum Lab cloud
Qsam simulator in IBM Quantum Lab cloudVijayananda Mohire
 
Service worker: discover the next web game changer
Service worker: discover the next web game changerService worker: discover the next web game changer
Service worker: discover the next web game changerSandro Paganotti
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017名辰 洪
 
Calculator code with scientific functions in java
Calculator code with scientific functions in java Calculator code with scientific functions in java
Calculator code with scientific functions in java Amna Nawazish
 
Star bed 2018.07.19
Star bed 2018.07.19Star bed 2018.07.19
Star bed 2018.07.19Ruo Ando
 
MongoDB World 2019: Life In Stitch-es
MongoDB World 2019: Life In Stitch-esMongoDB World 2019: Life In Stitch-es
MongoDB World 2019: Life In Stitch-esMongoDB
 
Monitoring und Metriken im Wunderland
Monitoring und Metriken im WunderlandMonitoring und Metriken im Wunderland
Monitoring und Metriken im WunderlandD
 
Async JavaScript in ES7
Async JavaScript in ES7Async JavaScript in ES7
Async JavaScript in ES7Mike North
 
Using Change Streams to Keep Up with Your Data
Using Change Streams to Keep Up with Your DataUsing Change Streams to Keep Up with Your Data
Using Change Streams to Keep Up with Your DataMongoDB
 
New feature of async fakeAsync test in angular
New feature of async fakeAsync test in angularNew feature of async fakeAsync test in angular
New feature of async fakeAsync test in angularJia Li
 
The Ring programming language version 1.2 book - Part 44 of 84
The Ring programming language version 1.2 book - Part 44 of 84The Ring programming language version 1.2 book - Part 44 of 84
The Ring programming language version 1.2 book - Part 44 of 84Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 69 of 189
The Ring programming language version 1.6 book - Part 69 of 189The Ring programming language version 1.6 book - Part 69 of 189
The Ring programming language version 1.6 book - Part 69 of 189Mahmoud Samir Fayed
 

Tendances (20)

The Ring programming language version 1.5.4 book - Part 62 of 185
The Ring programming language version 1.5.4 book - Part 62 of 185The Ring programming language version 1.5.4 book - Part 62 of 185
The Ring programming language version 1.5.4 book - Part 62 of 185
 
Hybrid quantum classical neural networks with pytorch and qiskit
Hybrid quantum classical neural networks with pytorch and qiskitHybrid quantum classical neural networks with pytorch and qiskit
Hybrid quantum classical neural networks with pytorch and qiskit
 
倒计时优化点滴
倒计时优化点滴倒计时优化点滴
倒计时优化点滴
 
Qsam simulator in IBM Quantum Lab cloud
Qsam simulator in IBM Quantum Lab cloudQsam simulator in IBM Quantum Lab cloud
Qsam simulator in IBM Quantum Lab cloud
 
Service worker: discover the next web game changer
Service worker: discover the next web game changerService worker: discover the next web game changer
Service worker: discover the next web game changer
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017
 
Calculator code with scientific functions in java
Calculator code with scientific functions in java Calculator code with scientific functions in java
Calculator code with scientific functions in java
 
Star bed 2018.07.19
Star bed 2018.07.19Star bed 2018.07.19
Star bed 2018.07.19
 
Multi qubit entanglement
Multi qubit entanglementMulti qubit entanglement
Multi qubit entanglement
 
node-rpi-ws281x
node-rpi-ws281xnode-rpi-ws281x
node-rpi-ws281x
 
Caching a page
Caching a pageCaching a page
Caching a page
 
MongoDB World 2019: Life In Stitch-es
MongoDB World 2019: Life In Stitch-esMongoDB World 2019: Life In Stitch-es
MongoDB World 2019: Life In Stitch-es
 
Monitoring und Metriken im Wunderland
Monitoring und Metriken im WunderlandMonitoring und Metriken im Wunderland
Monitoring und Metriken im Wunderland
 
Async JavaScript in ES7
Async JavaScript in ES7Async JavaScript in ES7
Async JavaScript in ES7
 
Rxjs swetugg
Rxjs swetuggRxjs swetugg
Rxjs swetugg
 
Using Change Streams to Keep Up with Your Data
Using Change Streams to Keep Up with Your DataUsing Change Streams to Keep Up with Your Data
Using Change Streams to Keep Up with Your Data
 
New feature of async fakeAsync test in angular
New feature of async fakeAsync test in angularNew feature of async fakeAsync test in angular
New feature of async fakeAsync test in angular
 
Rxjs marble-testing
Rxjs marble-testingRxjs marble-testing
Rxjs marble-testing
 
The Ring programming language version 1.2 book - Part 44 of 84
The Ring programming language version 1.2 book - Part 44 of 84The Ring programming language version 1.2 book - Part 44 of 84
The Ring programming language version 1.2 book - Part 44 of 84
 
The Ring programming language version 1.6 book - Part 69 of 189
The Ring programming language version 1.6 book - Part 69 of 189The Ring programming language version 1.6 book - Part 69 of 189
The Ring programming language version 1.6 book - Part 69 of 189
 

Similaire à Arduino & node.js

How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js ModuleFred Chien
 
End to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux SagaEnd to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux SagaBabacar NIANG
 
Артем Маркушев - JavaScript
Артем Маркушев - JavaScriptАртем Маркушев - JavaScript
Артем Маркушев - JavaScriptDataArt
 
a friend in need-a js indeed / Yonatan levin
a friend in need-a js indeed / Yonatan levina friend in need-a js indeed / Yonatan levin
a friend in need-a js indeed / Yonatan levingeektimecoil
 
A friend in need - A JS indeed
A friend in need - A JS indeedA friend in need - A JS indeed
A friend in need - A JS indeedYonatan Levin
 
Yves & Zed @ Developer Conference 2013
Yves & Zed @ Developer Conference 2013Yves & Zed @ Developer Conference 2013
Yves & Zed @ Developer Conference 2013FabianWesnerBerlin
 
Background Jobs - Com BackgrounDRb
Background Jobs - Com BackgrounDRbBackground Jobs - Com BackgrounDRb
Background Jobs - Com BackgrounDRbJuan Maiz
 
node.js and the AR.Drone: building a real-time dashboard using socket.io
node.js and the AR.Drone: building a real-time dashboard using socket.ionode.js and the AR.Drone: building a real-time dashboard using socket.io
node.js and the AR.Drone: building a real-time dashboard using socket.ioSteven Beeckman
 
fog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloudfog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the CloudWesley Beary
 
Ardupilot Gazebo status.pdf
Ardupilot Gazebo status.pdfArdupilot Gazebo status.pdf
Ardupilot Gazebo status.pdfssuserd7d2f2
 
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Masahiro Nagano
 
Gearmanpresentation 110308165409-phpapp01
Gearmanpresentation 110308165409-phpapp01Gearmanpresentation 110308165409-phpapp01
Gearmanpresentation 110308165409-phpapp01longtuan
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comVan-Duyet Le
 
AWS IoT 핸즈온 워크샵 - 실습 5. DynamoDB에 센서 데이터 저장하기 (김무현 솔루션즈 아키텍트)
AWS IoT 핸즈온 워크샵 - 실습 5. DynamoDB에 센서 데이터 저장하기 (김무현 솔루션즈 아키텍트)AWS IoT 핸즈온 워크샵 - 실습 5. DynamoDB에 센서 데이터 저장하기 (김무현 솔루션즈 아키텍트)
AWS IoT 핸즈온 워크샵 - 실습 5. DynamoDB에 센서 데이터 저장하기 (김무현 솔루션즈 아키텍트)Amazon Web Services Korea
 
Live Streaming & Server Sent Events
Live Streaming & Server Sent EventsLive Streaming & Server Sent Events
Live Streaming & Server Sent Eventstkramar
 
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)Wesley Beary
 
Real World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationReal World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationBen Hall
 

Similaire à Arduino & node.js (20)

How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js Module
 
Server/Client Remote platform logger.
Server/Client Remote platform logger.Server/Client Remote platform logger.
Server/Client Remote platform logger.
 
End to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux SagaEnd to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux Saga
 
Артем Маркушев - JavaScript
Артем Маркушев - JavaScriptАртем Маркушев - JavaScript
Артем Маркушев - JavaScript
 
a friend in need-a js indeed / Yonatan levin
a friend in need-a js indeed / Yonatan levina friend in need-a js indeed / Yonatan levin
a friend in need-a js indeed / Yonatan levin
 
A friend in need - A JS indeed
A friend in need - A JS indeedA friend in need - A JS indeed
A friend in need - A JS indeed
 
R-House (LSRC)
R-House (LSRC)R-House (LSRC)
R-House (LSRC)
 
Yves & Zed @ Developer Conference 2013
Yves & Zed @ Developer Conference 2013Yves & Zed @ Developer Conference 2013
Yves & Zed @ Developer Conference 2013
 
Der perfekte 12c trigger
Der perfekte 12c triggerDer perfekte 12c trigger
Der perfekte 12c trigger
 
Background Jobs - Com BackgrounDRb
Background Jobs - Com BackgrounDRbBackground Jobs - Com BackgrounDRb
Background Jobs - Com BackgrounDRb
 
node.js and the AR.Drone: building a real-time dashboard using socket.io
node.js and the AR.Drone: building a real-time dashboard using socket.ionode.js and the AR.Drone: building a real-time dashboard using socket.io
node.js and the AR.Drone: building a real-time dashboard using socket.io
 
fog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloudfog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloud
 
Ardupilot Gazebo status.pdf
Ardupilot Gazebo status.pdfArdupilot Gazebo status.pdf
Ardupilot Gazebo status.pdf
 
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015
 
Gearmanpresentation 110308165409-phpapp01
Gearmanpresentation 110308165409-phpapp01Gearmanpresentation 110308165409-phpapp01
Gearmanpresentation 110308165409-phpapp01
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.com
 
AWS IoT 핸즈온 워크샵 - 실습 5. DynamoDB에 센서 데이터 저장하기 (김무현 솔루션즈 아키텍트)
AWS IoT 핸즈온 워크샵 - 실습 5. DynamoDB에 센서 데이터 저장하기 (김무현 솔루션즈 아키텍트)AWS IoT 핸즈온 워크샵 - 실습 5. DynamoDB에 센서 데이터 저장하기 (김무현 솔루션즈 아키텍트)
AWS IoT 핸즈온 워크샵 - 실습 5. DynamoDB에 센서 데이터 저장하기 (김무현 솔루션즈 아키텍트)
 
Live Streaming & Server Sent Events
Live Streaming & Server Sent EventsLive Streaming & Server Sent Events
Live Streaming & Server Sent Events
 
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
 
Real World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationReal World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS Application
 

Plus de Steven Beeckman

An Incomplete Introduction to Artificial Intelligence
An Incomplete Introduction to Artificial IntelligenceAn Incomplete Introduction to Artificial Intelligence
An Incomplete Introduction to Artificial IntelligenceSteven Beeckman
 
Digital transformation in other countries' governments
Digital transformation in other countries' governmentsDigital transformation in other countries' governments
Digital transformation in other countries' governmentsSteven Beeckman
 
csv,conf 2014 - Open data within organizations
csv,conf 2014 - Open data within organizationscsv,conf 2014 - Open data within organizations
csv,conf 2014 - Open data within organizationsSteven Beeckman
 
Boondoggle Bright - Hackathing - StartupBus
Boondoggle Bright - Hackathing - StartupBusBoondoggle Bright - Hackathing - StartupBus
Boondoggle Bright - Hackathing - StartupBusSteven Beeckman
 
BlackBerry 10 Core Native Camera API
BlackBerry 10 Core Native Camera APIBlackBerry 10 Core Native Camera API
BlackBerry 10 Core Native Camera APISteven Beeckman
 
Testing & Deploying node.js apps
Testing & Deploying node.js appsTesting & Deploying node.js apps
Testing & Deploying node.js appsSteven Beeckman
 
4 Simple Rules of Design
4 Simple Rules of Design4 Simple Rules of Design
4 Simple Rules of DesignSteven Beeckman
 
BlackBerry Developers Group Belgium - 1st meetup
BlackBerry Developers Group Belgium - 1st meetupBlackBerry Developers Group Belgium - 1st meetup
BlackBerry Developers Group Belgium - 1st meetupSteven Beeckman
 
Node.js User Group Belgium - 1st meetup
Node.js User Group Belgium - 1st meetupNode.js User Group Belgium - 1st meetup
Node.js User Group Belgium - 1st meetupSteven Beeckman
 
Think Before You Act or Rapid Prototyping
Think Before You Act or Rapid PrototypingThink Before You Act or Rapid Prototyping
Think Before You Act or Rapid PrototypingSteven Beeckman
 

Plus de Steven Beeckman (12)

An Incomplete Introduction to Artificial Intelligence
An Incomplete Introduction to Artificial IntelligenceAn Incomplete Introduction to Artificial Intelligence
An Incomplete Introduction to Artificial Intelligence
 
Digital transformation in other countries' governments
Digital transformation in other countries' governmentsDigital transformation in other countries' governments
Digital transformation in other countries' governments
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
csv,conf 2014 - Open data within organizations
csv,conf 2014 - Open data within organizationscsv,conf 2014 - Open data within organizations
csv,conf 2014 - Open data within organizations
 
Boondoggle Bright - Hackathing - StartupBus
Boondoggle Bright - Hackathing - StartupBusBoondoggle Bright - Hackathing - StartupBus
Boondoggle Bright - Hackathing - StartupBus
 
Intro
IntroIntro
Intro
 
BlackBerry 10 Core Native Camera API
BlackBerry 10 Core Native Camera APIBlackBerry 10 Core Native Camera API
BlackBerry 10 Core Native Camera API
 
Testing & Deploying node.js apps
Testing & Deploying node.js appsTesting & Deploying node.js apps
Testing & Deploying node.js apps
 
4 Simple Rules of Design
4 Simple Rules of Design4 Simple Rules of Design
4 Simple Rules of Design
 
BlackBerry Developers Group Belgium - 1st meetup
BlackBerry Developers Group Belgium - 1st meetupBlackBerry Developers Group Belgium - 1st meetup
BlackBerry Developers Group Belgium - 1st meetup
 
Node.js User Group Belgium - 1st meetup
Node.js User Group Belgium - 1st meetupNode.js User Group Belgium - 1st meetup
Node.js User Group Belgium - 1st meetup
 
Think Before You Act or Rapid Prototyping
Think Before You Act or Rapid PrototypingThink Before You Act or Rapid Prototyping
Think Before You Act or Rapid Prototyping
 

Dernier

Gaya Call Girls #9907093804 Contact Number Escorts Service Gaya
Gaya Call Girls #9907093804 Contact Number Escorts Service GayaGaya Call Girls #9907093804 Contact Number Escorts Service Gaya
Gaya Call Girls #9907093804 Contact Number Escorts Service Gayasrsj9000
 
5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)
5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)
5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)861c7ca49a02
 
定制(UI学位证)爱达荷大学毕业证成绩单原版一比一
定制(UI学位证)爱达荷大学毕业证成绩单原版一比一定制(UI学位证)爱达荷大学毕业证成绩单原版一比一
定制(UI学位证)爱达荷大学毕业证成绩单原版一比一ss ss
 
1:1原版定制美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
1:1原版定制美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree1:1原版定制美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
1:1原版定制美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degreeyuu sss
 
专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degreeyuu sss
 
Presentation.pptxjnfoigneoifnvoeifnvklfnvf
Presentation.pptxjnfoigneoifnvoeifnvklfnvfPresentation.pptxjnfoigneoifnvoeifnvklfnvf
Presentation.pptxjnfoigneoifnvoeifnvklfnvfchapmanellie27
 
NO1 WorldWide kala jadu Love Marriage Black Magic Punjab Powerful Black Magic...
NO1 WorldWide kala jadu Love Marriage Black Magic Punjab Powerful Black Magic...NO1 WorldWide kala jadu Love Marriage Black Magic Punjab Powerful Black Magic...
NO1 WorldWide kala jadu Love Marriage Black Magic Punjab Powerful Black Magic...Amil baba
 
Papular No 1 Online Istikhara Amil Baba Pakistan Amil Baba In Karachi Amil B...
Papular No 1 Online Istikhara Amil Baba Pakistan  Amil Baba In Karachi Amil B...Papular No 1 Online Istikhara Amil Baba Pakistan  Amil Baba In Karachi Amil B...
Papular No 1 Online Istikhara Amil Baba Pakistan Amil Baba In Karachi Amil B...Authentic No 1 Amil Baba In Pakistan
 
Hifi Defence Colony Call Girls Service WhatsApp -> 9999965857 Available 24x7 ...
Hifi Defence Colony Call Girls Service WhatsApp -> 9999965857 Available 24x7 ...Hifi Defence Colony Call Girls Service WhatsApp -> 9999965857 Available 24x7 ...
Hifi Defence Colony Call Girls Service WhatsApp -> 9999965857 Available 24x7 ...srsj9000
 
专业一比一美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree专业一比一美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degreeyuu sss
 
Erfurt FH学位证,埃尔福特应用技术大学毕业证书1:1制作
Erfurt FH学位证,埃尔福特应用技术大学毕业证书1:1制作Erfurt FH学位证,埃尔福特应用技术大学毕业证书1:1制作
Erfurt FH学位证,埃尔福特应用技术大学毕业证书1:1制作f3774p8b
 
RBS学位证,鹿特丹商学院毕业证书1:1制作
RBS学位证,鹿特丹商学院毕业证书1:1制作RBS学位证,鹿特丹商学院毕业证书1:1制作
RBS学位证,鹿特丹商学院毕业证书1:1制作f3774p8b
 
定制(USF学位证)旧金山大学毕业证成绩单原版一比一
定制(USF学位证)旧金山大学毕业证成绩单原版一比一定制(USF学位证)旧金山大学毕业证成绩单原版一比一
定制(USF学位证)旧金山大学毕业证成绩单原版一比一ss ss
 
Hifi Babe North Delhi Call Girl Service Fun Tonight
Hifi Babe North Delhi Call Girl Service Fun TonightHifi Babe North Delhi Call Girl Service Fun Tonight
Hifi Babe North Delhi Call Girl Service Fun TonightKomal Khan
 
(办理学位证)韩国汉阳大学毕业证成绩单原版一比一
(办理学位证)韩国汉阳大学毕业证成绩单原版一比一(办理学位证)韩国汉阳大学毕业证成绩单原版一比一
(办理学位证)韩国汉阳大学毕业证成绩单原版一比一C SSS
 
Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...
Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...
Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...nagunakhan
 
威廉玛丽学院毕业证学位证成绩单-安全学历认证
威廉玛丽学院毕业证学位证成绩单-安全学历认证威廉玛丽学院毕业证学位证成绩单-安全学历认证
威廉玛丽学院毕业证学位证成绩单-安全学历认证kbdhl05e
 

Dernier (20)

Gaya Call Girls #9907093804 Contact Number Escorts Service Gaya
Gaya Call Girls #9907093804 Contact Number Escorts Service GayaGaya Call Girls #9907093804 Contact Number Escorts Service Gaya
Gaya Call Girls #9907093804 Contact Number Escorts Service Gaya
 
5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)
5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)
5S - House keeping (Seiri, Seiton, Seiso, Seiketsu, Shitsuke)
 
定制(UI学位证)爱达荷大学毕业证成绩单原版一比一
定制(UI学位证)爱达荷大学毕业证成绩单原版一比一定制(UI学位证)爱达荷大学毕业证成绩单原版一比一
定制(UI学位证)爱达荷大学毕业证成绩单原版一比一
 
1:1原版定制美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
1:1原版定制美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree1:1原版定制美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
1:1原版定制美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
 
专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国旧金山艺术学院毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
 
Presentation.pptxjnfoigneoifnvoeifnvklfnvf
Presentation.pptxjnfoigneoifnvoeifnvklfnvfPresentation.pptxjnfoigneoifnvoeifnvklfnvf
Presentation.pptxjnfoigneoifnvoeifnvklfnvf
 
NO1 WorldWide kala jadu Love Marriage Black Magic Punjab Powerful Black Magic...
NO1 WorldWide kala jadu Love Marriage Black Magic Punjab Powerful Black Magic...NO1 WorldWide kala jadu Love Marriage Black Magic Punjab Powerful Black Magic...
NO1 WorldWide kala jadu Love Marriage Black Magic Punjab Powerful Black Magic...
 
Papular No 1 Online Istikhara Amil Baba Pakistan Amil Baba In Karachi Amil B...
Papular No 1 Online Istikhara Amil Baba Pakistan  Amil Baba In Karachi Amil B...Papular No 1 Online Istikhara Amil Baba Pakistan  Amil Baba In Karachi Amil B...
Papular No 1 Online Istikhara Amil Baba Pakistan Amil Baba In Karachi Amil B...
 
Hifi Defence Colony Call Girls Service WhatsApp -> 9999965857 Available 24x7 ...
Hifi Defence Colony Call Girls Service WhatsApp -> 9999965857 Available 24x7 ...Hifi Defence Colony Call Girls Service WhatsApp -> 9999965857 Available 24x7 ...
Hifi Defence Colony Call Girls Service WhatsApp -> 9999965857 Available 24x7 ...
 
young call girls in Gtb Nagar,🔝 9953056974 🔝 escort Service
young call girls in Gtb Nagar,🔝 9953056974 🔝 escort Serviceyoung call girls in Gtb Nagar,🔝 9953056974 🔝 escort Service
young call girls in Gtb Nagar,🔝 9953056974 🔝 escort Service
 
CIVIL ENGINEERING
CIVIL ENGINEERINGCIVIL ENGINEERING
CIVIL ENGINEERING
 
专业一比一美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree专业一比一美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国加州州立大学东湾分校毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
 
Erfurt FH学位证,埃尔福特应用技术大学毕业证书1:1制作
Erfurt FH学位证,埃尔福特应用技术大学毕业证书1:1制作Erfurt FH学位证,埃尔福特应用技术大学毕业证书1:1制作
Erfurt FH学位证,埃尔福特应用技术大学毕业证书1:1制作
 
RBS学位证,鹿特丹商学院毕业证书1:1制作
RBS学位证,鹿特丹商学院毕业证书1:1制作RBS学位证,鹿特丹商学院毕业证书1:1制作
RBS学位证,鹿特丹商学院毕业证书1:1制作
 
young call girls in Khanpur,🔝 9953056974 🔝 escort Service
young call girls in  Khanpur,🔝 9953056974 🔝 escort Serviceyoung call girls in  Khanpur,🔝 9953056974 🔝 escort Service
young call girls in Khanpur,🔝 9953056974 🔝 escort Service
 
定制(USF学位证)旧金山大学毕业证成绩单原版一比一
定制(USF学位证)旧金山大学毕业证成绩单原版一比一定制(USF学位证)旧金山大学毕业证成绩单原版一比一
定制(USF学位证)旧金山大学毕业证成绩单原版一比一
 
Hifi Babe North Delhi Call Girl Service Fun Tonight
Hifi Babe North Delhi Call Girl Service Fun TonightHifi Babe North Delhi Call Girl Service Fun Tonight
Hifi Babe North Delhi Call Girl Service Fun Tonight
 
(办理学位证)韩国汉阳大学毕业证成绩单原版一比一
(办理学位证)韩国汉阳大学毕业证成绩单原版一比一(办理学位证)韩国汉阳大学毕业证成绩单原版一比一
(办理学位证)韩国汉阳大学毕业证成绩单原版一比一
 
Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...
Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...
Slim Call Girls Service Badshah Nagar * 9548273370 Naughty Call Girls Service...
 
威廉玛丽学院毕业证学位证成绩单-安全学历认证
威廉玛丽学院毕业证学位证成绩单-安全学历认证威廉玛丽学院毕业证学位证成绩单-安全学历认证
威廉玛丽学院毕业证学位证成绩单-安全学历认证
 

Arduino & node.js

  • 1. How to build a depression predictor (a.k.a. a belgian weather station) using Arduino & Node.js @stevenbeeckman #iotbe #njugbe
  • 2. In short Arduino IDE: arduino.cc/dowload Install StandardFirmata sketch on the Arduino npm install johnny-five write your script.js Run node script.js
  • 3. You need a host computer connected to the Arduino
  • 4. Let’s build a depression predictor (or a belgian weather station)
  • 5. Things we need A sensor Something to gather the sensor data Something to store the generated timeseries A visualisation
  • 7. Heroku + node.js + hapi.js + Tempo DB add-on photoresistor Arduino Uno Node.js + Johnny Five + request + forever TempoDB web app ADC http httpusb
  • 8. Heroku + node.js + hapi.js + Tempo DB add-on photoresistor Arduino Uno Node.js + Johnny Five + request + forever TempoDB web app ADC http httpusb
  • 9. MacGyver-ism: no resistors in house and no nearby shops to buy them from -> use a piezo as a resistor
  • 10. Heroku + node.js + hapi.js + Tempo DB add-on photoresistor Arduino Uno Node.js + Johnny Five + request + forever TempoDB web app ADC http httpusb
  • 11.
  • 12. Packages you need npm install --save johnny-five npm install --save request npm install -g forever usage: forever start script.js forever list (to see what’s running) https://github.com/stevenbeeckman/arduino-j5
  • 13. Heroku + node.js + hapi.js + Tempo DB add-on photoresistor Arduino Uno Node.js + Johnny Five + request + forever TempoDB web app ADC http httpusb
  • 14. Design Need a REST API over HTTP (Mandatory) POST new sensor values (Optional) GET overview of past sensor values Store data in a time series friendly database
  • 15. Packages you need "dependencies": { "hapi": "^6.5.1", "moment": "^2.8.2", "tempodb": "^1.0.0" } https://github.com/stevenbeeckman/iotbe-njugbe/
  • 16. Hosting This code can run on your own server or in the cloud. I ran it in the cloud, on Heroku and used the free TempoDB add-on.
  • 17.
  • 18. Some code var Hapi = require('hapi'); var server = new Hapi.Server(process.env.PORT || 3000); server.route({ method: 'GET' , path: '/' , handler: function(request, reply){ reply('Hello, Internet of Things fans!'); } }); server.start(function(){ console.log('Server running at:' + server.info.uri); }); heroku create git add index.js git commit -m “First deploy.” git push heroku master http://iotbe-njugbe.herokuapp.com/
  • 19. Writing to your TempoDB var TempoDBClient = require('tempodb').TempoDBClient; var tempodb = new TempoDBClient('heroku-5e2f03bd25cf424098426a8a21db26f3', process.env.TEMPODB_API_KEY, process.env. TEMPODB_API_SECRET, {hostname: process.env.TEMPODB_API_HOST, port: process.env.TEMPODB_API_PORT}); var moment = require('moment'); server.route({ method: 'POST' , path: '/sensor/{sensor_id}/measurement' , config: { handler: function(request, reply){ var newMeasurement = new Object(); newMeasurement.t = moment().format("YYYY-MM-DDTHH:mm:ss.SSSZZ"); newMeasurement.v = request.payload.value; var tempodb_data = new Array(); tempodb_data.push(newMeasurement); var series_key = 'sensor-' + request.params.sensor_id; tempodb.write_key(series_key, tempodb_data, function(error, result){ error ? reply(error) : reply(result); }); } } });
  • 20. Writing to your TempoDB var TempoDBClient = require('tempodb').TempoDBClient; var tempodb = new TempoDBClient('heroku-5e2f03bd25cf424098426a8a21db26f3', process.env.TEMPODB_API_KEY, process.env. TEMPODB_API_SECRET, {hostname: process.env.TEMPODB_API_HOST, port: process.env.TEMPODB_API_PORT}); var moment = require('moment'); server.route({ method: 'POST' , path: '/sensor/{sensor_id}/measurement' , config: { handler: function(request, reply){ var newMeasurement = new Object(); newMeasurement.t = moment().format("YYYY-MM-DDTHH:mm:ss.SSSZZ"); newMeasurement.v = request.payload.value; var tempodb_data = new Array(); tempodb_data.push(newMeasurement); var series_key = 'sensor-' + request.params.sensor_id; tempodb.write_key(series_key, tempodb_data, function(error, result){ error ? reply(error) : reply(result); }); } } }); Not documented: date must be formatted. new Date() will not work as is. Use moment.js for easy formatting.
  • 21. Writing to your TempoDB var TempoDBClient = require('tempodb').TempoDBClient; var tempodb = new TempoDBClient('heroku-5e2f03bd25cf424098426a8a21db26f3', process.env.TEMPODB_API_KEY, process.env. TEMPODB_API_SECRET, {hostname: process.env.TEMPODB_API_HOST, port: process.env.TEMPODB_API_PORT}); var moment = require('moment'); server.route({ method: 'POST' , path: '/sensor/{sensor_id}/measurement' , config: { handler: function(request, reply){ var newMeasurement = new Object(); newMeasurement.t = moment().format("YYYY-MM-DDTHH:mm:ss.SSSZZ"); newMeasurement.v = request.payload.value; var tempodb_data = new Array(); tempodb_data.push(newMeasurement); var series_key = 'sensor-' + request.params.sensor_id; tempodb.write_key(series_key, tempodb_data, function(error, result){ error ? reply(error) : reply(result); }); } } }); Single key value pairs {t,v} must be wrapped in an Array too...
  • 22. Writing to your TempoDB var TempoDBClient = require('tempodb').TempoDBClient; var tempodb = new TempoDBClient('heroku-5e2f03bd25cf424098426a8a21db26f3', process.env.TEMPODB_API_KEY, process.env. TEMPODB_API_SECRET, {hostname: process.env.TEMPODB_API_HOST, port: process.env.TEMPODB_API_PORT}); var moment = require('moment'); server.route({ method: 'POST' , path: '/sensor/{sensor_id}/measurement' , config: { handler: function(request, reply){ var newMeasurement = new Object(); newMeasurement.t = moment().format("YYYY-MM-DDTHH:mm:ss.SSSZZ"); newMeasurement.v = request.payload.value; var tempodb_data = new Array(); tempodb_data.push(newMeasurement); var series_key = 'sensor-' + request.params.sensor_id; tempodb.write_key(series_key, tempodb_data, function(error, result){ error ? reply(error) : reply(result); }); } } }); Warning: You have to pass the TempoDB database name too, which is not documented!
  • 23. Heroku + node.js + hapi.js + Tempo DB add-on photoresistor Arduino Uno Node.js + Johnny Five + request + forever TempoDB web app ADC http httpusb
  • 24.
  • 25.