Professional IoT solution equipment supplier

Internet of Things Communication Protocol – CoAP

Custom Solutions 2022-10-03 35 views

Overview

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 a protocol intended for use on very simple hardware. This protocol is particularly suitable for constrained hardware, such as 8-bit microcontrollers, low-power sensors, and similar devices that cannot run HTTP or TLS. It is a simplified version of the HTTP protocol that runs over UDP, helping to conserve bandwidth. It is designed for use between devices on the same constrained network (e.g., low-power, lossy networks), between devices on the Internet and general nodes, and between devices on different constrained networks connected by the Internet. CoAP is also utilized via other mechanisms, such as SMS over mobile communication networks.

CoAP Features

  • Meets M2M requirements in constrained network protocol environments
  • UDP [RFC0768] binding with optional reliability supports unicast and multicast requests
  • Asynchronous message exchange
  • Low header overhead and parsing complexity
  • URI and content-type support
  • Simple proxy and caching capabilities

CoAP Protocol

It extends ordinary HTTP clients to clients with resource constraints. These clients are called CoAP clients. Proxy devices bridge the gap between the constrained environment and the typical Internet environment based on the HTTP protocol. The same server is responsible for handling both HTTP and CoAP protocol messages.

CoAP Protocol Stack

CoAP Architecture

CoAP Data Format

CoAP Data Format

The CoAP message format consists of a 4-byte header and a token value (0 to 8 bytes). The table below describes the header identifier, which consists of 4 bytes (i.e., 32 bits).

CoAP Message Header IdentifierDescription
VerIt is a 2-bit unsigned integer. It indicates the CoAP version number. Set to 1.
TIt is a 2-bit unsigned integer. Indicates the message type: Confirmable (0), Non-confirmable (1), Acknowledgement (2), or RESET (3).
TKLIt is a 4-bit unsigned integer indicating the token length (0 to 8 bytes).
CodeIt is an 8-bit unsigned integer, divided into two parts: a 3-bit class (MSB) and a 5-bit detail (LSB).
Message ID16-bit unsigned integer. Used to match responses and detect message duplication.
CoAP Header Identifier

CoAP Data Exchange

Protocol messages are exchanged between CoAP clients and CoAP servers in two modes: separate response mode and non-separate response mode.

With a separate response, the server notifies the client that the request message has been received. This increases processing time but helps avoid unnecessary retransmissions. Because it uses UDP, CoAP for IoT is an unreliable protocol. Therefore, CoAP messages may arrive out of order or be lost upon reaching their destination.

To make CoAP a reliable protocol, a stop-and-wait mechanism with exponential backoff retransmission is employed. Duplicate detection is also introduced.

CoAP Applications in Smart Homes

Smart home networks provide control and monitoring of home devices and energy. The energy control system uses smart sockets to manage and monitor power-consuming devices, providing voltage, current, and other energy information. This enables accident warnings, remote control, and dynamic energy savings. The system structure is shown in Figure 12. Each data collection node using a CoAP client can exchange information with other nodes. CoAP can be installed on either a local area network or the Internet. Unlike many wireless protocols used for home automation devices, CoAP is designed not to be limited to local networks but to provide foundational data for networking. In this system, a CoAP-HTTP proxy is used to provide HTTP client connectivity to CoAP resources and vice versa.

Energy Control System

Device energy information and environmental information are collected by smart sockets, transmitted via wireless channels to the data acquisition module, which then sends serial data to the proxy for processing and packaging. The control server analyzes all data and stores it in a database. The system integrates home networks and the Internet, allowing users to access the system's web page to remotely control switches, manage configurations, query energy consumption, etc.

CoAP & MQTT

MQTT is another protocol widely used in IoT. There are some differences between these two protocols. The first aspect to note is the different paradigms used. MQTT uses a publisher-subscriber model, while CoAP uses a request-response paradigm. MQTT uses a central broker to dispatch messages from publishers to clients. CoAP is essentially a one-to-one protocol, very similar to the HTTP protocol. Furthermore, MQTT is an event-oriented protocol, while CoAP is more suitable for state transfer.

References

Website Editor-in-Chief:

Content Reviewer:
online_customer_service
welcome_to_customer_service