Professional Documents
Culture Documents
PHY LAYER
IFA’2021 2
Message Queuing Telemetry Transport (MQTT)
n Lightweight (low network bandwidth & small code) messaging protocol for M2M & IoT
communications
n Telemetry = Tele-Metering = Remote Measurements
n Telemetry data goes from devices to a server(s) or broker(s)
n MQTT is a many-to-many communication protocol for passing messages between multiple clients
through a central broker or (brokers).
– Invented in 1999 by Andy Stanford-Clark (IBM) and Arlen Nipper (Arcom, now Cirrus Link)
– Original use case was to create a protocol for minimum battery loss and minimum
bandwidth connecting oil pipelines over satellite connections
IFA’2021 4
MQTT OVERVIEW
n Built for proprietary embedded systems; now shifting to IoT
n Messages have a topic, QoS, and retain status associated with them
IFA’2021 5
MQTT OBJECTIVES
– Simple to implement
– Provide a QoS Data Delivery
– Lightweight and Bandwidth Efficient
– Data Agnostic
– Continuous Session Awareness
– Reliability and low power
– “Publish/Subscribe” model
– Requires a central MQTT broker to manage and route messages
– Uses TCP for its transport layer for reliability
IFA’2021 6
MQTT COMPONENTS
MQTT BROKER
n Consists of three parts:
– Broker
– Subscribers
– Publishers
– Both roles can be !!
IFA’2021 7
MQTT BROKER
n Software on a Computer
n On premise or in the Cloud
n Self Builit or 3rd Party hosted
n Open Source or Proprietary
n Receives all messages
n Filters all messages
n Publishes the messages to all subscribed clients
IFA’2021 8
MQTT Concepts
n Topics/Subscriptions:
– Messages are published to topics (news, sports, food, fashion, trave, etc..).
– Clients can subscribe to a topic or a set of related topics
n Publish/Subscribe:
– Clients can subscribe to topics or publish to topics.
– (One to many or many to many or many to one)
Publish Topics Subscribe
Temperature
Temperature
Sensor Apartment
Dweller
Humidity
Sensor Humidity
Building
Light Manager
Sensor Light
IFA’2021 9
MQTT ARCHITECTURE
Sensors MQTT
Sensors
Sensors
Sensors
Sensors
Broker
Sensors
Sensors
Bridge
Broker Broker
Publish Publish Publish
Publish
…/location …/weight …/contents
…/speed
Publisher Publisher Publisher Publisher
IFA’2021 10
Topics
n Each published data specifies a topic
n Each subscriber subscribed to that topic will receive it
n Topic format (TREE): Organized as trees using “/” character (topic level)
n TOPIC replaces the ADDRESS notion!!!
/home/rooms/kitchen/temperature
(topic level) 11
IFA’2021
Publish/Subscribe Concept
Decoupled in space and time:
(Or open source MOSQUITTO
on Windows or Linux)) Clients do not need each others
IP address and port (space) and
they do not need to be running at
the same time (time).
n Subscriptions
– Clean Sessions:
At connection setupà Clean session flag à all subscriptions are removed on disconnect.
(When I disconnect then do not worry about me; I leave Rejkjavik I do not need weather report anymore)
– Durable Connections
l When I disconnect, please save/store it for my future need
l Subscription messages remain in effect after disconnection.
l Subscriber disconnect messages are buffered at the broker and delivered upon reconnection
– Non-durable Connections
l Connection lifetime gives subscription lifetime
IFA’2021 14
State Retention
n Publications
– Retained (“Persistent”) Sessions/Messages
- When a client subscribes to a topic, retained messages are automatically delivered
- Server (Broker) keeps messages even after sending it to all subscribers.
– New subscribers get the retained messages
– One flag set both in the publish packet to the broker and in the
published packet to the subscribers
lOnly the most recent persistent message is stored and distributed
IFA’2021 15
MQTT Session Aware Features
n Last Will and Testament (LWT) Message:
– At connection a client can inform that it has a WILL or a message that should
be published if unpexpected disconnection occurs à Alarm if the client looses
connection
In other words, topic published upon disconnecting a connection
IFA’2021 17
Publishing “QoS” (Reliability)
IFA’2021 18
Publishing “QoS” (Reliability)
n 2 – Delivery “Exactly Once”
[Request to Send (Publish), Clear-to-Send (Pubrel), Message (Pubrel),
ACK (Pubcomp)] (No duplication; no loss)
– Utmost reliability is important – most overhead (4 messages) and slowest
IFA’2021 19
Publishing “QoS” (Reliability)
IFA’2021 20
MQTT Message Format
IFA’2021 21
Message Types
IFA’2021 22
Message Types
IFA’2021 23
MQTT Application Example
MQTT HTTP
Purpose Messaging Documents
Protocol Efficiency High Average
Power Efficiency High Average
QoS Yes No
Client Languages Many Many
IFA’2021 26
MQTT: Advantages
n Publish/Subscribe model
– Brokers and nodes publish information and others subscribe according to the
message content, type, or subject.
– Generally, the broker subscribes to all messages and then manages information
flow to its nodes.
– Advantages
l Space Decoupling:
– Nodes can publish information and subscribe without any knowledge of each other
l Time Secoupling
– Nodes can remain in sleep states even when other nodes are publishing messages
l Synchronization Decoupling
– For nodes in operation, messages are queued by the broker until the receiving node is finished with its
existing operation
IFA’2021 27
MQTT – Disadvantages
n Centralized Broker
– Must be specialized due to increased cost and responsibility
– Can be a drawback for distributed IoT systems
– Can become a single point of failure for the complete network
n TCP
– Designed for devices with more memory and processing resources
(e.g., multi-step handshake)
– With TCP, it is ideal for two communicating nodes to hold their TCP sockets
open for each other continuously with a persistent session.
– Without session persistence, need to establish connection over and over.
IFA’2021 28
CoAP (Constrained Application) Protocol Stack
IFA’2021 29
Constrained Application Protocol (CoAP)
IFA’2021 30
What is REST? (Representational State Transfer)
IFA’2021 31
CoAP FEATURES
IFA’2021 32
CoAP
IFA’2021 33
CoAP REST Compatibility
IFA’2021 34
CoAP Architecture
CoAP has…
UDP
Multicast Support
Security (DTLS)
Use of URI allows interaction
expectations
Asynchronous Comms
(observe) – similar to pub/sub
BUT…
Immature
QoS = confirming message
received
IFA’2021 35
Use Case
Light
LoWPAN-1
Network
Light-1
Router-1
(6LoWPAN Border Router)
LoWPAN-2
Light-2
Router-2
Light-3 (6LoWPAN Border Router)
Use-cases
IP Multicast Group •Group light control
(Room-A-Lights)
Room-A •Firmware updates
•Parameter distribution
IFA’2021 36
CoAP Message Types
IFA’2021 37
CoAP Features
n CoAP provides reliability without using TCP as transport protocol
IFA’2021 38
CoAP: Open Source Implementations
n mbed
n Java CoAP Library Californium
n C CoAP Library Erbium
n libCoAP C Library
n Open CoAP C Library
n TinyOS and Contiki Operating Systems with CoAp Support
IFA’2021 39
CoAP versus HTTP
IFA’2021 40
Comparison CoAP & MQTT
Both used in IoT
n CoAP:
– one-to-one communication
– UDP/IP
– unreliable
– lightweight and easy to implement
n MQTT:
– many-to-many communication
– TCP/IP
– focus on message delivery; reliable
– higher overheads (protocol data, processing costs)
IFA’2021 41