summarize
CoAP (Constrained Application Protocol) is a specialized Internet protocol for constrained devices defined in RFC 7252. application protocols. It enables devices to communicate over the Internet. It is defined as a protocol intended for use with very simple hardware. The protocol is particularly suitable for constrained hardware such as 8-bit microcontrollers, low-power sensors and similar devices that cannot run over HTTP or TLS. It is a simplification of the HTTP protocol that runs over UDP and helps save bandwidth. It is designed to be used between devices on the same restricted network (e.g., low-power, lossy networks), between devices and general nodes on the Internet, and between devices on different restricted networks connected by the Internet.CoAP is also used through other mechanisms, such as SMS on mobile communication networks.
CoAP Features
- Network protocol environments that fulfill M2M requirements in constrained situations
- UDP with optional reliability [RFC0768] Binding support for unicast and multicast requests
- asynchronous message exchange
- Low header overhead and parsing complexity
- URI and content type support
- Simple proxy and caching features
CoAP protocol
It extends normal HTTP clients to clients with resource constraints. These clients are called CoAP clients. Proxy devices bridge the gap between constrained and typical Internet environments based on the HTTP protocol. The same server handles both HTTP and CoAP protocol messages.
CoAP stack


CoAP data format

CoAP message format, consisting of a 4-byte header and a token value (from 0 to 8 bytes). The following table mentions the header identifier consisting of 4 bytes (i.e. 32 bits)
CoAP message header identification | clarification |
Ver | It is a 2-bit unsigned integer. It refers to the CoAP version number. It is set to 1. |
T | It is a 2-bit unsigned integer. Indicates the message type, i.e., Acknowledged (0), Not Acknowledged (1), Acknowledged (2), or RESET (3). |
TKL | It is a 4-bit unsigned integer that represents the length of the token (0 to 8 bytes). |
Code | It is an 8-bit unsigned integer that is divided into two parts, the 3-bit class (MSB) and the 5-bit detail (LSB). |
Message ID | 16-bit unsigned integer. Used to match responses. Used to detect duplicate emails. |
CoAP data exchange
Protocol messages are exchanged between the CoAP client and the CoAP server in two modes, individual response mode and non-individual response mode
With a separate response, the server notifies the client of the receipt of the request message. This increases processing time, but helps avoid unnecessary retransmissions. Due to the use of UDP, CoAP IoT is an unreliable protocol. As a result, CoAP messages arrive out of order or are lost when they reach their destination.
In order to make CoAP a reliable protocol, stopping and waiting when it contains the exponential backoff retransmission feature. Duplicate detection was also introduced
CoAP in the Smart Home
Smart home networks provide control of home devices and monitor energy. The energy control system uses smart outlets to manage and monitor power-consuming devices to provide voltage, current, and other energy information. Accident warning, remote control, and dynamic energy saving can be realized. The system architecture is shown in Fig. 12. Each data collection node using a CoAP client can exchange information with other nodes.CoAPs can all be installed on a LAN or the Internet. Unlike many wireless protocols used for home automotive devices, CoAP is designed to be independent of the local network and instead provides the underlying data for the network.In this system, the CoAP-HTTP proxy is used to provide HTTP client connections to CoAP resources and vice versa.In this system, the CoAP-HTTP proxy is used to provide HTTP client connections to CoAP resources and vice versa.

The energy information and environmental information of the device is collected by the smart socket, transmitted to the data acquisition module through a wireless channel, and then serial data is sent to the agent for processing and packaging. The control server analyzes all the data and stores it in a database. The system integrates the home network and the Internet, and users can access the system webpage to remotely control switches, manage configurations, and query energy consumption, etc.
CoAP & MQTT
MQTTis another protocol widely used in IoT. There are some differences between the two protocols. The first aspect to note is the different paradigms used. mQTT uses a publisher-subscriber, while CoAP uses a request-response paradigm. mQTT uses a centralized agent to dispatch messages from the publisher to the client. coAP is essentially a one-to-one protocol, much like the HTTP protocol. In addition, MQTT is an event-oriented protocol, whereas CoAP is better suited for stateful transport.
bibliography
Content review.