CoAP protocol is a network-oriented protocol proposed by the IETF, which adopts similar characteristics to HTTP, and the core content is resource abstraction, RESTful interaction, and extensible header options. The CoAP protocol is based on the REST architecture, which refers to the expressive state transition architecture, which is the general design style of the Internet resource access protocol. In order to overcome the disadvantages of HTTP for constrained environments, CoAP takes into account both the optimization of the data report length and the provision of reliable communication. On the one hand, CoAP provides URIs, RESTful methods such as GET, POST, PUT, and DELETE, as well as the extensibility provided by header options that can be defined independently. CoAP, on the other hand, is based on the lightweight UDP protocol and allows IP multicast. To compensate for the unreliability of UDP transmission, CoAP defines a transaction processing mechanism with a retransmission mechanism. It also provides a resource discovery mechanism with a resource description.
The transport layer is the CoAP protocol packet format, the CoAP is carried by UDP, follows the basic UDP protocol packet format, and the UDP data content is written and transmitted in accordance with the CoAP packet format.
Ver version number, which indicates the version number of the CoAP protocol. Similar to HTTP 1.0 HTTP 1.1. The version number occupies two digits, and the value in the example is 01B.
The CoAP protocol defines four types of packets: CON packets, NON packets, ACK packets, and RST packets.
The length of the TKLCoAP identifier. The CoAP protocol has two identifiers with similar functions, one is the message ID and the other is the token. Each of these packets contains a message number, but the identifier is not required for the message.
Code function code/response code. Code occupies one byte, which is divided into two parts, the first three bits and the last five bits, and is written as a c.dd structure for easy description. where 0. XX represents a certain method of the CoAP request, while 2. XX, 4.XX, or 5.XX indicates a specific manifestation of the CoAP response.
The message ID packet number.
For the specific content of the token identifier, the length of the token is specified by TKL.
Option: You can use the packet options to set the CoAP host and CoAP
URIs, CoAP request parameters, payload media types, and so on.
CoAP supports multiple Options, and the Options of CoAP are described in a special way in an incremental manner. In general, the Option section consists of Option Delta, Option Length, and Option Val.
Option Delta represents the increment of the Option, and the specific number of the current Option is equal to the sum of all previous Option Deltas.
Option Length indicates the specific length of the Option Val terminal device.
The Option Val terminal device indicates the specific content of the Option.
For details about the values in CoAP packets, see IETF RFC7252.
Device Login Packet
Parameter | Description |
---|---|
POST | $sys/{pid}/{device-name}/login |
HOST | {Acc-ip} |
PORT | 5683 |
Code | POST |
Type | Con |
Content-Format | application/json |
payload | {"lt":86400, "st":"xxxxxx"} |
Parameters of device login packets
Parameter | Description |
---|---|
pid | Product ID |
device-name | {Acc-ip} |
HOST | Access address, in the following example: 183.230.102.122 |
Port | port, the value in the following example is 5683 |
Content-Format | The uplink data that the device sends to IoT Platform is in the application/json format that supports |
payload | The content of the device login information, in JSON data format. The lt parameter is the keep-alive time in seconds, and the parameter ST is the generated authentication information |
Returns results
Parameter | Description |
---|---|
Resp-success | 2.0.1CreatedPayload:{token} |
Resp-failed | 4.00 Bad Request/4.03 Forbidden |
Device keep-alive
Device keep-alive packets
Parameter | Description |
---|---|
POST | $sys/{pid}/{device-name}/keep_alive |
HOST | {Acc-ip} |
PORT | 5683 |
Code | POST |
Type | Con |
Content-Format | application/json |
payload | {"lt":86400, "st":"xxxxxx"} |
Returns results
Parameter | Description |
---|---|
Resp-success | 2.04 Changed |
Resp-failed | 4.00 Bad Request/4.04 Not Found |
Device Thing Model Uplink
Attribute Class:
Attribute reporting: $sys/{pid}/{device-name}/thing/property/post
Desired property acquisition: $sys/{pid}/{device-name}/thing/property/desired/get
Desired deletion of properties: $sys/{pid}/{device-name}/thing/property/desired/delete
Event Class:
The uplink parameters of the Thing model are described as follows:
Parameter | Description |
---|---|
POST | Use the upstream topic, defined by the Thing model |
HOST | {Acc-ip} |
PORT | 5683 |
Code | POST |
Type | Con/Non |
Accept | application/json |
Content-Format | application/json |
payload | Thing model data |
Thing Model Downlink Command
Attribute Class:
Set property: $sys/{pid}/{device-name}/thing/property/set
Get property: $sys/{pid}/{device-name}/thing/property/get
Service:
The following table describes the downstream parameters of the Thing model:
Parameter | Description |
---|---|
POST | Use the downstream topic, defined by the Thing model |
HOST | Device IP |
PORT | Device connection port |
Code | POST |
Type | Con |
Accept | application/json |
Content-Format | application/json |
payload | Set the Thing model data for the property |
Thing model downstream command response packets:
Parameter | Description |
---|---|
Code | 2.05 content |
HOST | {Acc-ip} |
PORT | 5683 |
Type | Ack |
Accept | application/json |
Content-Format | application/json |
payload | Thing model response data |
Device Logout
Device logout packets:
Parameter | Description |
---|---|
POST | $sys/{pid}/{device-name}/logout |
HOST | {Acc-ip} |
PORT | 5683 |
Code | POST |
Type | Con |
Content-Format | application/json |
payload | { "st":"xxxxxx"} |
Returns results
Parameter | Description |
---|---|
Resp-success | 2.02 Deleted |
Resp-failed | 4.00 Bad Request/4.03 Forbidden |
Platform Access Address
Communication protocol | Address | Port | Description |
---|---|---|---|
CoAP | www.onenet.hk.chinamobile.com | 5683 | Unencrypted port |