SlideShare a Scribd company logo
1 of 58
Download to read offline
@matteocollina
   matteocollina.com




  Building a multi-protocol
  broker for the Internet of
  Things using node.js

Node.js Conference - Brescia 2012/11/09
How many people will own
a smartphone by 2014



       1.000.000.000
Did you see
it coming




   http://www.flickr.com/photos/12738000@N00/360231193/
They didn’t!


  ...
What's next
              (hint: it's a big number)




    50.000.000.000
50.000.000.000




1.000.000.000
"Things"
Let's experiment
Goal:


   I want to
   chat with
   my house
>: hi house
hi matteo

>: what's the
temperature?
20
>: 4 8 15 16 23 42


 If you don’t
 understand
 this, you are
 not a geek!
Enter Hubot




              Hubot © 2012 GitHub Inc. All rights
A programmable robot
that is controlled through
chat



                      Hubot © 2012 GitHub Inc. All rights
We can supercharge our house with hubot
We can supercharge our house with hubot


                  How
module.exports = (robot) ->

  robot.respond /what’s the temperature?/i, (msg) ->
    msg.http("http://mchouse.it/temperature")
      .header("Accept", "application/json")
      .get() (err, res, body) ->
        msg.send JSON.parse(body)
In order to ask our temp
to hubot, we need to:

 1. sense the temp
 2. get the temp on the web
 3. build a web API
We are building an API




      In Italy,
     “API” means
        “bees”
                   http://www.flickr.com/photos/theseanster93/4056815767
What do we need to
sense my house
temperature
We add a sensor to an Arduino



                    TMP
                     36




                                TMP
                                 36
We add an ethernet shield to
  connect to the Internet

                                                          TMP
                                                           36




                   http://www.flickr.com/photos/snootlab/6052465980/
What protocol do we use
to push our temperature
to our API?
HTTP is slow and safe




               http://www.flickr.com/photos/clearlyambiguous/48185613/
We need a
fast, binary
protocol




               http://www.flickr.com/photos/grrphoto/305649629
M2M protocols are         “Things” should interact
mostly ad-hoc, and        with our lives, and all the
researchers and              technology should be
businesses focus on low    built to make them easy
level problems.                              to use.
• “things” exposed       • “things” exposed
  with binary protocol     to the web

• publish/subscribe      • request/response

• topics as the naming   • URIs as the
  system                   naming system
Discover


QEST
qest.me
HTTP Clients           MQTT Clients



   QEST
                     REST Server          MQTT Server
• MQTT broker
                                       QEST
• REST interface

• HTTP semantics                  Data Layer

• no QoS

• built on node.js
  and redis                            Redis
state-of-art
                  state-of-art                                             QEST-based      QEST-based
              approach to IoT apps IoT apps
                    approach to                                        solution to IoT apps
                                                                                       solution to IoT apps


  Web App                                                              Web App
                                                   Web App
                                                    Bridge
                                                                                     Web App

                                                                         QEST
                                                              Bridge



                                                                                                                                    QEST
                                                   IoT
                                                  Broker                  Device
                                                       IoT
                                                                                                                                    Device
                                                                                         3 2 1 0 9 8    7 6 5 4 3 2 1 0




                                                                                   GND
                                                                                   SCL

                                                                                  AREF
                                                                                   SDA
                                                                                         1 1 1 1   DIGITAL




                                                                                                                            RX
                                                                                                                            TX
                                                                                               PWM
                                                                                               PWM
                                                                                               PWM




                                                                                                               PWM
                                                                                                               PWM

                                                                                                                      PWM
                                                                                          L

                                                                                          TX
                                                                                               Arduino UNO                  ON




                                                      Broker
                                                                                          RX




                                                                                                                             1
                                                                                                                             ICSP




                                                                                                     www.arduino.cc




                                                                                          RESET
                                                                                          IOREF
                                                                                                    POWER         ANALOG IN




                                                                                          3V3
                                                                                                  5V Gnd Vin     0 1 2 3 4 5




                                                  Device
       3 2 1 0 9 8    7 6 5 4 3 2 1 0
 GND
 SCL

AREF
 SDA




       1 1 1 1   DIGITAL
                                          RX
                                          TX
             PWM
             PWM
             PWM




                             PWM
                             PWM

                                    PWM




        L

        TX
        RX
             Arduino UNO                  ON
                                           1




                                           ICSP




                   www.arduino.cc
        RESET
        IOREF




                  POWER         ANALOG IN
        3V3




                5V Gnd Vin     0 1 2 3 4 5




                                                             Device
QEST : MQTT to REST
• retains every message received

                     client = PubSubClient(server, 1883, callback);
                     client.publish("temp", "30");


• every topic has its own URI: /topics/<NAME>


                   curl -H "Accept: txt" http://qest.me/topics/temp
QEST : REST to MQTT
• transform every HTTP PUT received to a MQTT message

                            curl -X PUT -d '{ "payload": 42 }' 
                                 -H "Content-Type: application/json" 
                                 http://qest.me/topics/temp

• devices can listen directly to MQTT topics
                               void callback(char* topic, byte*
                                             payload, int length) {
                                 ...
                               }
                               PubSubClient(server, 1883, callback);
                               client.subscribe("temp");
HTTP/MQTT Clients

How to                          Load Balancer

scale

         REST Server   MQTT Server           REST Server   MQTT Server

                 QEST
                 Data Layer
                                     ...             QEST
                                                     Data Layer




                                     Redis
How much
time took me
to write the
first version
of QEST?
How much       A day.
time took me
to write the
first version    Thanks
of QEST?
A day.    • Express

          • Socket.io

          • node_redis

 Thanks   • MQTT.js

          • Coffeescript
What happens if you
write a broker in a day?
                           (Hint)
Spaghetti code!
How to untangle it?
http://www.flickr.com/photos/adewale_oshineye/2933030620/




Refactoring!!!
1.
         A single file
         can go really
         far!


 Well, the first
 improvement
 were two files
Coffee-script
is awesome for prototyping!
Coffee-script
is a real pain to debug
2.
 Extracting a
 data layer!
        HTTP Clients           MQTT Clients




     REST Server          MQTT Server
                       QEST

                  Data Layer




                       Redis
Discover my roots
Ruby Language
Ruby Language



Ruby on Rails
Ruby on Rails
       The
  ActiveRecord
    pattern is
   AWESOME!
ActiveRecord

1. Best pattern for storing data
2. Its main responsibilities are
   CRUD operations
3. I used that pattern to build a
   cross-process pub/sub
   system
Hubot © 2012 GitHub Inc. All rights
3.
 Extracting an
 inter process
 pub/sub
 library
Discover


  Ascoltatori
github.com/mcollina/ascoltatori
ir
     to
 lta                      • Redis
co
           is a multi-    • ZeroMQ
      process pub/sub
As


      library backed by
                          • RabbitMQ

                          • MQTT
                            (Mosquitto)

                          • Memory
                            (EventEmitter)
r     i
      to
 lta
co
     var	
  ascoltatori	
  =	
  require('ascoltatori');

     //	
  you	
  can	
  use	
  RedisAscoltatore,	
  ZeromqAscoltatore,
As

     //	
  RabbitAscoltatore,	
  MQTTAscoltatore
     var	
  ascoltatore	
  =	
  new	
  ascoltatori.MemoryAscoltatore();

     ascoltatore.subscribe("hello/*",	
  function()	
  {
     	
  	
  //	
  this	
  will	
  print	
  {	
  '0':	
  "hello/42",	
  '1':	
  "a	
  message"	
  }
     	
  	
  console.log(arguments);	
  
     	
  	
  process.exit(0);
     });

     ascoltatore.publish("hello/42",	
  "a	
  message",	
  function()	
  {
     	
  	
  console.log("message	
  published");
     });
Memory   Redis    ZeroMQ       RabbitMQ   Mosquitto




                    r i
                 to
        lta
100.000 us
   co
 10.000 us
As


  1.000 us


   100 us


     10 us


      1 us
             1           10               100          1000
                              Listeners
i r
     to
 lta
co
            allowed me to
As

            refactor QEST as
            just an MQTT
            wrapper!
ut ing
           s
    rib ek
         or
  nt se
co m
  Ia



            github.com/mcollina/qest


            github.com/mcollina/ascoltatori
DEMO!




        Source NASA
Matteo Collina

Software Engineer @
Mavigex

Ph.D. Student @
University of Bologna

matteocollina.com
@matteocollina




Thank You!
 Matteo Collina (matteo.collina2@unibo.it)




                                                http://www.flickr.com/photos/axel-d/479627824/

More Related Content

Similar to Building a multi protocol broker for the internet of things using nodejs

OpenStack Quantum - Past, Present & Future
OpenStack Quantum - Past, Present & FutureOpenStack Quantum - Past, Present & Future
OpenStack Quantum - Past, Present & FutureSomik Behera
 
Tears for quantum fears
Tears for quantum fearsTears for quantum fears
Tears for quantum fearsMark Carney
 
Inside Sql Azure - Cihan Biyikoglu - SQL Azure
Inside Sql Azure - Cihan Biyikoglu - SQL AzureInside Sql Azure - Cihan Biyikoglu - SQL Azure
Inside Sql Azure - Cihan Biyikoglu - SQL AzureCihan Biyikoglu
 
ICS/SCADA/PLC Google/Shodanhq Cheat Sheet
ICS/SCADA/PLC Google/Shodanhq Cheat SheetICS/SCADA/PLC Google/Shodanhq Cheat Sheet
ICS/SCADA/PLC Google/Shodanhq Cheat Sheetqqlan
 
2011 intelligent operator_panels
2011 intelligent operator_panels2011 intelligent operator_panels
2011 intelligent operator_panelsadvantech2012
 
Mircochip pmsm
Mircochip pmsmMircochip pmsm
Mircochip pmsmwarluck88
 
Micro chip an1292 sensorless foc pmsm using pll estimator and field weakening
Micro chip an1292 sensorless foc pmsm using pll estimator and field weakeningMicro chip an1292 sensorless foc pmsm using pll estimator and field weakening
Micro chip an1292 sensorless foc pmsm using pll estimator and field weakeningwarluck88
 
Vyatta cloud expo-sjc_2012-share
Vyatta cloud expo-sjc_2012-shareVyatta cloud expo-sjc_2012-share
Vyatta cloud expo-sjc_2012-shareScott Sneddon
 
Heterogeneous Systems Architecture: The Next Area of Computing Innovation
Heterogeneous Systems Architecture: The Next Area of Computing Innovation Heterogeneous Systems Architecture: The Next Area of Computing Innovation
Heterogeneous Systems Architecture: The Next Area of Computing Innovation AMD
 
IRJET- Note to Coin Converter using Digital Image Correlation Technique i...
IRJET-  	  Note to Coin Converter using Digital Image Correlation Technique i...IRJET-  	  Note to Coin Converter using Digital Image Correlation Technique i...
IRJET- Note to Coin Converter using Digital Image Correlation Technique i...IRJET Journal
 
SAMSUNG Exynos Mobile AP
SAMSUNG Exynos Mobile APSAMSUNG Exynos Mobile AP
SAMSUNG Exynos Mobile APJJ Wu
 
Solaiemes RCS-e Open & Ubiquitous
Solaiemes RCS-e Open & UbiquitousSolaiemes RCS-e Open & Ubiquitous
Solaiemes RCS-e Open & UbiquitousSolaiemes
 
isscc2017 28_7
isscc2017 28_7isscc2017 28_7
isscc2017 28_7adcfan
 
A 0.7V 12b 160MS/s 12.8fJ/convstep Pipelined-SAR ADC in 28nm CMOS with Digita...
A 0.7V 12b 160MS/s 12.8fJ/convstep Pipelined-SAR ADC in 28nm CMOS with Digita...A 0.7V 12b 160MS/s 12.8fJ/convstep Pipelined-SAR ADC in 28nm CMOS with Digita...
A 0.7V 12b 160MS/s 12.8fJ/convstep Pipelined-SAR ADC in 28nm CMOS with Digita...Kentaro Yoshioka
 
Access control system using RFID and zigbee
 Access control system using  RFID and zigbee  Access control system using  RFID and zigbee
Access control system using RFID and zigbee Pradheep Shrinivasan
 
Essential Guide Automation
Essential Guide AutomationEssential Guide Automation
Essential Guide AutomationGilbert Brault
 

Similar to Building a multi protocol broker for the internet of things using nodejs (20)

IPTV lecture
IPTV lectureIPTV lecture
IPTV lecture
 
OpenStack Quantum - Past, Present & Future
OpenStack Quantum - Past, Present & FutureOpenStack Quantum - Past, Present & Future
OpenStack Quantum - Past, Present & Future
 
Tears for quantum fears
Tears for quantum fearsTears for quantum fears
Tears for quantum fears
 
Arm 7 nxp
Arm 7 nxpArm 7 nxp
Arm 7 nxp
 
Inside Sql Azure - Cihan Biyikoglu - SQL Azure
Inside Sql Azure - Cihan Biyikoglu - SQL AzureInside Sql Azure - Cihan Biyikoglu - SQL Azure
Inside Sql Azure - Cihan Biyikoglu - SQL Azure
 
ICS/SCADA/PLC Google/Shodanhq Cheat Sheet
ICS/SCADA/PLC Google/Shodanhq Cheat SheetICS/SCADA/PLC Google/Shodanhq Cheat Sheet
ICS/SCADA/PLC Google/Shodanhq Cheat Sheet
 
2011 intelligent operator_panels
2011 intelligent operator_panels2011 intelligent operator_panels
2011 intelligent operator_panels
 
R2 R
R2 RR2 R
R2 R
 
Mircochip pmsm
Mircochip pmsmMircochip pmsm
Mircochip pmsm
 
Micro chip an1292 sensorless foc pmsm using pll estimator and field weakening
Micro chip an1292 sensorless foc pmsm using pll estimator and field weakeningMicro chip an1292 sensorless foc pmsm using pll estimator and field weakening
Micro chip an1292 sensorless foc pmsm using pll estimator and field weakening
 
Vyatta cloud expo-sjc_2012-share
Vyatta cloud expo-sjc_2012-shareVyatta cloud expo-sjc_2012-share
Vyatta cloud expo-sjc_2012-share
 
Heterogeneous Systems Architecture: The Next Area of Computing Innovation
Heterogeneous Systems Architecture: The Next Area of Computing Innovation Heterogeneous Systems Architecture: The Next Area of Computing Innovation
Heterogeneous Systems Architecture: The Next Area of Computing Innovation
 
IRJET- Note to Coin Converter using Digital Image Correlation Technique i...
IRJET-  	  Note to Coin Converter using Digital Image Correlation Technique i...IRJET-  	  Note to Coin Converter using Digital Image Correlation Technique i...
IRJET- Note to Coin Converter using Digital Image Correlation Technique i...
 
SAMSUNG Exynos Mobile AP
SAMSUNG Exynos Mobile APSAMSUNG Exynos Mobile AP
SAMSUNG Exynos Mobile AP
 
Solaiemes RCS-e Open & Ubiquitous
Solaiemes RCS-e Open & UbiquitousSolaiemes RCS-e Open & Ubiquitous
Solaiemes RCS-e Open & Ubiquitous
 
isscc2017 28_7
isscc2017 28_7isscc2017 28_7
isscc2017 28_7
 
A 0.7V 12b 160MS/s 12.8fJ/convstep Pipelined-SAR ADC in 28nm CMOS with Digita...
A 0.7V 12b 160MS/s 12.8fJ/convstep Pipelined-SAR ADC in 28nm CMOS with Digita...A 0.7V 12b 160MS/s 12.8fJ/convstep Pipelined-SAR ADC in 28nm CMOS with Digita...
A 0.7V 12b 160MS/s 12.8fJ/convstep Pipelined-SAR ADC in 28nm CMOS with Digita...
 
Matrix setu ata vs_linksys_pap2_t
Matrix  setu ata vs_linksys_pap2_tMatrix  setu ata vs_linksys_pap2_t
Matrix setu ata vs_linksys_pap2_t
 
Access control system using RFID and zigbee
 Access control system using  RFID and zigbee  Access control system using  RFID and zigbee
Access control system using RFID and zigbee
 
Essential Guide Automation
Essential Guide AutomationEssential Guide Automation
Essential Guide Automation
 

More from Matteo Collina

Build a community, not a framework
Build a community, not a frameworkBuild a community, not a framework
Build a community, not a frameworkMatteo Collina
 
No. la sottile arte di trovare il tempo dove non esite - codemotion 2015
No. la sottile arte di trovare il tempo dove non esite - codemotion 2015No. la sottile arte di trovare il tempo dove non esite - codemotion 2015
No. la sottile arte di trovare il tempo dove non esite - codemotion 2015Matteo Collina
 
Making your washing machine talk with a power plant
Making your washing machine talk with a power plantMaking your washing machine talk with a power plant
Making your washing machine talk with a power plantMatteo Collina
 
Crea il TUO database con LevelDB e Node.js
Crea il TUO database con LevelDB e Node.jsCrea il TUO database con LevelDB e Node.js
Crea il TUO database con LevelDB e Node.jsMatteo Collina
 
No. la sottile arte di trovare il tempo dove non esite.
No. la sottile arte di trovare il tempo dove non esite.No. la sottile arte di trovare il tempo dove non esite.
No. la sottile arte di trovare il tempo dove non esite.Matteo Collina
 
Making things that work with us - Distill
Making things that work with us - DistillMaking things that work with us - Distill
Making things that work with us - DistillMatteo Collina
 
Exposing M2M to the REST of us
Exposing M2M to the REST of usExposing M2M to the REST of us
Exposing M2M to the REST of usMatteo Collina
 
The internet of things - Rails Girls Galway
The internet of things - Rails Girls GalwayThe internet of things - Rails Girls Galway
The internet of things - Rails Girls GalwayMatteo Collina
 
Making things that works with us - First Italian Internet of Things Day
Making things that works with us - First Italian Internet of Things DayMaking things that works with us - First Italian Internet of Things Day
Making things that works with us - First Italian Internet of Things DayMatteo Collina
 
L'universo dietro alle App
L'universo dietro alle AppL'universo dietro alle App
L'universo dietro alle AppMatteo Collina
 
Enter the app era with ruby on rails (rubyday)
Enter the app era with ruby on rails (rubyday)Enter the app era with ruby on rails (rubyday)
Enter the app era with ruby on rails (rubyday)Matteo Collina
 
E così vuoi sviluppare un'app (ci servono le APi!)
E così vuoi sviluppare un'app (ci servono le APi!)E così vuoi sviluppare un'app (ci servono le APi!)
E così vuoi sviluppare un'app (ci servono le APi!)Matteo Collina
 
Operational transformation
Operational transformationOperational transformation
Operational transformationMatteo Collina
 
Enter the app era with ruby on rails
Enter the app era with ruby on railsEnter the app era with ruby on rails
Enter the app era with ruby on railsMatteo Collina
 
E così vuoi sviluppare un'app
E così vuoi sviluppare un'appE così vuoi sviluppare un'app
E così vuoi sviluppare un'appMatteo Collina
 
The usability of open data
The usability of open dataThe usability of open data
The usability of open dataMatteo Collina
 
Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...Matteo Collina
 
Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...Matteo Collina
 

More from Matteo Collina (19)

Build a community, not a framework
Build a community, not a frameworkBuild a community, not a framework
Build a community, not a framework
 
No. la sottile arte di trovare il tempo dove non esite - codemotion 2015
No. la sottile arte di trovare il tempo dove non esite - codemotion 2015No. la sottile arte di trovare il tempo dove non esite - codemotion 2015
No. la sottile arte di trovare il tempo dove non esite - codemotion 2015
 
Making your washing machine talk with a power plant
Making your washing machine talk with a power plantMaking your washing machine talk with a power plant
Making your washing machine talk with a power plant
 
Crea il TUO database con LevelDB e Node.js
Crea il TUO database con LevelDB e Node.jsCrea il TUO database con LevelDB e Node.js
Crea il TUO database con LevelDB e Node.js
 
No. la sottile arte di trovare il tempo dove non esite.
No. la sottile arte di trovare il tempo dove non esite.No. la sottile arte di trovare il tempo dove non esite.
No. la sottile arte di trovare il tempo dove non esite.
 
Making things that work with us - Distill
Making things that work with us - DistillMaking things that work with us - Distill
Making things that work with us - Distill
 
Exposing M2M to the REST of us
Exposing M2M to the REST of usExposing M2M to the REST of us
Exposing M2M to the REST of us
 
The internet of things - Rails Girls Galway
The internet of things - Rails Girls GalwayThe internet of things - Rails Girls Galway
The internet of things - Rails Girls Galway
 
Making things that works with us - First Italian Internet of Things Day
Making things that works with us - First Italian Internet of Things DayMaking things that works with us - First Italian Internet of Things Day
Making things that works with us - First Italian Internet of Things Day
 
L'universo dietro alle App
L'universo dietro alle AppL'universo dietro alle App
L'universo dietro alle App
 
Enter the app era with ruby on rails (rubyday)
Enter the app era with ruby on rails (rubyday)Enter the app era with ruby on rails (rubyday)
Enter the app era with ruby on rails (rubyday)
 
E così vuoi sviluppare un'app (ci servono le APi!)
E così vuoi sviluppare un'app (ci servono le APi!)E così vuoi sviluppare un'app (ci servono le APi!)
E così vuoi sviluppare un'app (ci servono le APi!)
 
Operational transformation
Operational transformationOperational transformation
Operational transformation
 
Enter the app era with ruby on rails
Enter the app era with ruby on railsEnter the app era with ruby on rails
Enter the app era with ruby on rails
 
E così vuoi sviluppare un'app
E così vuoi sviluppare un'appE così vuoi sviluppare un'app
E così vuoi sviluppare un'app
 
The usability of open data
The usability of open dataThe usability of open data
The usability of open data
 
CI-18n
CI-18nCI-18n
CI-18n
 
Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...
 
Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...
 

Recently uploaded

Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 

Building a multi protocol broker for the internet of things using nodejs

  • 1. @matteocollina matteocollina.com Building a multi-protocol broker for the Internet of Things using node.js Node.js Conference - Brescia 2012/11/09
  • 2. How many people will own a smartphone by 2014 1.000.000.000
  • 3. Did you see it coming http://www.flickr.com/photos/12738000@N00/360231193/
  • 5. What's next (hint: it's a big number) 50.000.000.000
  • 9. Goal: I want to chat with my house
  • 10. >: hi house hi matteo >: what's the temperature? 20
  • 11. >: 4 8 15 16 23 42 If you don’t understand this, you are not a geek!
  • 12. Enter Hubot Hubot © 2012 GitHub Inc. All rights
  • 13. A programmable robot that is controlled through chat Hubot © 2012 GitHub Inc. All rights
  • 14. We can supercharge our house with hubot
  • 15. We can supercharge our house with hubot How module.exports = (robot) -> robot.respond /what’s the temperature?/i, (msg) -> msg.http("http://mchouse.it/temperature") .header("Accept", "application/json") .get() (err, res, body) -> msg.send JSON.parse(body)
  • 16. In order to ask our temp to hubot, we need to: 1. sense the temp 2. get the temp on the web 3. build a web API
  • 17. We are building an API In Italy, “API” means “bees” http://www.flickr.com/photos/theseanster93/4056815767
  • 18. What do we need to sense my house temperature
  • 19. We add a sensor to an Arduino TMP 36 TMP 36
  • 20. We add an ethernet shield to connect to the Internet TMP 36 http://www.flickr.com/photos/snootlab/6052465980/
  • 21. What protocol do we use to push our temperature to our API?
  • 22. HTTP is slow and safe http://www.flickr.com/photos/clearlyambiguous/48185613/
  • 23. We need a fast, binary protocol http://www.flickr.com/photos/grrphoto/305649629
  • 24. M2M protocols are “Things” should interact mostly ad-hoc, and with our lives, and all the researchers and technology should be businesses focus on low built to make them easy level problems. to use.
  • 25. • “things” exposed • “things” exposed with binary protocol to the web • publish/subscribe • request/response • topics as the naming • URIs as the system naming system
  • 27. HTTP Clients MQTT Clients QEST REST Server MQTT Server • MQTT broker QEST • REST interface • HTTP semantics Data Layer • no QoS • built on node.js and redis Redis
  • 28. state-of-art state-of-art QEST-based QEST-based approach to IoT apps IoT apps approach to solution to IoT apps solution to IoT apps Web App Web App Web App Bridge Web App QEST Bridge QEST IoT Broker Device IoT Device 3 2 1 0 9 8 7 6 5 4 3 2 1 0 GND SCL AREF SDA 1 1 1 1 DIGITAL RX TX PWM PWM PWM PWM PWM PWM L TX Arduino UNO ON Broker RX 1 ICSP www.arduino.cc RESET IOREF POWER ANALOG IN 3V3 5V Gnd Vin 0 1 2 3 4 5 Device 3 2 1 0 9 8 7 6 5 4 3 2 1 0 GND SCL AREF SDA 1 1 1 1 DIGITAL RX TX PWM PWM PWM PWM PWM PWM L TX RX Arduino UNO ON 1 ICSP www.arduino.cc RESET IOREF POWER ANALOG IN 3V3 5V Gnd Vin 0 1 2 3 4 5 Device
  • 29. QEST : MQTT to REST • retains every message received client = PubSubClient(server, 1883, callback); client.publish("temp", "30"); • every topic has its own URI: /topics/<NAME> curl -H "Accept: txt" http://qest.me/topics/temp
  • 30. QEST : REST to MQTT • transform every HTTP PUT received to a MQTT message curl -X PUT -d '{ "payload": 42 }' -H "Content-Type: application/json" http://qest.me/topics/temp • devices can listen directly to MQTT topics void callback(char* topic, byte* payload, int length) { ... } PubSubClient(server, 1883, callback); client.subscribe("temp");
  • 31. HTTP/MQTT Clients How to Load Balancer scale REST Server MQTT Server REST Server MQTT Server QEST Data Layer ... QEST Data Layer Redis
  • 32. How much time took me to write the first version of QEST?
  • 33. How much A day. time took me to write the first version Thanks of QEST?
  • 34. A day. • Express • Socket.io • node_redis Thanks • MQTT.js • Coffeescript
  • 35. What happens if you write a broker in a day? (Hint)
  • 39. 1. A single file can go really far! Well, the first improvement were two files
  • 41. Coffee-script is a real pain to debug
  • 42. 2. Extracting a data layer! HTTP Clients MQTT Clients REST Server MQTT Server QEST Data Layer Redis
  • 46. Ruby on Rails The ActiveRecord pattern is AWESOME!
  • 47. ActiveRecord 1. Best pattern for storing data 2. Its main responsibilities are CRUD operations 3. I used that pattern to build a cross-process pub/sub system
  • 48. Hubot © 2012 GitHub Inc. All rights
  • 49. 3. Extracting an inter process pub/sub library
  • 51. ir to lta • Redis co is a multi- • ZeroMQ process pub/sub As library backed by • RabbitMQ • MQTT (Mosquitto) • Memory (EventEmitter)
  • 52. r i to lta co var  ascoltatori  =  require('ascoltatori'); //  you  can  use  RedisAscoltatore,  ZeromqAscoltatore, As //  RabbitAscoltatore,  MQTTAscoltatore var  ascoltatore  =  new  ascoltatori.MemoryAscoltatore(); ascoltatore.subscribe("hello/*",  function()  {    //  this  will  print  {  '0':  "hello/42",  '1':  "a  message"  }    console.log(arguments);      process.exit(0); }); ascoltatore.publish("hello/42",  "a  message",  function()  {    console.log("message  published"); });
  • 53. Memory Redis ZeroMQ RabbitMQ Mosquitto r i to lta 100.000 us co 10.000 us As 1.000 us 100 us 10 us 1 us 1 10 100 1000 Listeners
  • 54. i r to lta co allowed me to As refactor QEST as just an MQTT wrapper!
  • 55. ut ing s rib ek or nt se co m Ia github.com/mcollina/qest github.com/mcollina/ascoltatori
  • 56. DEMO! Source NASA
  • 57. Matteo Collina Software Engineer @ Mavigex Ph.D. Student @ University of Bologna matteocollina.com
  • 58. @matteocollina Thank You! Matteo Collina (matteo.collina2@unibo.it) http://www.flickr.com/photos/axel-d/479627824/