SlideShare a Scribd company logo
@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 (20)

IPTV lecture
IPTV lectureIPTV lecture
IPTV lecture
Adrian Hornsby
 
OpenStack Quantum - Past, Present & Future
OpenStack Quantum - Past, Present & FutureOpenStack Quantum - Past, Present & Future
OpenStack Quantum - Past, Present & Future
Somik Behera
 
Tears for quantum fears
Tears for quantum fearsTears for quantum fears
Tears for quantum fears
Mark Carney
 
Arm 7 nxp
Arm 7 nxpArm 7 nxp
Arm 7 nxp
Pantech ProLabs India Pvt Ltd
 
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
Cihan 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 Sheet
qqlan
 
2011 intelligent operator_panels
2011 intelligent operator_panels2011 intelligent operator_panels
2011 intelligent operator_panels
advantech2012
 
R2 R
R2 RR2 R
R2 R
Luis Zurita
 
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
warluck88
 
Mircochip pmsm
Mircochip pmsmMircochip pmsm
Mircochip pmsm
warluck88
 
Vyatta cloud expo-sjc_2012-share
Vyatta cloud expo-sjc_2012-shareVyatta cloud expo-sjc_2012-share
Vyatta cloud expo-sjc_2012-share
Scott 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 AP
JJ Wu
 
Solaiemes RCS-e Open & Ubiquitous
Solaiemes RCS-e Open & UbiquitousSolaiemes RCS-e Open & Ubiquitous
Solaiemes RCS-e Open & Ubiquitous
Solaiemes
 
isscc2017 28_7
isscc2017 28_7isscc2017 28_7
isscc2017 28_7
adcfan
 
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
 
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
Gateway Business Solutions
 
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 Automation
Gilbert Brault
 
OpenStack Quantum - Past, Present & Future
OpenStack Quantum - Past, Present & FutureOpenStack Quantum - Past, Present & Future
OpenStack Quantum - Past, Present & Future
Somik Behera
 
Tears for quantum fears
Tears for quantum fearsTears for quantum fears
Tears for quantum fears
Mark 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 Azure
Cihan 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 Sheet
qqlan
 
2011 intelligent operator_panels
2011 intelligent operator_panels2011 intelligent operator_panels
2011 intelligent operator_panels
advantech2012
 
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
warluck88
 
Mircochip pmsm
Mircochip pmsmMircochip pmsm
Mircochip pmsm
warluck88
 
Vyatta cloud expo-sjc_2012-share
Vyatta cloud expo-sjc_2012-shareVyatta cloud expo-sjc_2012-share
Vyatta cloud expo-sjc_2012-share
Scott 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 AP
JJ Wu
 
Solaiemes RCS-e Open & Ubiquitous
Solaiemes RCS-e Open & UbiquitousSolaiemes RCS-e Open & Ubiquitous
Solaiemes RCS-e Open & Ubiquitous
Solaiemes
 
isscc2017 28_7
isscc2017 28_7isscc2017 28_7
isscc2017 28_7
adcfan
 
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 Automation
Gilbert Brault
 

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
Matteo 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 2015
Matteo 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 plant
Matteo 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.js
Matteo 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 - Distill
Matteo 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 us
Matteo 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 Galway
Matteo 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 Day
Matteo Collina
 
L'universo dietro alle App
L'universo dietro alle AppL'universo dietro alle App
L'universo dietro alle App
Matteo 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 transformation
Matteo 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 rails
Matteo Collina
 
E così vuoi sviluppare un'app
E così vuoi sviluppare un'appE così vuoi sviluppare un'app
E così vuoi sviluppare un'app
Matteo Collina
 
The usability of open data
The usability of open dataThe usability of open data
The usability of open data
Matteo Collina
 
CI-18n
CI-18nCI-18n
CI-18n
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
 
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
 
Build a community, not a framework
Build a community, not a frameworkBuild a community, not a framework
Build a community, not a framework
Matteo 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 2015
Matteo 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 plant
Matteo 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.js
Matteo 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 - Distill
Matteo 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 us
Matteo 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 Galway
Matteo 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 Day
Matteo Collina
 
L'universo dietro alle App
L'universo dietro alle AppL'universo dietro alle App
L'universo dietro alle App
Matteo 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 transformation
Matteo 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 rails
Matteo Collina
 
E così vuoi sviluppare un'app
E così vuoi sviluppare un'appE così vuoi sviluppare un'app
E così vuoi sviluppare un'app
Matteo Collina
 
The usability of open data
The usability of open dataThe usability of open data
The usability of open data
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
 
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
 
Ad

Recently uploaded (20)

Evaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical ContentEvaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical Content
Paul Groth
 
Introducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and ARIntroducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and AR
Safe Software
 
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath InsightsUiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPathCommunity
 
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptxECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
Jasper Oosterveld
 
Supercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMsSupercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMs
Francesco Corti
 
The case for on-premises AI
The case for on-premises AIThe case for on-premises AI
The case for on-premises AI
Principled Technologies
 
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Lorenzo Miniero
 
SDG 9000 Series: Unleashing multigigabit everywhere
SDG 9000 Series: Unleashing multigigabit everywhereSDG 9000 Series: Unleashing multigigabit everywhere
SDG 9000 Series: Unleashing multigigabit everywhere
Adtran
 
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
James Anderson
 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
 
6th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 20256th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 2025
DanBrown980551
 
New Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDBNew Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDB
ScyllaDB
 
Gihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai TechnologyGihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai Technology
zainkhurram1111
 
AI Emotional Actors: “When Machines Learn to Feel and Perform"
AI Emotional Actors:  “When Machines Learn to Feel and Perform"AI Emotional Actors:  “When Machines Learn to Feel and Perform"
AI Emotional Actors: “When Machines Learn to Feel and Perform"
AkashKumar809858
 
AI Trends - Mary Meeker
AI Trends - Mary MeekerAI Trends - Mary Meeker
AI Trends - Mary Meeker
Razin Mustafiz
 
Cyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptxCyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptx
Ghimire B.R.
 
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
Jasper Oosterveld
 
Create Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent BuilderCreate Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent Builder
DianaGray10
 
Fortinet Certified Associate in Cybersecurity
Fortinet Certified Associate in CybersecurityFortinet Certified Associate in Cybersecurity
Fortinet Certified Associate in Cybersecurity
VICTOR MAESTRE RAMIREZ
 
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk TechniciansOffshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
john823664
 
Evaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical ContentEvaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical Content
Paul Groth
 
Introducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and ARIntroducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and AR
Safe Software
 
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath InsightsUiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPathCommunity
 
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptxECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
Jasper Oosterveld
 
Supercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMsSupercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMs
Francesco Corti
 
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Lorenzo Miniero
 
SDG 9000 Series: Unleashing multigigabit everywhere
SDG 9000 Series: Unleashing multigigabit everywhereSDG 9000 Series: Unleashing multigigabit everywhere
SDG 9000 Series: Unleashing multigigabit everywhere
Adtran
 
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
James Anderson
 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
 
6th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 20256th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 2025
DanBrown980551
 
New Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDBNew Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDB
ScyllaDB
 
Gihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai TechnologyGihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai Technology
zainkhurram1111
 
AI Emotional Actors: “When Machines Learn to Feel and Perform"
AI Emotional Actors:  “When Machines Learn to Feel and Perform"AI Emotional Actors:  “When Machines Learn to Feel and Perform"
AI Emotional Actors: “When Machines Learn to Feel and Perform"
AkashKumar809858
 
AI Trends - Mary Meeker
AI Trends - Mary MeekerAI Trends - Mary Meeker
AI Trends - Mary Meeker
Razin Mustafiz
 
Cyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptxCyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptx
Ghimire B.R.
 
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
Jasper Oosterveld
 
Create Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent BuilderCreate Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent Builder
DianaGray10
 
Fortinet Certified Associate in Cybersecurity
Fortinet Certified Associate in CybersecurityFortinet Certified Associate in Cybersecurity
Fortinet Certified Associate in Cybersecurity
VICTOR MAESTRE RAMIREZ
 
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk TechniciansOffshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
john823664
 
Ad

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 ([email protected]) http://www.flickr.com/photos/axel-d/479627824/