CoAP protocol learning notes-CoAP format details (1)
CoAP is synonymous with restricted Application protocols. In the current world composed of PCs, information exchange is achieved through TCP and the application layer protocol HTTP. However, for small devices, implementing TCP and HTTP protocols is obviously an excessive requirement. To allow small devices to access the Internet, the CoAP protocol is designed. CoAP is an application layer protocol that runs over UDP rather than over TCP as HTTP. The CoAP protocol is very small, and the minimum data packet is only 4 bytes.
1. CoAP protocol Overview
Like the protocols in other tcp ip protocol clusters, the CoAP protocol always appears in the form of a "Header" before the load, while the load and CoAP headers are separated by a single byte 0xFF. The best way to learn the CoAP protocol is to analyze each part of the CoAP protocol message format in detail in combination with the RFC documentation. It is the CoAP Protocol packet structure.
Figure 1.1 CoAP Protocol packet structure
2 CoAP protocol packets
Ver indicates the version number of the CoAP protocol. Similar to HTTP 1.0 HTTP 1.1. The version number occupies 2 digits and the value is 01B.
T] Message type. The CoAP Protocol defines four different types of packets: CON, NON, ACK, and RST.
TKL: length of the CoAP identifier. CoAP has two similar identifiers: Message ID and Token ). Each packet contains a message ID, but the identifier is not required for the message.
Code: Function Code/response Code. Code has different forms in the CoAP request message and Response Message. Code occupies one byte and is divided into two parts: the first three parts and the last five parts, it is written as c. dd structure. 0. XX indicates a method of CoAP request, while 2.xx, 4. XX or 5. XX indicates a specific manifestation of CoAP response.
Message ID: the number of the Message.
Token: Specifies the Token length through TKL.
Option: Message Option. You can set the CoAP host, CoAP URI, CoAP request parameters, and load media type.
1111 11b: the delimiter between the CoAP message and the specific load.