SlideShare a Scribd company logo
1 of 64
Download to read offline
IOTDB.org 
• 
Control all the Things 
with Node-JS
David Janes 
@dpjanes 
davidjanes@iotdb.org 
http://iotdb.org/social/imadeit/ 
November 2014
Introduction
N.B. 
• Demo example code on github 
• dpjanes/ 
• iotdb-examples/ 
• demos/ 
• 2014-11-fsto/
What is it? 
{ 
"on" : true, 
"temperature" : 225 
}
What does each field 
mean?
Control or 
Measurement? 
• Does on mean: 
• Turn it on? or 
• Is it on? 
• Does temperature mean: 
• Set the temperature? or 
• What is the temperature?
Units 
• What does temperature refer to? 
• degrees Celsius, Fahrenheit … or Kelvin?
What does the whole 
message represent?
What are we talking 
about … or with? 
• An oven? 
• A toaster? 
• A sensor in the Large Hadron Collider?
Solve “the Basket Full 
of Remotes Apps 
Problem”
Solve the N-standards 
• Open Interconnect 
Consortium 
• Thread Group 
• AllSeen Alliance 
• HyperCat Consortium 
• Industrial Internet 
Consortium 
• IoT-GSI) from ITU-T 
• oneM2M 
• Open Mobile Alliance 
• Internet of Things (IEE) 
• IETF 
• IPSO Alliance
XKCD
IOTDB(.org)
Semantic Vocab 
• Formal definitions 
• https://iotdb.org/pub 
• JSON-LD
Models 
• https://iotdb.org/iotdb 
• https://github.com/dpjanes/iotdb-models
Node-IOTDB
IOTDB Stack 
• Client Program 
• Node-IOTDB 
• Models 
• Drivers 
• Libraries 
•simple_on.js 
•require('iotdb') 
•WeMoSwitch 
•iot-driver:upnp 
•upnplib
Client Program 
simple_red 
iot 
.connect() 
.set(':color', 'red');
require(‘iotdb’) 
• locates Models, Drivers, Stores,… 
• loads & maintains user configuration 
• connects to iotdb.org (sometimes) 
• manages Things (huge deal … too many 
things to go into in detail)
Model (I) 
• Semantic description of Things 
• (can be) written in JavaScript 
• actually compiles to JSON-LD (with some 
restrained JavaScript) 
• Node independent!
Model (II) 
iotdb.make_model('WeMoSwitch') 
.facet(":device.switch") 
.product(“http://www.belkin.com/…”) 
.name("WeMo Switch") 
.description("Belkin WeMo Switch") 
.attribute( 
iotdb.make_boolean(":on") 
.name("on / off") 
.control() 
)
Model (III) 
.driver_out(function(paramd) { 
if (paramd.thingd.on !== undefined) { 
paramd.driverd['urn:Belkin:service:basicevent:1'] = { 
'SetBinaryState' : { 
'BinaryState' : paramd.thingd.on ? 1 : 0 
} 
} 
} 
})
Drivers 
iot-driver:upnp 
• Binds Models to the code that actually 
“does the work” 
• discovery 
• static configuration 
• dynamic / environmental
Libraries 
• What developers usually program against 
• We’ve rewritten a number of libraries to 
make them more reliable
Demos
simple_on 
things = iot.connect() 
things.set(':on', true);
simple_off 
things = iot.connect() 
things.set(‘:on’, false);
simple_model 
iot 
.connect(‘HueLight') 
.set(':on', true);
Metadata
Select Things 
• select Things by (e.g.) 
• Model 
• name 
• number 
• place 
• facet
meta_dump 
var things = iot.connect(); 
iot.on_things(function() { 
console.log(things.metas()); 
});
meta_model 
iot.connect() 
.with_model("TCPConnectedLight") 
.set(':on', false)
meta_name 
iot 
.connect() 
.with_name("Hue Lamp 2") 
.set(':color', 'purple')
meta_number 
iot 
.connect() 
.with_number(3) 
.set(':color', 'cyan')
meta_place 
iot 
.connect() 
.with_room("David Bedroom") 
.with_floor("Second Floor") 
.set(':color', 'green')
meta_facet 
iot 
.connect() 
.with_facet(":device.lighting") 
.set(':on', true);
where does Metadata 
come from? 
• Metadata comes from several places 
• can be altered in code 
• can be persisted to locally / to disk 
• can be retrieved from iotdb.org 
• “inherent” in the Model / Driver
Events
two types of events 
• thing.on(key, callback) 
• thing.on_change(callback)
event_brightness 
var lights = iot.connect() 
var input = iot.connect({ 
model: "FirmataInputUnit", 
pin: 0 
}); 
input.on(":value", function(thing, attribute, value) { 
lights.set(':brightness', value); 
})
event_fob 
var things = iot.connect(); 
iot 
.connect('TIKeyFob') 
.on('left', function() { 
things.set(':on', true); 
}) 
.on('right', function() { 
things.set(':on', false); 
})
Arduino / Firmata
firmata_cycle 
var things = iot 
.connect() 
.connect({ 
model: "FirmataNeoPixel", 
pin: 6, 
n: 16 
}) 
var colors = [ "red", "green", "blue", "white", "black" ]; 
var ci = 0; 
setInterval(function() { 
things.set(":color", colors[ci++ % colors.length]); 
}, 2500)
firmata_neopixel 
var n = 16; 
var leds = iot.connect({ 
model: "FirmataNeoPixel", 
pin: 6, 
n: n 
}) 
var c = new iotdb.libs.Color() 
var ci = 0; 
var cf = 0; 
setInterval(function() { 
c.set_hsl(cf, 1, 0.5) 
cf += 0.015; 
if (cf > 1) cf = 0; 
leds 
.with_number(ci++ % n) 
.set(":color", c.get_hex()) 
; 
}, 50)
Arduino Models 
• FirmataChainableLED 
• FirmataDHT11 
• FirmataGroveThermistor 
• FirmataInputBoolean 
• FirmataInputUnit 
• FirmataLightDimmer 
• FirmataLightSensor 
• FirmataLightSimple 
• FirmataMotionSensor 
• FirmataNeoPixel 
• FirmataOn 
• FirmataOutputBoolean
Stores
Available Stores 
• dweet 
• http 
• mqtt 
• phant 
• pubnub 
• thingspeak
store_phant 
var input = iot.connect('TIKeyFob') 
var store = iot 
.store('phant') 
.track(input) 
https://data.sparkfun.com/streams/aGNjQK9RwZHgEmx089Lg
store_mqtt 
var input = iot.connect({ 
model: "FirmataInputUnit", 
pin: 0 
}); 
var store = iot 
.store('mqtt') 
.track(input) 
mqtt.iotdb.org u/dpjanes/#
Transmogrifiers
What if we have the 
wrong thing? 
• Have Celsius but want Fahrenheit 
• Want to set brightness but only have color 
• What if brightness is 0-100 on one device 
and 0-1 on another 
• Average data? Max data over time? &c…
trans_fahrenheit 
var t_c = iot.connect("FirmataDHT11") 
t_c.on('temperature', function(thing, attribute, value) { 
console.log("+ temperature (C)", value) 
}) 
var t_f = t_c.transmogrify( 
iot.transmogrifier(":imperial/fahrenheit")) 
t_f.on('temperature', function(thing, attribute, value) { 
console.log("+ temperature (F)", value) 
})
warning 
• transmogrifiers are very much a work in 
progress! 
• not even pushed to npm yet
Takeaways
IOTDB 
• Semantic description of how things work
Node-IOTDB 
• Powerful language for controlling things 
• Builds on IOTDB concepts 
• Strong alpha 
• Join! Help!
Modeling 
{ 
"@context": "./meta-iri.jsonld", 
"on": true, 
"temperature": 225 
} 
Note: @context is just one way of doing this!
N.B. 
• The data does not have to be JSON! 
• You don’t need to have IOTDB! 
• You don’t need to use IOTDB IRIs (but you 
should) 
• https://iotdb.org/pub/
Additional Resources 
• Many examples + House of Janes 
https://github.com/dpjanes/iotdb-examples 
• Getting started 
https://iotdb.org/docs/node/getting-started 
• Concepts 
https://medium.com/@dpjanes
One last point 
• Don’t be misled by the simplicity! 
• I worked backward from “what do I want 
to do” to get the code 
• Way more things than I demoed today 
• I want to work with you!
Get in touch! 
David Janes 
@dpjanes 
davidjanes@iotdb.org 
http://iotdb.org/social/imadeit/

More Related Content

Similar to Control all the Things with Node-JS

Firefox OS, HTML5 to the next level - Python Montreal - 2014-05-12
Firefox OS, HTML5 to the next level - Python Montreal - 2014-05-12Firefox OS, HTML5 to the next level - Python Montreal - 2014-05-12
Firefox OS, HTML5 to the next level - Python Montreal - 2014-05-12Frédéric Harper
 
Firefox OS, fixing the mobile web - FITC Toronto - 2014-04-28
Firefox OS, fixing the mobile web - FITC Toronto - 2014-04-28Firefox OS, fixing the mobile web - FITC Toronto - 2014-04-28
Firefox OS, fixing the mobile web - FITC Toronto - 2014-04-28Frédéric Harper
 
System insight without Interference
System insight without InterferenceSystem insight without Interference
System insight without InterferenceTony Tam
 
掀起 Swift 的面紗
掀起 Swift 的面紗掀起 Swift 的面紗
掀起 Swift 的面紗Pofat Tseng
 
IL2CPP: Debugging and Profiling
IL2CPP: Debugging and ProfilingIL2CPP: Debugging and Profiling
IL2CPP: Debugging and Profilingjoncham
 
Building the IOT Platform as a Service
Building the IOT Platform as a ServiceBuilding the IOT Platform as a Service
Building the IOT Platform as a ServiceJesus Rodriguez
 
Chapter i c#(console application and programming)
Chapter i c#(console application and programming)Chapter i c#(console application and programming)
Chapter i c#(console application and programming)Chhom Karath
 
Firefox OS: HTML5 sur les stéroïdes - HTML5mtl - 2014-04-22
Firefox OS: HTML5 sur les stéroïdes - HTML5mtl - 2014-04-22Firefox OS: HTML5 sur les stéroïdes - HTML5mtl - 2014-04-22
Firefox OS: HTML5 sur les stéroïdes - HTML5mtl - 2014-04-22Frédéric Harper
 
HTML for the Mobile Web, Firefox OS - All Things Open - 2014-10-22
HTML for the Mobile Web, Firefox OS - All Things Open - 2014-10-22HTML for the Mobile Web, Firefox OS - All Things Open - 2014-10-22
HTML for the Mobile Web, Firefox OS - All Things Open - 2014-10-22Frédéric Harper
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformationLars Marius Garshol
 
Getting Started with the Internet of Things - Allianz Hackrisk Hackathon 29/...
Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/...Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/...
Getting Started with the Internet of Things - Allianz Hackrisk Hackathon 29/...The Internet of Things Methodology
 
Android and Arduio mixed with Breakout js
Android and Arduio mixed with Breakout jsAndroid and Arduio mixed with Breakout js
Android and Arduio mixed with Breakout jsmusart Park
 
HTML, not just for desktops: Firefox OS - Congreso Universitario Móvil - 201...
HTML, not just for desktops: Firefox OS - Congreso Universitario Móvil - 201...HTML, not just for desktops: Firefox OS - Congreso Universitario Móvil - 201...
HTML, not just for desktops: Firefox OS - Congreso Universitario Móvil - 201...Frédéric Harper
 
Using Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systemsUsing Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systemsSerge Stinckwich
 
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07Frédéric Harper
 
Java Hurdling: Obstacles and Techniques in Java Client Penetration-Testing
Java Hurdling: Obstacles and Techniques in Java Client Penetration-TestingJava Hurdling: Obstacles and Techniques in Java Client Penetration-Testing
Java Hurdling: Obstacles and Techniques in Java Client Penetration-TestingTal Melamed
 
Reactive programming
Reactive programmingReactive programming
Reactive programmingNick Hodge
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeWim Godden
 
Codestrong 2012 breakout session hacking titanium
Codestrong 2012 breakout session   hacking titaniumCodestrong 2012 breakout session   hacking titanium
Codestrong 2012 breakout session hacking titaniumAxway Appcelerator
 

Similar to Control all the Things with Node-JS (20)

Firefox OS, HTML5 to the next level - Python Montreal - 2014-05-12
Firefox OS, HTML5 to the next level - Python Montreal - 2014-05-12Firefox OS, HTML5 to the next level - Python Montreal - 2014-05-12
Firefox OS, HTML5 to the next level - Python Montreal - 2014-05-12
 
Firefox OS, fixing the mobile web - FITC Toronto - 2014-04-28
Firefox OS, fixing the mobile web - FITC Toronto - 2014-04-28Firefox OS, fixing the mobile web - FITC Toronto - 2014-04-28
Firefox OS, fixing the mobile web - FITC Toronto - 2014-04-28
 
System insight without Interference
System insight without InterferenceSystem insight without Interference
System insight without Interference
 
掀起 Swift 的面紗
掀起 Swift 的面紗掀起 Swift 的面紗
掀起 Swift 的面紗
 
IL2CPP: Debugging and Profiling
IL2CPP: Debugging and ProfilingIL2CPP: Debugging and Profiling
IL2CPP: Debugging and Profiling
 
Building the IOT Platform as a Service
Building the IOT Platform as a ServiceBuilding the IOT Platform as a Service
Building the IOT Platform as a Service
 
Chapter i c#(console application and programming)
Chapter i c#(console application and programming)Chapter i c#(console application and programming)
Chapter i c#(console application and programming)
 
Firefox OS: HTML5 sur les stéroïdes - HTML5mtl - 2014-04-22
Firefox OS: HTML5 sur les stéroïdes - HTML5mtl - 2014-04-22Firefox OS: HTML5 sur les stéroïdes - HTML5mtl - 2014-04-22
Firefox OS: HTML5 sur les stéroïdes - HTML5mtl - 2014-04-22
 
HTML for the Mobile Web, Firefox OS - All Things Open - 2014-10-22
HTML for the Mobile Web, Firefox OS - All Things Open - 2014-10-22HTML for the Mobile Web, Firefox OS - All Things Open - 2014-10-22
HTML for the Mobile Web, Firefox OS - All Things Open - 2014-10-22
 
Polyglot
PolyglotPolyglot
Polyglot
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformation
 
Getting Started with the Internet of Things - Allianz Hackrisk Hackathon 29/...
Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/...Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/...
Getting Started with the Internet of Things - Allianz Hackrisk Hackathon 29/...
 
Android and Arduio mixed with Breakout js
Android and Arduio mixed with Breakout jsAndroid and Arduio mixed with Breakout js
Android and Arduio mixed with Breakout js
 
HTML, not just for desktops: Firefox OS - Congreso Universitario Móvil - 201...
HTML, not just for desktops: Firefox OS - Congreso Universitario Móvil - 201...HTML, not just for desktops: Firefox OS - Congreso Universitario Móvil - 201...
HTML, not just for desktops: Firefox OS - Congreso Universitario Móvil - 201...
 
Using Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systemsUsing Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systems
 
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
 
Java Hurdling: Obstacles and Techniques in Java Client Penetration-Testing
Java Hurdling: Obstacles and Techniques in Java Client Penetration-TestingJava Hurdling: Obstacles and Techniques in Java Client Penetration-Testing
Java Hurdling: Obstacles and Techniques in Java Client Penetration-Testing
 
Reactive programming
Reactive programmingReactive programming
Reactive programming
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
Codestrong 2012 breakout session hacking titanium
Codestrong 2012 breakout session   hacking titaniumCodestrong 2012 breakout session   hacking titanium
Codestrong 2012 breakout session hacking titanium
 

Recently uploaded

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 

Recently uploaded (20)

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 

Control all the Things with Node-JS

  • 1. IOTDB.org • Control all the Things with Node-JS
  • 2. David Janes @dpjanes davidjanes@iotdb.org http://iotdb.org/social/imadeit/ November 2014
  • 4. N.B. • Demo example code on github • dpjanes/ • iotdb-examples/ • demos/ • 2014-11-fsto/
  • 5. What is it? { "on" : true, "temperature" : 225 }
  • 6. What does each field mean?
  • 7. Control or Measurement? • Does on mean: • Turn it on? or • Is it on? • Does temperature mean: • Set the temperature? or • What is the temperature?
  • 8. Units • What does temperature refer to? • degrees Celsius, Fahrenheit … or Kelvin?
  • 9. What does the whole message represent?
  • 10. What are we talking about … or with? • An oven? • A toaster? • A sensor in the Large Hadron Collider?
  • 11. Solve “the Basket Full of Remotes Apps Problem”
  • 12.
  • 13. Solve the N-standards • Open Interconnect Consortium • Thread Group • AllSeen Alliance • HyperCat Consortium • Industrial Internet Consortium • IoT-GSI) from ITU-T • oneM2M • Open Mobile Alliance • Internet of Things (IEE) • IETF • IPSO Alliance
  • 14. XKCD
  • 16. Semantic Vocab • Formal definitions • https://iotdb.org/pub • JSON-LD
  • 17. Models • https://iotdb.org/iotdb • https://github.com/dpjanes/iotdb-models
  • 19. IOTDB Stack • Client Program • Node-IOTDB • Models • Drivers • Libraries •simple_on.js •require('iotdb') •WeMoSwitch •iot-driver:upnp •upnplib
  • 20. Client Program simple_red iot .connect() .set(':color', 'red');
  • 21. require(‘iotdb’) • locates Models, Drivers, Stores,… • loads & maintains user configuration • connects to iotdb.org (sometimes) • manages Things (huge deal … too many things to go into in detail)
  • 22. Model (I) • Semantic description of Things • (can be) written in JavaScript • actually compiles to JSON-LD (with some restrained JavaScript) • Node independent!
  • 23. Model (II) iotdb.make_model('WeMoSwitch') .facet(":device.switch") .product(“http://www.belkin.com/…”) .name("WeMo Switch") .description("Belkin WeMo Switch") .attribute( iotdb.make_boolean(":on") .name("on / off") .control() )
  • 24. Model (III) .driver_out(function(paramd) { if (paramd.thingd.on !== undefined) { paramd.driverd['urn:Belkin:service:basicevent:1'] = { 'SetBinaryState' : { 'BinaryState' : paramd.thingd.on ? 1 : 0 } } } })
  • 25. Drivers iot-driver:upnp • Binds Models to the code that actually “does the work” • discovery • static configuration • dynamic / environmental
  • 26. Libraries • What developers usually program against • We’ve rewritten a number of libraries to make them more reliable
  • 27. Demos
  • 28. simple_on things = iot.connect() things.set(':on', true);
  • 29. simple_off things = iot.connect() things.set(‘:on’, false);
  • 32. Select Things • select Things by (e.g.) • Model • name • number • place • facet
  • 33. meta_dump var things = iot.connect(); iot.on_things(function() { console.log(things.metas()); });
  • 35. meta_name iot .connect() .with_name("Hue Lamp 2") .set(':color', 'purple')
  • 36. meta_number iot .connect() .with_number(3) .set(':color', 'cyan')
  • 37. meta_place iot .connect() .with_room("David Bedroom") .with_floor("Second Floor") .set(':color', 'green')
  • 38. meta_facet iot .connect() .with_facet(":device.lighting") .set(':on', true);
  • 39. where does Metadata come from? • Metadata comes from several places • can be altered in code • can be persisted to locally / to disk • can be retrieved from iotdb.org • “inherent” in the Model / Driver
  • 41. two types of events • thing.on(key, callback) • thing.on_change(callback)
  • 42. event_brightness var lights = iot.connect() var input = iot.connect({ model: "FirmataInputUnit", pin: 0 }); input.on(":value", function(thing, attribute, value) { lights.set(':brightness', value); })
  • 43. event_fob var things = iot.connect(); iot .connect('TIKeyFob') .on('left', function() { things.set(':on', true); }) .on('right', function() { things.set(':on', false); })
  • 45. firmata_cycle var things = iot .connect() .connect({ model: "FirmataNeoPixel", pin: 6, n: 16 }) var colors = [ "red", "green", "blue", "white", "black" ]; var ci = 0; setInterval(function() { things.set(":color", colors[ci++ % colors.length]); }, 2500)
  • 46. firmata_neopixel var n = 16; var leds = iot.connect({ model: "FirmataNeoPixel", pin: 6, n: n }) var c = new iotdb.libs.Color() var ci = 0; var cf = 0; setInterval(function() { c.set_hsl(cf, 1, 0.5) cf += 0.015; if (cf > 1) cf = 0; leds .with_number(ci++ % n) .set(":color", c.get_hex()) ; }, 50)
  • 47. Arduino Models • FirmataChainableLED • FirmataDHT11 • FirmataGroveThermistor • FirmataInputBoolean • FirmataInputUnit • FirmataLightDimmer • FirmataLightSensor • FirmataLightSimple • FirmataMotionSensor • FirmataNeoPixel • FirmataOn • FirmataOutputBoolean
  • 49. Available Stores • dweet • http • mqtt • phant • pubnub • thingspeak
  • 50. store_phant var input = iot.connect('TIKeyFob') var store = iot .store('phant') .track(input) https://data.sparkfun.com/streams/aGNjQK9RwZHgEmx089Lg
  • 51. store_mqtt var input = iot.connect({ model: "FirmataInputUnit", pin: 0 }); var store = iot .store('mqtt') .track(input) mqtt.iotdb.org u/dpjanes/#
  • 53.
  • 54. What if we have the wrong thing? • Have Celsius but want Fahrenheit • Want to set brightness but only have color • What if brightness is 0-100 on one device and 0-1 on another • Average data? Max data over time? &c…
  • 55. trans_fahrenheit var t_c = iot.connect("FirmataDHT11") t_c.on('temperature', function(thing, attribute, value) { console.log("+ temperature (C)", value) }) var t_f = t_c.transmogrify( iot.transmogrifier(":imperial/fahrenheit")) t_f.on('temperature', function(thing, attribute, value) { console.log("+ temperature (F)", value) })
  • 56. warning • transmogrifiers are very much a work in progress! • not even pushed to npm yet
  • 58. IOTDB • Semantic description of how things work
  • 59. Node-IOTDB • Powerful language for controlling things • Builds on IOTDB concepts • Strong alpha • Join! Help!
  • 60. Modeling { "@context": "./meta-iri.jsonld", "on": true, "temperature": 225 } Note: @context is just one way of doing this!
  • 61. N.B. • The data does not have to be JSON! • You don’t need to have IOTDB! • You don’t need to use IOTDB IRIs (but you should) • https://iotdb.org/pub/
  • 62. Additional Resources • Many examples + House of Janes https://github.com/dpjanes/iotdb-examples • Getting started https://iotdb.org/docs/node/getting-started • Concepts https://medium.com/@dpjanes
  • 63. One last point • Don’t be misled by the simplicity! • I worked backward from “what do I want to do” to get the code • Way more things than I demoed today • I want to work with you!
  • 64. Get in touch! David Janes @dpjanes davidjanes@iotdb.org http://iotdb.org/social/imadeit/