Set up CoAP Server

Last modified by Xiaoling on 2022/07/27 18:05

     Table of Contents:

1.  Introduction

In this chapter, we set up a CoAP/ MQTT server by using Open Source MQTT Broker : EMQX.IO. And show how to communicate it with CoAP and MQTT.

Below is the network structure. The end device use CoAP to connect our Emqx server via NB-IoT network. EMQ X broker will further process the data for the actually application.

 

image-20220530084843-1.png

Network structure

2.  Install CoAP server

Set up example in Ubuntu 18.04

sudo apt-get update
sudo apt-get upgrade
wget https://www.emqx.io/downloads/broker/v3.2.7/emqx-ubuntu18.04-v3.2.7_amd64.deb  #download the installation package.
sudo dpkg –i emqx-ubuntu18.04-v3.2.4_amd64.deb  #install EMQX
emqx start            # Start EMQX service
emqx_ctl status   #check if EMQX is running
./bin/emqx_ctl plugins load emqx_coap # Run COAP service

Notice: CoAP default port use 5683, if you install EMQX in a cloud server, make sure you open the UDP port 5683. So can receive the packets from NB-IoT.

 

3.  Test CoAP Server

3.1  Install Copper in Chrome

1. Download Copper4Cr from https://github.com/mkovatsc/Copper4Cr and unpack it.

2. Run install.bat in the directory.

image-20220530085327-2.png

Run install.bat

3. Load the unpacked CoAP APP in Google Chrome:

image-20220530085423-3.png

Install Copper APP

image-20220530085531-4.png

Install APP Successful

4. Load the unpacked CoAP extension in Google Chrome:

image-20220530085638-5.png

Install Copper Extension

image-20220530090104-7.png

Install Extension Successful

5. Replace the appID in file extension\endpoint\ClientPortChrome.js to Copper (Cu4Cr) Application ID

image-20220530090444-10.png

Replace ID

6. Open the Copper extension. If you see below message, means install successfully.

image-20220530090404-9.png

Install Finished

3.2  Test CoAP connection

Use Chrome Copper externsion to connect to the CoAP server. Input coap://COAP_SERVER_IP/mqtt/topic0?c=t1 to connect to the MQTT topic0 in CoAP server. Replace COAP_SERVER_IP with your COAP Server IP address, and refer here for the CoAP detail in EMQX. When connection ok, you can see below window.

image-20220530090848-13.png

Connect to CoAP server

Try to use MQTT.fx to subscribe a the topic (topic0) in the server. And use CoAP to send a message to this topic, we can see the message arrive the topic0 and shown in MQTT.fx.

image-20220530090939-14.png

Use MQTT.fx to subscribe the topic

image-20220530091358-18.png

Use CoAP Exension to send a update to CoAP server

image-20220530091237-17.png

MQTT.fx get the update of this topic on CoAP server

Try to use MQTT.fx to publish a message to the topic (topic0) in the server. CoAP extension will see this incomming message.

Tags:
    
Copyright ©2010-2022 Dragino Technology Co., LTD. All rights reserved
Dragino Wiki v2.0