How to Use EMQX Cloud to Access CoAP Devices

Introduction to the CoAP Protocol

Due to the complexity and diversity of IoT scenarios, hardware conditions at the device side, network stability, traffic limitations, device power consumption, and the number of device connections, the messaging of IoT devices is very different from the traditional Internet scenarios, and therefore a variety of IoT communication protocols have been created.

Protocol Features

CoAP is based on many HTTP design ideas but also improves many design details according to the specific situation of resource-constrained devices, adding many practical features. For example:

  • Based on the message model
  • Transport layer based on UDP protocol, supporting restricted devices
  • Use a request/response model similar to HTTP requests, HTTP is in text format, CoAP is in binary format, and more compact than HTTP
  • Supports bi-directional communication
  • Lightweight and low power consumption
  • Supports reliable transmission, data retransmission, and block transfer to ensure reliable data arrival
  • Supports IP multicast
  • Supports watch mode
  • Support asynchronous communication

Market Status

Compared to MQTT, CoAP is lighter, has lower overhead, and is more appropriate in the certain device and network environments.

CoAP Protocol Access to EMQX Cloud

Create Deployment

Create a new deployment and get the public network connection address: 120.77.x.x on the EMQX Cloud deployment page.

Turn on the CoAP Access Gateway

CoAP access gateway is currently in internal testing, you can submit a work order to enable the access capability. Once enabled, the CoAP Access Gateway address is your deployment connection address, 120.77.x.x, on port udp 5683.

Connecting to Deployments, Publishing Messages

The libcoap is a very easy-to-use CoAP client library, and we use it here as a CoAP client to test the functionality of the EMQX Cloud CoAP access gateway.

git clone
cd libcoap
./configure --enable-documentation=no --enable-tests=no
  • Topic name: “topic1”
  • Client ID: “client1”
  • User name: “emqx”
  • Password: “public”
  • Payload: “hello,EMQX Cloud”
# CoAP terminal sends the message "hello EMQX Cloud",topic 为 topic1
./examples/coap-client -m put -e "hello,EMQX Cloud" "coap://120.77.x.x:5683/mqtt/topic1?c=client1&u=emqx&p=public"
  • The topic name is: “topic1”
  • Client ID is: “client1”
  • User name: “emqx”
  • Password is: “public”
  • Payload is: “hello,EMQX Cloud”
# CoAP terminal subscribe to topic1,-s 20 means the subscription is maintained for 20 seconds ./examples/coap-client -m get -s 20 "coap://120.77.x.x:5683/mqtt/topic1?c=client1&u=emqx&p=public"


At this point, we have completed the whole process of using the CoAP protocol gateway to access EMQX Cloud.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
EMQ Technologies

EMQ Technologies

EMQ is an open-source IoT data infrastructure software provider, delivering the world’s leading open-source MQTT message broker and stream processing database.