What is CoAP Protocol ?

CoAP-Constrained Application Protocol is a specialized Internet Application Protocol for constrained devices, as defined in RFC 7252. It enables devices to communicate over the Internet. It is defined as Contrained Application Protocol, and is a protocol intended to be used in very simple hardware. The protocol is especially targeted for constrained hardware such as 8-bits microcontrollers, low power sensors and similar devices that can’t run on HTTP or TLS. It is a simplification of the HTTP protocol running on UDP, that helps save bandwidth. It is designed for use between devices on the same constrained network (e.g., low-power, lossy networks), between devices and general nodes on the Internet, and between devices on different constrained networks both joined by an internet. CoAP is also being used via other mechanisms, such as SMS on mobile communication networks.

The Internet Engineering Task Force Constrained RESTful environments (IETF CoRE) Working Group has done the major standardization work for CoAP. The core of the protocol is specified in RFC 7252, which means that CoAP is still not a standard protocol.

Two new features designed specifically for Internet of Things and M2M are:

Observe at new events happened on sensors or actuators.

Device management and discoverability from external devices.

The main features of this protocol are:

Web protocol used in M2M with constrained requirements

Asynchronous message exchange

Low overhead and very simple to parse

URI and content-type support

Proxy and caching capabilities

When to use



Some of the specific cases in which CoAP are useful are:

Your hardware cannot run HTTP or TLS: If this is the case then running CoAP and DTLS can practically do the same as HTTP. If one is an expert on HTTP APIs, then the migration will be simple. You receive GET for reading and POST, PUT and DELETE for mutations and the security runs on DTLS.

If this is the case then running CoAP and DTLS can practically do the same as HTTP. If one is an expert on HTTP APIs, then the migration will be simple. You receive GET for reading and POST, PUT and DELETE for mutations and the security runs on DTLS. Your hardware uses battery: If this is ones problem then running CoAP will improve the battery performance when compared with HTTP over TCP/IP. UDP saves some bandwidth and makes the protocol more efficient.

If this is ones problem then running CoAP will improve the battery performance when compared with HTTP over TCP/IP. UDP saves some bandwidth and makes the protocol more efficient. A subscription is necessary: If one cannot run MQTT and HTTP polling is impossible then CoAP is a solution

You may like also : MQTT Public Brokers List

You may like also: How To Create Secure MQTT Broker

Some features of CoAP Prtocols are very similar to HTTP even if CoAP must not be considered a compressed HTTP protocol because it is specifically designed for IoT and in more details for M2M so it is very optimized for this task.

From the abstraction protocol layer, CoAP can be represented as:

In this above diagram you can see there are two different layers that make CoAp protocol: Message and Request/Response. The Messages layer deals with UDP and with asynchronous messages. The Request/Response layer manages request/response interaction based on request/response messages.

CoAP Protocol supports four different message types:

Confirmable

Non-confirmable

Acknowledgment

Reset

Now We discuss some term related CoAP Protocol.

Endpoint: An entity that participates in the CoAP protocol. Usually, an Endpoint is identified with a host

Sender: The entity that sends a message

Recipient: The destination of a message

Client: The entity that sends a request and the destination of the response

Server: The entity that receives a request from a client and sends back a response to the client

CoAP Message Model

CoAP Message is lowest layer and deals with UDP exchanging messages between endpoints. CoAP message has unique ID and three parts:

a binary header

a compact options

payload

CoAP protocol uses two kinds of messages:

Confirmable message

Non-confirmable message

A CoAP confirmable message is a reliable message. During exchanging messages between two endpoints, these messages can be reliable. In the CoAP protocol, a reliable message is obtained using a Confirmable message (CON). Using this kind of message, the client can be sure that the message will arrive at the server. A CoAP Confirmable message is sent again and again until the other party sends an acknowledge message (ACK). The ACK message contains the same ID of the confirmable message (CON).

In the above diagram, you can see communication but If the server has troubles managing the incoming request it can send back a Rest message (RST) instead of the Acknowledge message (ACK).

Non-confirmable (NON) messages that don’t require an Acknowledge by the server. These mesages are unreliable messages means do not contain critical information that must be delivered to the server. To this category belongs messages that contain values read from sensors. Even if these messages are unreliable, they have a unique ID.

CoAp Request/Response Model

This is Second layer in the abstraction layer. Here request is sent using a Confirmable (CON) or Non-Confirmable (NON) message. There are several scenarios depending on if the server can answer immediately to the client request or the answer if not available: