One of the widely used protocols for interaction between IoT devices (Internet of Things) or IoT devices and the external environment is a protocol CoAP – Constrained Application Protocol.
CoAP protocol was created by The Internet Engineering Task Force (IETF) Constrained RESTful Environments (CoRE) working group in June 2014. The standard of this protocol is described in the document RFC 7252 .
The CoAP protocol is designed for the interaction of simple devices such as low-power sensors, switches, and valves that are controlled or monitored remotely over the Internet. Such devices are used in the Internet of Things, and the information exchange they generate is called machine-to-machine (M2M) communication. Such devices are often referred to as resource-constrained devices. They usually have limited power resources, little memory, and low power, so it is important to ensure low power consumption and use low-volume message transmission when working with them. The CoAP protocol allows these devices to communicate while meeting all of the requirements. The network in which such devices operate is called a resource-constrained network. An essential feature of the CoAP protocol is its compatibility with the HTTP protocol, which ensures that when it is used, a set of IoT devices that form some kind of network will interact with the World Wide Web.
Using the CoAP protocol
Consider a resource-constrained device such as a sensor. A user may have several sensors installed in a room, which he can control either via the Internet or directly through a resource-constrained network, in case his device has a SoAP-based application installed on it.
In this interaction, the server receives all requests and then individually one-way sends to the relevant device the request relevant to it and waits for a response from it.
The structure of the CoAP protocol has been designed according to the REST architecture. REST (Representational State Transfer) is a type of architecture that allows you to build applications based on the following group of methods:
GET – searches for resources and provides information that corresponds to the resource specified in the URI (Uniform Resource Identifier) link, where the resource is the data source, which, for example, can be a sensor;
PUT – specifies a new action on the resource;
POST – changes an action on a resource;
DELETE – deletes activated features of the resource.
The CoAP protocol was created by The Internet Engineering Task Force (IETF) Constrained RESTful Environments (CoRE) working group in June 2014. The standard for this protocol is described in RFC 7252
In April 2017, an RFC document was released that extends the CoAP protocol with new methods. This standard describes two methods:
FETCH – performs partial information about the resource according to the parameters in the request;
PATCH – is responsible for partial modification of the action on the resource.
The protocol was augmented with these methods because of the need for some applications to access or modify a resource, not completely, but to interact only with a certain part of it.
Access to resources, as mentioned above, is accomplished by a URI character sequence that identifies a physical or abstract resource. The URI identifies CoAP resources and serves as a means to locate them. The user device requests data from the sensor via a URI link, but for this request to be understood by the sensor, it will be converted at the user device into one of the REST methods and entered into a CoAP message. For example, when a URI link is entered, the application on the user device creates a GET request to the sensor where the CoAP protocol message options will contain the URI. More details about translating URIs into the corresponding options are discussed below in the section “Message Format”.
When communicating with the sensor over the Internet, the application on the user’s device will use the HTTP protocol and REST methods to send requests. By using the same methods in the HTTP and CoAP protocols, it is possible to exchange messages between the user device where the application resides and the sensor that uses different protocols, because the messages will easily translate into each other on the proxy.
The CoAP protocol uses UDP (User Datagram Protocol) as the default transport protocol, which reduces the size of the service data and increases efficiency. In rare cases, TCP or SCTP can also be used. Since CoAP is an application layer protocol, DTLS (Datagram Transport Layer Security) message encryption is used in cases where a secure connection is needed. DTLS operates on top of the UDP protocol and serves to protect data at the transport layer (operating between the application layer and the transport layer).
The paper has considered such important features of the protocol as message format, different interaction scenarios, and ways of grouping devices with limited resources.
The reviewed material allows us to conclude about the significant advantages of the CoAP protocol that distinguish it from other Internet of Things protocols, for example, unlike MQTT , CoAP has a small message volume, simple algorithms for their processing, as well as support for multicasting. CoAP protocol is focused on M2M applications and provides interaction of IoT networks with the Internet through CoAP-proxy.
CoAP protocol is appropriate for devices and networks with limited resources.