Wiki source code of Set up CoAP Server

Version 16.2 by Xiaoling on 2022/07/22 16:43

Show last authors
1 **~ Contents:**
2
3 {{toc/}}
4
5
6
7 = 1. Introduction =
8
9 (((
10 In this chapter, we set up a CoAP/ MQTT server by using Open Source MQTT Broker : [[EMQX.IO>>url:https://www.emqx.io/]]. And show how to communicate it with CoAP and MQTT.
11 )))
12
13 (((
14 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.
15 )))
16
17 [[image:image-20220530084843-1.png]]
18
19 Network structure
20
21
22 = 2. Install CoAP server =
23
24 Set up example in Ubuntu 18.04
25
26 (% class="box" %)
27 (((
28 sudo apt-get update
29 sudo apt-get upgrade
30 wget [[https:~~/~~/www.emqx.io/downloads/broker/v3.2.7/emqx-ubuntu18.04-v3.2.7_amd64.deb>>url:https://www.emqx.io/downloads/broker/v3.2.7/emqx-ubuntu18.04-v3.2.7_amd64.deb]]  #download the installation package.
31 sudo dpkg –i emqx-ubuntu18.04-v3.2.4_amd64.deb  #install EMQX
32 emqx start            # Start EMQX service
33 emqx_ctl status   #check if EMQX is running
34 ./bin/emqx_ctl plugins load emqx_coap # Run COAP service
35 )))
36
37 (((
38 (% style="color:red" %)**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.**
39
40
41 )))
42
43 = 3. Test CoAP Server =
44
45 == 3.1 Install Copper in Chrome ==
46
47 (((
48 ~1. Download Copper4Cr from [[https:~~/~~/github.com/mkovatsc/Copper4Cr>>url:https://github.com/mkovatsc/Copper4Cr]] and unpack it.
49 )))
50
51 (((
52 2. Run install.bat in the directory.
53
54 [[image:image-20220530085327-2.png]]
55 )))
56
57 Run install.bat
58
59
60 3. Load the unpacked CoAP APP in Google Chrome:
61
62 [[image:image-20220530085423-3.png||height="241" width="1250"]]
63
64 Install Copper APP
65
66
67 [[image:image-20220530085531-4.png]]
68
69 Install APP Successful
70
71
72 4. Load the unpacked CoAP extension in Google Chrome:
73
74 [[image:image-20220530085638-5.png||height="338" width="1320"]]
75
76 Install Copper Extension
77
78
79 [[image:image-20220530090104-7.png||height="389" width="1282"]]
80
81 Install Extension Successful
82
83
84 5. Replace the appID in file extension\endpoint\ClientPortChrome.js to Copper (Cu4Cr) Application ID
85
86 [[image:image-20220530090444-10.png]]
87
88 Replace ID
89
90
91 6. Open the Copper extension. If you see below message, means install successfully.
92
93 [[image:image-20220530090404-9.png||height="658" width="1238"]]
94
95 Install Finished
96
97
98 == 3.2 Test CoAP connection ==
99
100 (((
101 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>>url:https://github.com/emqx/emqx-coap]] for the CoAP detail in EMQX. When connection ok, you can see below window.
102
103 [[image:image-20220530090848-13.png||height="616" width="1154"]]
104 )))
105
106 Connect to CoAP server
107
108
109 == 3.3 Test CoAP Uplink ==
110
111 (((
112 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.
113
114 [[image:image-20220530090939-14.png]]
115 )))
116
117 Use MQTT.fx to subscribe the topic
118
119
120 [[image:image-20220530091358-18.png||height="549" width="1035"]]
121
122 Use CoAP Exension to send a update to CoAP server
123
124
125 [[image:image-20220530091237-17.png]]
126
127 MQTT.fx get the update of this topic on CoAP server
128
129
130 == 3.4 Test CoAP Downlink ==
131
132 (((
133 Try to use MQTT.fx to publish a message to the topic (topic0) in the server. CoAP extension will see this incomming message.
134 )))