SlideShare a Scribd company logo
Building a serverless
sensor network in
Javascript
About Your Speaker
Josh Marinacci
Head of Developer Relations at PubNub
Very nasty cold
Keep it short
Sensor Network
● Small, fairly dumb devices connected to the Internet
● Collect data in realtime
● Do something with the data, in realtime
IoT-Enabled Smart Parking Meter
Building a Serverless Sensor Network in Javascript - Josh Marinacci
Sensor Options
● Adafruit.com
● Weather: (temperature, humidity, wind speed, etc.)
● Cameras
● Buttons and switches
Arduino MKR1000
Arduino MKR1000
● Built in WiFi
● Lots of IO
● Power Saving
● Built in LiPo
● Turn into Soft AP
● No host PC required
● Have to code in C
● pubnub.com/blog/tag/mkr1000
Building a Serverless Sensor Network in Javascript - Josh Marinacci
Arduino Uno
● Cheaper
● Mature
● Requires host PC
● Code in JavaScript on the host
Arduino Uno
Controlling with JavaScript
1. var five = require('johnny-five');
2. var board = new five.Board();
3.
4. board.on('ready', function() {
5. var led = new five.Led(13); // pin 13
6. led.blink(500); // 500ms interval
7. });
Controlling with JavaScript
1. pubnub.subscribe({
2. channel: 'smart-led' ,
3. callback: function(m) {
4. if(led) {
5. r = (m.color === 'red') ? m.brightness : r;
6. g = (m.color === 'green') ? m.brightness : g;
7. b = (m.color === 'blue') ? m.brightness : b;
8.
9. led.color({red: r, blue: b, green: g});
10.
11. console .log( 'color change to...' );
12. console .log( led.color() );
13. }
14. }
15. error: function(err) {console.log(err);}
16. });
Building a Serverless Sensor Network in Javascript - Josh Marinacci
Serverless Architecture
● Combine micro-services
● No server administration, hosting, owning, etc.
● Run code at higher level: Module, Object, Function
● Pay by usage
● Leverage microservices
● Not all or nothing. Usually hybrid.
PubNub
● Global Data Stream Network
● Low latency
● High security
● M:n
● 70+ SDKs
PubNub BLOCKS
● Computation in global Data Stream Network
● Just Javascript w/ Promises
● Distributed data store
● Secure: NodeJS + cgroups + DSN
● Web or CLI
● Fast, low latency
● Pay for just what you use
● Just released. Free until Dec.
EON: Charts + Maps
Creating Realtime Data Visualization
https://www.pubnub.com/developers/eon/
Building a Serverless Sensor Network in Javascript - Josh Marinacci
●
●
●
●
●
Building a Serverless Sensor Network in Javascript - Josh Marinacci
●
●
●
●
●
Building a Serverless Sensor Network in Javascript - Josh Marinacci
Building a Serverless Sensor Network in Javascript - Josh Marinacci
●
●
○
○
○
Light sensor
Temperature
sensor
potentiometer
var five = require('johnny-five');
five.Board().on('ready', function() {
var temperature = new five.Thermometer({
controller: 'DS18B20', pin: 2
});
photoresistor = new five.Sensor({
pin: 'A2', freq: 250
});
temperature.on('data', function() {
console.log(this.celsius + '°C', this.fahrenheit + '°F');
temp = this.celsius;
});
photoresistor.on('data', function() {
console.log('photoresistor: ' + this.value);
light = this.value;
});
setInterval(sendData, 3000);
Using Johnny-Five to get the data
from Arduino!
We’re going to publish the data
from sensors every 3 seconds
function sendData() {
var data = {
'temperature': temp,
'light': light
};
pubnub.publish({
channel: 'temperature-photoresistor',
message: data,
});
Publishing data to PubNub
<div id="chart">
<div id="light"></div>
<div id="temp"></div>
<div id="pot"></div>
</div>
<script type="text/javascript">
var pubnub = PUBNUB.init({
subscribe_key :'sub-c-d784e128-da7d-11e5-9511-0619f8945a4f'
eon.chart({
channel: 'temperature-photoresistor',
generate: {
bindto: '#light',
},
pubnub: pubnub,
transform: function(m) {
return {
eon: {
light: m.light
}
}
}
transform() takes raw data to
transform to fit in the schema that
EON understands!
{'temperature': 20,
'light': 350 };
Receive raw data
eon.chart({
channel: 'temperature-photoresistor',
generate: {
bindto: '#temp,
},
pubnub: pubnub,
transform: function(m) {
return {
eon: {
temp: m.temp
}
}
var five = require('johnny-five');
five.Board().on('ready', function() {
potentiometer.on('data', function() {
// value range 0 - 1023
console.log(this.value, this.raw);
pubnub.publish({
channel: 'potentiometer',
message: { eon: {
'potentiometer': this.value
Note:
I am sending the object differently
this time.
Instead of the raw data,
{pot: value}, I am publishing {eon:{pot:
value}}, so EON can read the data
directly.
eon.chart({
channel: 'potentiometer',
generate: {
bindto: '#pot',
data: {
type: 'gauge'
}
},
pubnub: pubnub
});
eon.chart({
channel: 'potentiometer',
generate: {
bindto: '#pot',
data: {
type:'gauge'
},
gauge: {
label:{
format: function(value, ratio){
return value; //returning here
the value, not in %
},
},
...
color: {
pattern: ['#FF0000', '#F6C600', '#60B044'],
threshold: {
values: [341, 682]
}
}
},
pubnub: pubnub
});
0 to 341 = red
342 to 682 = yellow
683 to 1023 = green
Building a Serverless Sensor Network in Javascript - Josh Marinacci
Building a Serverless Sensor Network in Javascript - Josh Marinacci
Building a Serverless Sensor Network in Javascript - Josh Marinacci
●
●
●
●
Building a Serverless Sensor Network in Javascript - Josh Marinacci
Building a Serverless Sensor Network in Javascript - Josh Marinacci

More Related Content

PDF
Using check json to monitor anything - monitoring house plants
PDF
Hands-on Labs: Raspberry Pi 2 + Windows 10 IoT Core
PPTX
Bare metal Javascript & GPIO programming in Linux
PDF
Raspberry Pi 2 + Windows 10 IoT Core + Node.js
PPTX
Thingsboard Gateway - Remote temperature monitoring tool for Industries
PDF
Banog meetup August 30th, network device property as code
PDF
Exploring Raspberry Pi
PDF
Abusing phones to make the internet of things - Wix UA Meetup
Using check json to monitor anything - monitoring house plants
Hands-on Labs: Raspberry Pi 2 + Windows 10 IoT Core
Bare metal Javascript & GPIO programming in Linux
Raspberry Pi 2 + Windows 10 IoT Core + Node.js
Thingsboard Gateway - Remote temperature monitoring tool for Industries
Banog meetup August 30th, network device property as code
Exploring Raspberry Pi
Abusing phones to make the internet of things - Wix UA Meetup

Similar to Building a Serverless Sensor Network in Javascript - Josh Marinacci (20)

PPT
Server/Client Remote platform logger.
PPTX
PPT on Weather Monitoring System-converted (1).pptx
PDF
Android Things in action
PPTX
M.Tech Internet of Things Unit - III.pptx
PPTX
Building a Raspberry Pi Robot with Dot NET 7, Blazor and SignalR - TechDays 2023
PPTX
IoT on Raspberry Pi
PDF
Remote CAD that Feels Local by Adam Chalmers & Adam Sunderland
PDF
Cc internet of things @ Thomas More
PDF
IoT Session Thomas More
PPTX
Intel galileo gen 2
ODP
Rete di casa e raspberry pi - Home network and Raspberry Pi
PPTX
introduction to Raspberry pi
KEY
Android and Arduio mixed with Breakout js
PDF
Android Things, from mobile apps to physical world - Stefano Sanna - Giovanni...
PDF
Android Things, from mobile apps to physical world by Giovanni Di Gialluca an...
PDF
[HTML5DevConf SF] Hardware Hacking for Javascript Developers
PPTX
Free5 gc installation
ODP
Nagios Conference 2013 - Mike Weber - Distributed Monitoring with Raspberry Pi
PDF
Raspberry Pi - HW/SW Application Development
PDF
Internet Protocol Deep-Dive
Server/Client Remote platform logger.
PPT on Weather Monitoring System-converted (1).pptx
Android Things in action
M.Tech Internet of Things Unit - III.pptx
Building a Raspberry Pi Robot with Dot NET 7, Blazor and SignalR - TechDays 2023
IoT on Raspberry Pi
Remote CAD that Feels Local by Adam Chalmers & Adam Sunderland
Cc internet of things @ Thomas More
IoT Session Thomas More
Intel galileo gen 2
Rete di casa e raspberry pi - Home network and Raspberry Pi
introduction to Raspberry pi
Android and Arduio mixed with Breakout js
Android Things, from mobile apps to physical world - Stefano Sanna - Giovanni...
Android Things, from mobile apps to physical world by Giovanni Di Gialluca an...
[HTML5DevConf SF] Hardware Hacking for Javascript Developers
Free5 gc installation
Nagios Conference 2013 - Mike Weber - Distributed Monitoring with Raspberry Pi
Raspberry Pi - HW/SW Application Development
Internet Protocol Deep-Dive
Ad

More from WithTheBest (20)

PDF
Riccardo Vittoria
PPTX
Recreating history in virtual reality
PDF
Engaging and sharing your VR experience
PDF
How to survive the early days of VR as an Indie Studio
PDF
Mixed reality 101
PDF
Unlocking Human Potential with Immersive Technology
PPTX
Building your own video devices
PPTX
Maximizing performance of 3 d user generated assets in unity
PPTX
Wizdish rovr
PPTX
Haptics & amp; null space vr
PPTX
How we use vr to break the laws of physics
PPTX
The Virtual Self
PPTX
You dont have to be mad to do VR and AR ... but it helps
PDF
Omnivirt overview
PDF
VR Interactions - Jason Jerald
PDF
Japheth Funding your startup - dating the devil
PDF
Transported vr the virtual reality platform for real estate
PDF
Measuring Behavior in VR - Rob Merki Cognitive VR
PDF
Global demand for Mixed Realty (VR/AR) content is about to explode.
PDF
VR, a new technology over 40,000 years old
Riccardo Vittoria
Recreating history in virtual reality
Engaging and sharing your VR experience
How to survive the early days of VR as an Indie Studio
Mixed reality 101
Unlocking Human Potential with Immersive Technology
Building your own video devices
Maximizing performance of 3 d user generated assets in unity
Wizdish rovr
Haptics & amp; null space vr
How we use vr to break the laws of physics
The Virtual Self
You dont have to be mad to do VR and AR ... but it helps
Omnivirt overview
VR Interactions - Jason Jerald
Japheth Funding your startup - dating the devil
Transported vr the virtual reality platform for real estate
Measuring Behavior in VR - Rob Merki Cognitive VR
Global demand for Mixed Realty (VR/AR) content is about to explode.
VR, a new technology over 40,000 years old
Ad

Recently uploaded (20)

PPTX
TLE Review Electricity (Electricity).pptx
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
STKI Israel Market Study 2025 version august
PPTX
Chapter 5: Probability Theory and Statistics
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PPTX
The various Industrial Revolutions .pptx
PDF
August Patch Tuesday
PDF
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
project resource management chapter-09.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
Developing a website for English-speaking practice to English as a foreign la...
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
TLE Review Electricity (Electricity).pptx
NewMind AI Weekly Chronicles – August ’25 Week III
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
Group 1 Presentation -Planning and Decision Making .pptx
STKI Israel Market Study 2025 version august
Chapter 5: Probability Theory and Statistics
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
The various Industrial Revolutions .pptx
August Patch Tuesday
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
Programs and apps: productivity, graphics, security and other tools
A novel scalable deep ensemble learning framework for big data classification...
DP Operators-handbook-extract for the Mautical Institute
project resource management chapter-09.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Module 1.ppt Iot fundamentals and Architecture
Developing a website for English-speaking practice to English as a foreign la...
Final SEM Unit 1 for mit wpu at pune .pptx
Assigned Numbers - 2025 - Bluetooth® Document

Building a Serverless Sensor Network in Javascript - Josh Marinacci

  • 1. Building a serverless sensor network in Javascript
  • 2. About Your Speaker Josh Marinacci Head of Developer Relations at PubNub Very nasty cold Keep it short
  • 3. Sensor Network ● Small, fairly dumb devices connected to the Internet ● Collect data in realtime ● Do something with the data, in realtime
  • 6. Sensor Options ● Adafruit.com ● Weather: (temperature, humidity, wind speed, etc.) ● Cameras ● Buttons and switches
  • 8. Arduino MKR1000 ● Built in WiFi ● Lots of IO ● Power Saving ● Built in LiPo ● Turn into Soft AP ● No host PC required ● Have to code in C ● pubnub.com/blog/tag/mkr1000
  • 10. Arduino Uno ● Cheaper ● Mature ● Requires host PC ● Code in JavaScript on the host
  • 12. Controlling with JavaScript 1. var five = require('johnny-five'); 2. var board = new five.Board(); 3. 4. board.on('ready', function() { 5. var led = new five.Led(13); // pin 13 6. led.blink(500); // 500ms interval 7. });
  • 13. Controlling with JavaScript 1. pubnub.subscribe({ 2. channel: 'smart-led' , 3. callback: function(m) { 4. if(led) { 5. r = (m.color === 'red') ? m.brightness : r; 6. g = (m.color === 'green') ? m.brightness : g; 7. b = (m.color === 'blue') ? m.brightness : b; 8. 9. led.color({red: r, blue: b, green: g}); 10. 11. console .log( 'color change to...' ); 12. console .log( led.color() ); 13. } 14. } 15. error: function(err) {console.log(err);} 16. });
  • 15. Serverless Architecture ● Combine micro-services ● No server administration, hosting, owning, etc. ● Run code at higher level: Module, Object, Function ● Pay by usage ● Leverage microservices ● Not all or nothing. Usually hybrid.
  • 16. PubNub ● Global Data Stream Network ● Low latency ● High security ● M:n ● 70+ SDKs
  • 17. PubNub BLOCKS ● Computation in global Data Stream Network ● Just Javascript w/ Promises ● Distributed data store ● Secure: NodeJS + cgroups + DSN ● Web or CLI ● Fast, low latency ● Pay for just what you use ● Just released. Free until Dec.
  • 18. EON: Charts + Maps Creating Realtime Data Visualization https://www.pubnub.com/developers/eon/
  • 27. var five = require('johnny-five'); five.Board().on('ready', function() { var temperature = new five.Thermometer({ controller: 'DS18B20', pin: 2 }); photoresistor = new five.Sensor({ pin: 'A2', freq: 250 }); temperature.on('data', function() { console.log(this.celsius + '°C', this.fahrenheit + '°F'); temp = this.celsius; }); photoresistor.on('data', function() { console.log('photoresistor: ' + this.value); light = this.value; }); setInterval(sendData, 3000); Using Johnny-Five to get the data from Arduino! We’re going to publish the data from sensors every 3 seconds
  • 28. function sendData() { var data = { 'temperature': temp, 'light': light }; pubnub.publish({ channel: 'temperature-photoresistor', message: data, }); Publishing data to PubNub
  • 29. <div id="chart"> <div id="light"></div> <div id="temp"></div> <div id="pot"></div> </div> <script type="text/javascript"> var pubnub = PUBNUB.init({ subscribe_key :'sub-c-d784e128-da7d-11e5-9511-0619f8945a4f'
  • 30. eon.chart({ channel: 'temperature-photoresistor', generate: { bindto: '#light', }, pubnub: pubnub, transform: function(m) { return { eon: { light: m.light } } } transform() takes raw data to transform to fit in the schema that EON understands! {'temperature': 20, 'light': 350 }; Receive raw data
  • 31. eon.chart({ channel: 'temperature-photoresistor', generate: { bindto: '#temp, }, pubnub: pubnub, transform: function(m) { return { eon: { temp: m.temp } }
  • 32. var five = require('johnny-five'); five.Board().on('ready', function() { potentiometer.on('data', function() { // value range 0 - 1023 console.log(this.value, this.raw); pubnub.publish({ channel: 'potentiometer', message: { eon: { 'potentiometer': this.value Note: I am sending the object differently this time. Instead of the raw data, {pot: value}, I am publishing {eon:{pot: value}}, so EON can read the data directly.
  • 33. eon.chart({ channel: 'potentiometer', generate: { bindto: '#pot', data: { type: 'gauge' } }, pubnub: pubnub });
  • 34. eon.chart({ channel: 'potentiometer', generate: { bindto: '#pot', data: { type:'gauge' }, gauge: { label:{ format: function(value, ratio){ return value; //returning here the value, not in % }, }, ... color: { pattern: ['#FF0000', '#F6C600', '#60B044'], threshold: { values: [341, 682] } } }, pubnub: pubnub }); 0 to 341 = red 342 to 682 = yellow 683 to 1023 = green