Coap MQTT - v2
Coap MQTT - v2
• Message Overhead
• HTTP:
• HTTP headers are verbose(provides detailed
information) and can add significant overhead to each
message, which is fine for powerful servers but inefficient
for constrained devices.
• CoAP:
• CoAP uses compact binary headers and much smaller
message sizes.
• This makes it more suitable for devices with limited
bandwidth, memory, and processing power.
CoAP and HTTP-Important differences
• Reliability
• HTTP:
• Provides guaranteed delivery and ordered messages through
TCP. If a message is lost, TCP ensures it is retransmitted.
• CoAP:
• Uses confirmable messages to achieve reliability.
• When a device sends a confirmable message, it waits for an
acknowledgment (ACK) from the recipient.
• If no ACK is received, the message is retransmitted.
• However, CoAP also supports non-confirmable messages,
which do not require an acknowledgment, trading reliability
for speed and simplicity.
CoAP and HTTP-Important differences
• Stateless Communication
• HTTP:
• Is a stateless protocol, meaning each request/response
pair is independent, with no session state maintained
between messages.
• CoAP:
• Also follows a stateless model like HTTP.
• Each CoAP request-response pair is independent, but
CoAP can maintain state across multiple devices using
block-wise transfers to handle larger payloads in smaller
parts.
CoAP and HTTP-Important differences
• Resource Discovery
• HTTP:
• Does not have built-in resource discovery; external
methods (such as using APIs or protocols like DNS
Service Discovery) are typically needed.
• CoAP:
• Has built-in mechanisms for resource discovery.
• Devices can advertise their resources, and other
devices can easily find them using the CoAP discovery
features.
CoAP and HTTP-Important differences
• Security
• HTTP:
• Uses TLS (Transport Layer Security) over TCP for secure
communication, adding encryption and authentication,
which increases the overhead.
• CoAP:
• Uses DTLS (Datagram Transport Layer Security) over
UDP for encryption and authentication.
• DTLS is a lightweight version of TLS designed for
connectionless protocols like UDP, providing security
while maintaining low overhead.
CoAP: Four types of messages
• Messages are used to communicate between
devices
• Each serving a specific purpose in communication
• Message types help manage communication
efficiency,Four types
reliability,
of messages
and flexibility for
constrained devices and networks
• Four types of messages
– confirmable (CON),
– non-confirmable (NON),
– acknowledgement,
– reset
CoAP: Four types of messages
• Confirmable Message (CON)
• Purpose:
• A confirmable message is used when a device wants to
ensure that the message it sent is received by the other
device. It’s like sending a letter where you need a receipt
(acknowledgment) that the recipient got it.
– Example:
• A temperature sensor sends a confirmable message with
the current temperature to a smart thermostat.
• The thermostat acknowledges (ACK) that it received the
temperature.
• If the sensor doesn’t receive the acknowledgment, it will
resend the message.
CoAP: Four types of messages
• Non-confirmable Message (NON)
• Purpose:
• A non-confirmable message is sent when the sender
doesn’t care whether the message is received or not.
It’s like broadcasting a message to a room where you
don’t expect anyone to respond.
• Example:
• A motion sensor sends a non-confirmable message to
the lights to turn on when it detects movement.
• The motion sensor doesn’t expect a response or
confirmation from the lights that the message was
received. If the message is lost, it won't resend it.
CoAP: Four types of messages
• Acknowledgment Message (ACK)
• Purpose:
• An acknowledgment message is sent in response to a
confirmable message to tell the sender, “I got your
message.”
• Example:
• The thermostat sends an acknowledgment message
back to the temperature sensor after receiving the
current temperature.
• This lets the sensor know that its message was
successfully delivered.
CoAP: Four types of messages
• Reset Message (RST)
• Purpose:
• A reset message is sent when the receiver gets a
message it can’t process or doesn’t understand. It’s like
saying, “I don’t understand this message, please stop.”
• Example:
• A smart light bulb receives a message from a controller
to turn on, but the message is corrupt or incorrect.
• The light bulb sends a reset message (RST) back to the
controller, telling it that the message couldn’t be
processed.
CoAP: Four types of messages
• conceptual structure that divides CoAP into different functional layers,
simplifying communication and making it modular.
providing transport
• Client-Server Model:
• CoAP follows a basic client-server model, similar
to the web's HTTP system. The client sends a
request to access or manipulate resources, and
the server responds to that request.
• Client:
• Requests data or performs actions (e.g., a smart
thermostat asks for temperature data).
• Server:
• Provides data or responds to actions (e.g., a
temperature sensor sends back the current
temperature).
CoAP: Architecture
• RESTful Design:
• CoAP is built around the REST (Representational
State Transfer) architecture, using familiar
methods like GET, POST, PUT, and DELETE to
interact with resources. Resources are identified
using URIs (just like URLs on the web).
• Example:
• A client may send a GET request to a sensor's URI to get
the current temperature reading.
CoAP: Architecture