After HTTP, MQTT and CoAP are perhaps the most commonly used communication protocols for connecting devices to the Internet of Things. But what are MQTT and CoAP, and what benefits do they provide over plain old HTTP?
In this session we’ll start by looking at the limitations to using HTTP in the IoT world. We will then introduce MQTT and CoAP, and explain why these can be compelling replacements for HTTP. By examining the strengths and weaknesses for HTTP, MQTT and CoAP we’ll identify IoT use cases for all three.
13. MQTT Quality of Service
• Guarantees
delivery.
• QoS level set for
each message by
the Client.
QoS Level 0
• At most once.
• Fire and forget – no delivery guaranteed.
• Fastest.
QoS Level 1
• At least once.
• Guaranteed delivery.
• Message repeatedly sent until an acknowledgement
is received from recipient.
• Duplicate messages can be received.
QoS Level 2
• Exactly once.
• Guaranteed delivery.
• Each message will be received exactly once.
• Requires an extra round of communication between
sender and receiver.
• Verbose solution, only use if needed.
15. Other Features of MQTT
Last will and
testament
• A normal MQTT message
with specified topic,
message and QoS.
• Specified by Client on
connection to the Broker.
• If the Client abruptly
disconnects the LWT
message will be sent to all
topic subscribers.
MQTT over WebSockets
• Modern web browsers are not
built to understand MQTT.
• MQTT over WebSockets
provides a mechanism for Web
Browsers to directly
communicate with n MQTT
Broker.
• Not all MQTT Browsers support
WebSocket connections.
Retained Messages
• A normal MQTT message with
specified topic, message and
QoS.
• Stored by the Broker until
explicitly removed.
• Sent to all new topic subscribers
immediately after they subscribe.
• Useful for topics with low traffic.
18. TCP vs. UDP
Transmission Control Protocol
• Header size is 20 bytes.
• Connection based, reliable.
• Heavyweight - handles
reliability, delivery order and
congestion control.
• Suits applications that require
high reliability.
• Used by HTTP, FTP, etc.
User Datagram Protocol
• Header size is 8 bytes.
• Connectionless, unreliable.
• Lightweight – simple transport
layer on top of IP.
• Suits applications that require
speed.
• Used by DNS, VOIP, etc.
23. Introducing CoAP
• Constrained Application Protocol.
• Based on RESTful architecture - with extensions.
• UDP + CoAP minimizes amount of bytes flowing
over the wire compared to HTTP – suitable for
extremely constrained environments.
• Built in retry mechanism (QoS).
• Request/Response model a-la HTTP (no broker).
Application Layer
MQTT
Transport Layer
TCP
Network Layer
IP
CoAP
UDP
IP
25. CoAP Security
• CoAP is unable to take advantage of the TCP based security
mechanisms such as TLS.
• Datagram Transport Layer Security (DTLS) to the rescue!
• DTLS is basically an implementation of TLS for UDP, with the added
functionality required for the connectionless UDP (for example packet
loss and ordering).
26. Observe a Resource
• Activated by sending a GET request
with Observe flag switched on.
• Good alternative when MQTT and
HTTP polling is impossible.
• Results in streaming notifications
when resource is changed.
• Can be terminated at any point by
both parties.
Resource
Discovery
• CoAP supports resource
discovery a-la REST.
• Servers provide a list of
their resources at /.well-
known/core.
• Allow clients to discover
resources, and fin out
which media types they
are.
Content
Negotiation
• Same as standard
HTTP.
• Clients can express a
preferred
representation of a
resource (i.e. XML,
JSON, Plain Text).
• Servers can tell clients
what they are getting.
Other Features of CoAP
30. What about HTTP2?
• HTTP2 offers many improvements over HTTP1.1 that can make it
attractive in the IoT space.
Compared to MQTT
• HTTP2 lacks guaranteed
delivery.
• HTTP2 more verbose that
MQTT.
• HTTP2 supports pub/sub
and request/response.
Compared to CoAP
• CoAP and HTTP2 support
server push (i.e. Observe).
• CoAP built for REALLY
constrained devices and
networks.
• HTTP2 built for TCP, not UDP.
Compared to HTTP1.1
• HTTP2 introduces header
compression and is a binary
protocol – less bytes over the
wire.
• HTTP2 supports pub/sub and
request/response.