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.

https://wiki.dragino.com/images/thumb/4/47/CoAP_Test_1.png/600px-CoAP_Test_1.png

Run install.bat

3. Load the unpacked CoAP APP in Google Chrome:

https://wiki.dragino.com/images/thumb/8/8b/CoAP_Test_2.png/600px-CoAP_Test_2.png

Install Copper APP

File:CoAP Test 3.png

Install APP Successful

4. Load the unpacked CoAP extension in Google Chrome:

https://wiki.dragino.com/images/thumb/6/65/CoAP_Test_4.png/600px-CoAP_Test_4.png

Install Copper Extension

https://wiki.dragino.com/images/thumb/9/99/CoAP_Test_5.png/600px-CoAP_Test_5.png

Install Extension Successful

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

https://wiki.dragino.com/images/thumb/7/7e/CoAP_Test_6.png/600px-CoAP_Test_6.png

Replace ID

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

https://wiki.dragino.com/images/thumb/b/b1/CoAP_Test_7.png/600px-CoAP_Test_7.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.

https://wiki.dragino.com/images/thumb/0/0c/CoAP_Test_8.png/600px-CoAP_Test_8.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.

https://wiki.dragino.com/images/thumb/b/b0/CoAP_Test_9.png/600px-CoAP_Test_9.png

Use MQTT.fx to subscribe the topic

https://wiki.dragino.com/images/thumb/3/39/CoAP_Test_10.png/600px-CoAP_Test_10.png

Use CoAP Exension to send a update to CoAP server

https://wiki.dragino.com/images/thumb/f/fe/CoAP_Test_11.png/600px-CoAP_Test_11.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