SlideShare a Scribd company logo
1 of 27
Download to read offline
REST vs MQTT
REST and MQTT
REST and MQTT
An IoT oriented comparison
Credits: Prof.Pietro Manzoni, University of Valencia, Spain
1
REST vs MQTT
REST
 Basic concepts
 Basic programming
12
REST vs MQTT
Data Representation
 Data-interchange format. Should be easy for humans to read and
write. Should be easy for machines to parse and generate
 Two main formats:
13
JavaScript Object Notation (JSON)
[http://www.json.org/]
{"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "New", "onclick": ”NewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
}
}
}
XML
<menu>
<id>file</id>
<value>File</value>
<popup>
<menuitem>
<value>New</value>
<onclick>NewDoc()</onclick>
</menuitem>
<menuitem>
<value>Open</value>
<onclick>OpenDoc()</onclick>
</menuitem>
<menuitem>
<value>Close</value>
<onclick>CloseDoc()</onclick>
</menuitem>
</popup>
</menu>
{“value": 237} vs. <value>237</value>
REST vs MQTT
REST and HTTP
 REST stands for Representational State Transfer.
 It basically leverages the HTTP protocol and its related frameworks to
provide data services.
 The motivation for REST was to capture the characteristics of the
Web which made the Web successful.
 Make a Request – Receive Response – Display Response
 REST is not a standard… but it uses several standards:
 HTTP
 URL
 XML/HTML/GIF/JPEG/etc (Resource Representations)
 text/xml, text/html, image/gif, image/jpeg, etc (Resource Types, MIME Types)
14
REST vs MQTT
Verbs
Represent the actions to be performed on resources
HTTP GET
HTTP POST
HTTP PUT
HTTP DELETE
20
REST vs MQTT
HTTP GET
 How clients ask for the information they seek.
 Issuing a GET request transfers the data from the server to the client
in some representation (JSON, XML, …)
GET http://www.library.edu/books
 Retrieve all books
GET http://www.library.edu/books/ISBN-0011021
 Retrieve book identified with ISBN-0011021
GET http://www.library.edu/books/ISBN-0011021/authors
 Retrieve authors for book identified with ISBN-0011021
21
REST vs MQTT
HTTP PUT, HTTP POST
 HTTP POST creates a resource
 HTTP PUT updates a resource
 POST http://www.library.edu/books/
Content: {title, authors[], …}
 Creates a new book with given properties
 PUT http://www.library.edu/books/isbn-111
Content: {isbn, title, authors[], …}
 Updates book identified by isbn-111 with submitted properties
22
REST vs MQTT
all-lights.floor-d.example.com
GET /status/power
PUT /control/onoff
PUT /control/color
#00FF00
REST for devices control communication
24
REST vs MQTT
HTTP DELETE
Removes the resource identified by the URI
DELETE http://www.library.edu/books/ISBN-0011
 Delete book identified by ISBN-0011
25
REST vs MQTT
REST is widely used
 Google Maps:
 https://developers.google.com/maps/web-services/
 Try: http://maps.googleapis.com/maps/api/geocode/json?address=bangkok
 Twitter:
 https://dev.twitter.com/rest/public
 Facebook:
 https://developers.facebook.com/docs/atlas-apis
 Amazon offers several REST services, e.g., for their S3 storage solution
 http://docs.aws.amazon.com/AmazonS3/latest/API/Welcome.html
 Also:
 The Google Glass API, known as "Mirror API", is a pure REST API.
 Here is (https://youtu.be/JpWmGX55a40) a video talk about this API. (The actual API
discussion starts after 16 minutes or so.)
 Tesla Model S uses an (undocumented) REST API between the car systems and its
Android/iOS apps.
 http://docs.timdorr.apiary.io/#reference/vehicles/state-and-settings
41
REST vs MQTT
Very widely…
https://apigee.com/providers
 https://apigee.com/resources/instagram
42
REST vs MQTT
MQTT
 Basic concepts
 Basic programming
43
Source: https://zoetrope.io/tech-blog/brief-practical-introduction-mqtt-protocol-and-its-application-iot
REST vs MQTT
Message Queuing Telemetry Transport
 A lightweight publish-subscribe protocol that runs on embedded
devices and mobile platforms designed to connect the physical world
devices with applications and middleware.
 http://mqtt.org/
 the MQTT community wiki: https://github.com/mqtt/mqtt.github.io/wiki
 http://www.hivemq.com/mqtt-essentials/
 Designed to provide a low latency two-way communication channel
and efficient distribution to one or many receivers.
 Minimizes the amount of bytes flowing over the wire
 Low power usage.
44
REST vs MQTT
Message Queuing Telemetry Transport
45
REST vs MQTT
Publish/subscribe pattern
 Pub/Sub decouples a client, who is sending a particular message
(called publisher) from another client (or more clients), who is
receiving the message (called subscriber). This means that the
publisher and subscriber don’t know about the existence of one
another.
 There is a third component, called broker, which is known by both the
publisher and subscriber, which filters all incoming messages and
distributes them accordingly.
48
Software bus
Publisher 1 Publisher 2
Subscriber 1 Subscriber 2 Subscriber 3
Software bus
Publisher 1 Publisher 2
Subscriber 1 Subscriber 2 Subscriber 3
REST vs MQTT
Publish
 MQTT is data-agnostic and it totally depends on the use case how the
payload is structured. It’s completely up to the sender if it wants to
send binary data, textual data or even full-fledged XML or JSON.
50
REST vs MQTT
Topics
 Topic subscriptions can have wildcards
 ‘+’ matches anything at a given tree level so the topic “sensor/+/temp” would
match “sensor/dev1/temp”, “sensor/dev2/temp”, etc.
 ‘#’ matches a whole sub-tree, so “sensor/#” would match all topics under
“sensor/”.
 These enable nodes to subscribe to groups of topics that don’t exist
yet, allowing greater flexibility in the network’s messaging structure.
52
REST vs MQTT
Quality of Service (QoS)
 Messages are published with a Quality of Service (QoS) level, which
specifies delivery requirements.
 A QoS-0 (“at most once”) message is fire-and-forget.
 For example, a notification from a doorbell may only matter when immediately
delivered.
 With QoS-1 (“at least once”), the broker stores messages on disk and
retries until clients have acknowledged their delivery.
 (Possibly with duplicates.) It’s usually worth ensuring error messages are
delivered, even with a delay.
 QoS-2 (“exactly once”) messages have a second acknowledgement
round-trip, to ensure that non-idempotent messages can be delivered
exactly once.
54
REST vs MQTT
“Will” message
 When clients connect, they can specify an optional “will” message, to
be delivered if they are unexpectedly disconnected from the network.
 (In the absence of other activity, a 2-byte ping message is sent to clients at a
configurable interval.)
 This “last will and testament” can be used to notify other parts of the
system that a node has gone down.
58
REST vs MQTT
MQTT
 Basic concepts
 Basic programming
62
REST vs MQTT
Software available
 Brokers (https://github.com/mqtt/mqtt.github.io/wiki/servers):
 http://mosquitto.org/
 http://www.hivemq.com/
 https://www.rabbitmq.com/mqtt.html
 http://activemq.apache.org/mqtt.html
 https://github.com/mcollina/mosca
 Clients
 http://www.eclipse.org/paho/
 Source: https://github.com/eclipse/paho.mqtt.python
 http://www.hivemq.com/demos/websocket-client/
 Tools
 https://github.com/mqtt/mqtt.github.io/wiki/tools
63
REST vs MQTT
The suggested working environment
 Installing the Python client
sudo pip install paho-mqtt
 or
git clone https://github.com/eclipse/paho.mqtt.python.git
cd org.eclipse.paho.mqtt.python.git
python setup.py install
 Installing the whole Mosquitto environment
sudo wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
sudo apt-key add mosquitto-repo.gpg.key
cd /etc/apt/sources.list.d/
sudo wget http://repo.mosquitto.org/debian/mosquitto-jessie.list
sudo apt-get update sudo apt-get install mosquitto
sudo apt-get install mosquitto mosquitto-clients python-mosquitto
64
REST vs MQTT
Controlling the broker
 Starting / stopping the broker
sudo /etc/init.d/mosquitto stop
sudo /etc/init.d/mosquitto start
 To avoid that it restarts automatically
sudo stop mosquitto
 Running verbose mode:
sudo mosquitto -v
 To check whether is running:
sudo netstat -tanlp | grep 1883
ps -ef | grep mosquitto
 man page:
https://mosquitto.org/man/mosquitto-8.html
65
REST vs MQTT
Sandboxes
 https://iot.eclipse.org/getting-started#sandboxes
 hostname iot.eclipse.org and port 1883.
 encrypted port 8883
 http://test.mosquitto.org/
 http://www.hivemq.com/try-out/
 http://www.mqtt-dashboard.com/
 Google CLOUD PUB/SUB A global service for real-time and reliable
messaging and streaming data
 https://cloud.google.com/pubsub/
66
REST vs MQTT
Excercise
67
REST vs MQTT
Excercise
 Broker information:
 WiFi SSID: mqtt
 WiFi password: brokerpi
 Broker IP address: 172.24.1.1
68
REST vs MQTT
Excercise
1. Start with the MQTT example. It will send a text message via MQTT
to the broker. Does it show up?
2. Next develop a MQTT + Pysense example. It will read sensor values
from Pysense and send them to the broker. Can you read the values
in the broker?
3. Install a MQTT client on your PC/smartphone and subscribe to the
topics of interest.
69

More Related Content

Similar to mqttvsrest_v4.pdf

Azure Service Bus Performance Checklist
Azure Service Bus Performance ChecklistAzure Service Bus Performance Checklist
Azure Service Bus Performance ChecklistSalim M Bhonhariya
 
Tungsten Fabric Overview
Tungsten Fabric OverviewTungsten Fabric Overview
Tungsten Fabric OverviewMichelle Holley
 
TechEvent Eclipse Microprofile
TechEvent Eclipse MicroprofileTechEvent Eclipse Microprofile
TechEvent Eclipse MicroprofileTrivadis
 
Hatkit Project - Datafiddler
Hatkit Project - DatafiddlerHatkit Project - Datafiddler
Hatkit Project - Datafiddlerholiman
 
Developing Realtime Data Pipelines With Apache Kafka
Developing Realtime Data Pipelines With Apache KafkaDeveloping Realtime Data Pipelines With Apache Kafka
Developing Realtime Data Pipelines With Apache KafkaJoe Stein
 
Monitoring as an entry point for collaboration
Monitoring as an entry point for collaborationMonitoring as an entry point for collaboration
Monitoring as an entry point for collaborationJulien Pivotto
 
Kubernetes for the PHP developer
Kubernetes for the PHP developerKubernetes for the PHP developer
Kubernetes for the PHP developerPaul Czarkowski
 
Internet of Things - protocols review (MeetUp Wireless & Networks, Poznań 21....
Internet of Things - protocols review (MeetUp Wireless & Networks, Poznań 21....Internet of Things - protocols review (MeetUp Wireless & Networks, Poznań 21....
Internet of Things - protocols review (MeetUp Wireless & Networks, Poznań 21....Marcin Bielak
 
Programming IoT Gateways with macchina.io
Programming IoT Gateways with macchina.ioProgramming IoT Gateways with macchina.io
Programming IoT Gateways with macchina.ioGünter Obiltschnig
 
LibOS as a regression test framework for Linux networking #netdev1.1
LibOS as a regression test framework for Linux networking #netdev1.1LibOS as a regression test framework for Linux networking #netdev1.1
LibOS as a regression test framework for Linux networking #netdev1.1Hajime Tazaki
 
Microservices Server - MSS Workshop
Microservices Server - MSS WorkshopMicroservices Server - MSS Workshop
Microservices Server - MSS WorkshopWSO2
 
Introduction to LAVA Workload Scheduler
Introduction to LAVA Workload SchedulerIntroduction to LAVA Workload Scheduler
Introduction to LAVA Workload SchedulerNopparat Nopkuat
 
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)QAware GmbH
 
PRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGE
PRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGEPRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGE
PRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGEEditor IJCTER
 
AWS IoT 및 Mobile Hub 서비스 소개 (김일호) :: re:Invent re:Cap Webinar 2015
AWS IoT 및 Mobile Hub 서비스 소개 (김일호) :: re:Invent re:Cap Webinar 2015AWS IoT 및 Mobile Hub 서비스 소개 (김일호) :: re:Invent re:Cap Webinar 2015
AWS IoT 및 Mobile Hub 서비스 소개 (김일호) :: re:Invent re:Cap Webinar 2015Amazon Web Services Korea
 
Connecting Internet of Things to the Cloud with MQTT
Connecting Internet of Things to the Cloud with MQTTConnecting Internet of Things to the Cloud with MQTT
Connecting Internet of Things to the Cloud with MQTTLeon Anavi
 
Monitoring using Prometheus and Grafana
Monitoring using Prometheus and GrafanaMonitoring using Prometheus and Grafana
Monitoring using Prometheus and GrafanaArvind Kumar G.S
 

Similar to mqttvsrest_v4.pdf (20)

Azure Service Bus Performance Checklist
Azure Service Bus Performance ChecklistAzure Service Bus Performance Checklist
Azure Service Bus Performance Checklist
 
Tungsten Fabric Overview
Tungsten Fabric OverviewTungsten Fabric Overview
Tungsten Fabric Overview
 
TechEvent Eclipse Microprofile
TechEvent Eclipse MicroprofileTechEvent Eclipse Microprofile
TechEvent Eclipse Microprofile
 
Hatkit Project - Datafiddler
Hatkit Project - DatafiddlerHatkit Project - Datafiddler
Hatkit Project - Datafiddler
 
Developing Realtime Data Pipelines With Apache Kafka
Developing Realtime Data Pipelines With Apache KafkaDeveloping Realtime Data Pipelines With Apache Kafka
Developing Realtime Data Pipelines With Apache Kafka
 
Monitoring as an entry point for collaboration
Monitoring as an entry point for collaborationMonitoring as an entry point for collaboration
Monitoring as an entry point for collaboration
 
CloudComp 2015 - SDN-Cloud Testbed with Hyper-convergent SmartX Boxes
CloudComp 2015 - SDN-Cloud Testbed with Hyper-convergent SmartX BoxesCloudComp 2015 - SDN-Cloud Testbed with Hyper-convergent SmartX Boxes
CloudComp 2015 - SDN-Cloud Testbed with Hyper-convergent SmartX Boxes
 
Kubernetes for the PHP developer
Kubernetes for the PHP developerKubernetes for the PHP developer
Kubernetes for the PHP developer
 
Internet of Things - protocols review (MeetUp Wireless & Networks, Poznań 21....
Internet of Things - protocols review (MeetUp Wireless & Networks, Poznań 21....Internet of Things - protocols review (MeetUp Wireless & Networks, Poznań 21....
Internet of Things - protocols review (MeetUp Wireless & Networks, Poznań 21....
 
Programming IoT Gateways with macchina.io
Programming IoT Gateways with macchina.ioProgramming IoT Gateways with macchina.io
Programming IoT Gateways with macchina.io
 
LibOS as a regression test framework for Linux networking #netdev1.1
LibOS as a regression test framework for Linux networking #netdev1.1LibOS as a regression test framework for Linux networking #netdev1.1
LibOS as a regression test framework for Linux networking #netdev1.1
 
Introduction To Cloud Computing
Introduction To Cloud ComputingIntroduction To Cloud Computing
Introduction To Cloud Computing
 
Microservices Server - MSS Workshop
Microservices Server - MSS WorkshopMicroservices Server - MSS Workshop
Microservices Server - MSS Workshop
 
Introduction to LAVA Workload Scheduler
Introduction to LAVA Workload SchedulerIntroduction to LAVA Workload Scheduler
Introduction to LAVA Workload Scheduler
 
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
Kubernetes One-Click Deployment: Hands-on Workshop (Mainz)
 
PRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGE
PRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGEPRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGE
PRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGE
 
Vert.x devoxx london 2013
Vert.x devoxx london 2013Vert.x devoxx london 2013
Vert.x devoxx london 2013
 
AWS IoT 및 Mobile Hub 서비스 소개 (김일호) :: re:Invent re:Cap Webinar 2015
AWS IoT 및 Mobile Hub 서비스 소개 (김일호) :: re:Invent re:Cap Webinar 2015AWS IoT 및 Mobile Hub 서비스 소개 (김일호) :: re:Invent re:Cap Webinar 2015
AWS IoT 및 Mobile Hub 서비스 소개 (김일호) :: re:Invent re:Cap Webinar 2015
 
Connecting Internet of Things to the Cloud with MQTT
Connecting Internet of Things to the Cloud with MQTTConnecting Internet of Things to the Cloud with MQTT
Connecting Internet of Things to the Cloud with MQTT
 
Monitoring using Prometheus and Grafana
Monitoring using Prometheus and GrafanaMonitoring using Prometheus and Grafana
Monitoring using Prometheus and Grafana
 

Recently uploaded

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 

mqttvsrest_v4.pdf

  • 1. REST vs MQTT REST and MQTT REST and MQTT An IoT oriented comparison Credits: Prof.Pietro Manzoni, University of Valencia, Spain 1
  • 2. REST vs MQTT REST  Basic concepts  Basic programming 12
  • 3. REST vs MQTT Data Representation  Data-interchange format. Should be easy for humans to read and write. Should be easy for machines to parse and generate  Two main formats: 13 JavaScript Object Notation (JSON) [http://www.json.org/] {"menu": { "id": "file", "value": "File", "popup": { "menuitem": [ {"value": "New", "onclick": ”NewDoc()"}, {"value": "Open", "onclick": "OpenDoc()"}, {"value": "Close", "onclick": "CloseDoc()"} ] } } } XML <menu> <id>file</id> <value>File</value> <popup> <menuitem> <value>New</value> <onclick>NewDoc()</onclick> </menuitem> <menuitem> <value>Open</value> <onclick>OpenDoc()</onclick> </menuitem> <menuitem> <value>Close</value> <onclick>CloseDoc()</onclick> </menuitem> </popup> </menu> {“value": 237} vs. <value>237</value>
  • 4. REST vs MQTT REST and HTTP  REST stands for Representational State Transfer.  It basically leverages the HTTP protocol and its related frameworks to provide data services.  The motivation for REST was to capture the characteristics of the Web which made the Web successful.  Make a Request – Receive Response – Display Response  REST is not a standard… but it uses several standards:  HTTP  URL  XML/HTML/GIF/JPEG/etc (Resource Representations)  text/xml, text/html, image/gif, image/jpeg, etc (Resource Types, MIME Types) 14
  • 5. REST vs MQTT Verbs Represent the actions to be performed on resources HTTP GET HTTP POST HTTP PUT HTTP DELETE 20
  • 6. REST vs MQTT HTTP GET  How clients ask for the information they seek.  Issuing a GET request transfers the data from the server to the client in some representation (JSON, XML, …) GET http://www.library.edu/books  Retrieve all books GET http://www.library.edu/books/ISBN-0011021  Retrieve book identified with ISBN-0011021 GET http://www.library.edu/books/ISBN-0011021/authors  Retrieve authors for book identified with ISBN-0011021 21
  • 7. REST vs MQTT HTTP PUT, HTTP POST  HTTP POST creates a resource  HTTP PUT updates a resource  POST http://www.library.edu/books/ Content: {title, authors[], …}  Creates a new book with given properties  PUT http://www.library.edu/books/isbn-111 Content: {isbn, title, authors[], …}  Updates book identified by isbn-111 with submitted properties 22
  • 8. REST vs MQTT all-lights.floor-d.example.com GET /status/power PUT /control/onoff PUT /control/color #00FF00 REST for devices control communication 24
  • 9. REST vs MQTT HTTP DELETE Removes the resource identified by the URI DELETE http://www.library.edu/books/ISBN-0011  Delete book identified by ISBN-0011 25
  • 10. REST vs MQTT REST is widely used  Google Maps:  https://developers.google.com/maps/web-services/  Try: http://maps.googleapis.com/maps/api/geocode/json?address=bangkok  Twitter:  https://dev.twitter.com/rest/public  Facebook:  https://developers.facebook.com/docs/atlas-apis  Amazon offers several REST services, e.g., for their S3 storage solution  http://docs.aws.amazon.com/AmazonS3/latest/API/Welcome.html  Also:  The Google Glass API, known as "Mirror API", is a pure REST API.  Here is (https://youtu.be/JpWmGX55a40) a video talk about this API. (The actual API discussion starts after 16 minutes or so.)  Tesla Model S uses an (undocumented) REST API between the car systems and its Android/iOS apps.  http://docs.timdorr.apiary.io/#reference/vehicles/state-and-settings 41
  • 11. REST vs MQTT Very widely… https://apigee.com/providers  https://apigee.com/resources/instagram 42
  • 12. REST vs MQTT MQTT  Basic concepts  Basic programming 43 Source: https://zoetrope.io/tech-blog/brief-practical-introduction-mqtt-protocol-and-its-application-iot
  • 13. REST vs MQTT Message Queuing Telemetry Transport  A lightweight publish-subscribe protocol that runs on embedded devices and mobile platforms designed to connect the physical world devices with applications and middleware.  http://mqtt.org/  the MQTT community wiki: https://github.com/mqtt/mqtt.github.io/wiki  http://www.hivemq.com/mqtt-essentials/  Designed to provide a low latency two-way communication channel and efficient distribution to one or many receivers.  Minimizes the amount of bytes flowing over the wire  Low power usage. 44
  • 14. REST vs MQTT Message Queuing Telemetry Transport 45
  • 15. REST vs MQTT Publish/subscribe pattern  Pub/Sub decouples a client, who is sending a particular message (called publisher) from another client (or more clients), who is receiving the message (called subscriber). This means that the publisher and subscriber don’t know about the existence of one another.  There is a third component, called broker, which is known by both the publisher and subscriber, which filters all incoming messages and distributes them accordingly. 48 Software bus Publisher 1 Publisher 2 Subscriber 1 Subscriber 2 Subscriber 3 Software bus Publisher 1 Publisher 2 Subscriber 1 Subscriber 2 Subscriber 3
  • 16. REST vs MQTT Publish  MQTT is data-agnostic and it totally depends on the use case how the payload is structured. It’s completely up to the sender if it wants to send binary data, textual data or even full-fledged XML or JSON. 50
  • 17. REST vs MQTT Topics  Topic subscriptions can have wildcards  ‘+’ matches anything at a given tree level so the topic “sensor/+/temp” would match “sensor/dev1/temp”, “sensor/dev2/temp”, etc.  ‘#’ matches a whole sub-tree, so “sensor/#” would match all topics under “sensor/”.  These enable nodes to subscribe to groups of topics that don’t exist yet, allowing greater flexibility in the network’s messaging structure. 52
  • 18. REST vs MQTT Quality of Service (QoS)  Messages are published with a Quality of Service (QoS) level, which specifies delivery requirements.  A QoS-0 (“at most once”) message is fire-and-forget.  For example, a notification from a doorbell may only matter when immediately delivered.  With QoS-1 (“at least once”), the broker stores messages on disk and retries until clients have acknowledged their delivery.  (Possibly with duplicates.) It’s usually worth ensuring error messages are delivered, even with a delay.  QoS-2 (“exactly once”) messages have a second acknowledgement round-trip, to ensure that non-idempotent messages can be delivered exactly once. 54
  • 19. REST vs MQTT “Will” message  When clients connect, they can specify an optional “will” message, to be delivered if they are unexpectedly disconnected from the network.  (In the absence of other activity, a 2-byte ping message is sent to clients at a configurable interval.)  This “last will and testament” can be used to notify other parts of the system that a node has gone down. 58
  • 20. REST vs MQTT MQTT  Basic concepts  Basic programming 62
  • 21. REST vs MQTT Software available  Brokers (https://github.com/mqtt/mqtt.github.io/wiki/servers):  http://mosquitto.org/  http://www.hivemq.com/  https://www.rabbitmq.com/mqtt.html  http://activemq.apache.org/mqtt.html  https://github.com/mcollina/mosca  Clients  http://www.eclipse.org/paho/  Source: https://github.com/eclipse/paho.mqtt.python  http://www.hivemq.com/demos/websocket-client/  Tools  https://github.com/mqtt/mqtt.github.io/wiki/tools 63
  • 22. REST vs MQTT The suggested working environment  Installing the Python client sudo pip install paho-mqtt  or git clone https://github.com/eclipse/paho.mqtt.python.git cd org.eclipse.paho.mqtt.python.git python setup.py install  Installing the whole Mosquitto environment sudo wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key sudo apt-key add mosquitto-repo.gpg.key cd /etc/apt/sources.list.d/ sudo wget http://repo.mosquitto.org/debian/mosquitto-jessie.list sudo apt-get update sudo apt-get install mosquitto sudo apt-get install mosquitto mosquitto-clients python-mosquitto 64
  • 23. REST vs MQTT Controlling the broker  Starting / stopping the broker sudo /etc/init.d/mosquitto stop sudo /etc/init.d/mosquitto start  To avoid that it restarts automatically sudo stop mosquitto  Running verbose mode: sudo mosquitto -v  To check whether is running: sudo netstat -tanlp | grep 1883 ps -ef | grep mosquitto  man page: https://mosquitto.org/man/mosquitto-8.html 65
  • 24. REST vs MQTT Sandboxes  https://iot.eclipse.org/getting-started#sandboxes  hostname iot.eclipse.org and port 1883.  encrypted port 8883  http://test.mosquitto.org/  http://www.hivemq.com/try-out/  http://www.mqtt-dashboard.com/  Google CLOUD PUB/SUB A global service for real-time and reliable messaging and streaming data  https://cloud.google.com/pubsub/ 66
  • 26. REST vs MQTT Excercise  Broker information:  WiFi SSID: mqtt  WiFi password: brokerpi  Broker IP address: 172.24.1.1 68
  • 27. REST vs MQTT Excercise 1. Start with the MQTT example. It will send a text message via MQTT to the broker. Does it show up? 2. Next develop a MQTT + Pysense example. It will read sensor values from Pysense and send them to the broker. Can you read the values in the broker? 3. Install a MQTT client on your PC/smartphone and subscribe to the topics of interest. 69