Last modified by Alec Chen on 2025/04/02 18:03

From version 8.1
edited by Alec Chen
on 2025/04/02 17:57
Change comment: There is no comment for this version
To version 2.2
edited by Alec Chen
on 2025/04/02 16:28
Change comment: There is no comment for this version

Summary

Details

Page properties
Title
... ... @@ -1,1 +1,1 @@
1 -How to Uplink -NB and -CB series devices data by MQTT with Thingseye
1 +How to communice Dragino -NB and -CB series devices data by MQTT with Thingseye
Content
... ... @@ -1,7 +1,5 @@
1 1  **Table of Contents:**
2 2  
3 -{{toc/}}
4 -
5 5  = 1. Introduction =
6 6  
7 7  This document guides you on integrating Dragino **-NB** and **-CB** series devices data with Thingseye.
... ... @@ -17,10 +17,132 @@
17 17  [[image:https://wiki.dragino.com/xwiki/bin/download/Main/ThingsBoard/ins1.png?width=500&height=310&rev=1.1||alt="ins1.png" height="310" width="500"]]
18 18  
19 19  
20 -= (% style="color:#333333; font-family:inherit; font-size:max(23px, min(29px, 12.3333px + 1.38889vw))" %)3. Configure Thingseye's Integration(%%) =
18 += 3.General MQTT Connection =
21 21  
22 -== 3.1 Creat new MQTT integration ==
20 +The NB-IoT Sensor can send packet to server use MQTT protocol.
23 23  
22 +Below are the commands.
23 +
24 +**AT Commands:**
25 +
26 +{{code language="none"}}
27 +AT+PRO=3,0                           //  Set to use MQTT protocol to uplink, Payload Type select Hex payload.
28 +AT+SERVADDR=120.24.4.116,1883        //  Set MQTT server address and port
29 +AT+CLIENT=CLIENT                     //  Set up the CLIENT of MQTT
30 +AT+UNAME=UNAME                       //  Set the username of MQTT
31 +AT+PWD=PWD                           //  Set the password of MQTT
32 +AT+PUBTOPIC=NSE01_PUB                //  Set the sending topic of MQTT
33 +AT+SUBTOPIC=NSE01_SUB                //  Set the subscription topic of MQTT
34 +{{/code}}
35 +
36 +[[image:https://wiki.dragino.com/xwiki/bin/download/Main/General%20Configure%20to%20Connect%20to%20IoT%20server%20for%20-NB%20%26%20-NS%20NB-IoT%20models/WebHome/image-20230802112413-4.png?rev=1.1||alt="image-20230802112413-4.png"]]
37 +
38 +[[image:https://wiki.dragino.com/xwiki/bin/download/Main/General%20Configure%20to%20Connect%20to%20IoT%20server%20for%20-NB%20%26%20-NS%20NB-IoT%20models/WebHome/image-20230802112413-5.png?width=987&height=530&rev=1.1||alt="image-20230802112413-5.png" height="530" width="987"]]
39 +
40 +(% class="text-uppercase small mark" %)##**Notice: MQTT protocol has a much higher power consumption compare with UDP/CoAP protocol. Please check the power analyze document and adjust the uplink**##
41 +
42 +(% class="text-uppercase small mark" %)##**period to a suitable interval.**##
43 +
44 += 4. Data Converters =
45 +
46 +In **Thingseye**, **Data Converters** are components used to transform incoming or outgoing data between different formats, typically to convert raw telemetry data from devices into a structured format that Thingseye can understand, or vice versa.
47 +
48 +== 4.1 Uplink ==
49 +
50 +In the left navigation, click **Integrations center**, and then click **Data converters**.
51 +
52 +On the **Data converters** page, click on the ‘**+**’ button, and then click on the **Create new converter** from the dropdown menu.
53 +
54 +[[image:1743578461281-635.png]]
55 +
56 +
57 +
58 +
59 +The **Add data converter** window will appear.
60 +
61 +Let's create an uplink data converter for the device named '**Device A**'. Name it ‘**MQTT Uplink Converter - Device A**’ and select the Type as **Uplink**.
62 +
63 +Click on the **TBEL** button if it has not been selected by default.
64 +
65 +Modify the default TBEL function to match with your device as described below:
66 +
67 +* Uncomment** line 11**:
68 +
69 +//var data = decodeToJson(payload)//
70 +
71 +* **Line 13**: Assign your device name to the **deviceName** field. - We used **Device A** as it is to match with our device, **Device A **in the Devices section.
72 +* From **line 38**: Modify the telemetry section to allow parsed data to be assigned to the fields.
73 +
74 +//telemetry: {
75 + temperature: data.temperature,
76 + humidity: data.humidity,
77 + rawData: payloadStr
78 + }//
79 +
80 +The modified uplink decoder function to match with **Device A** is shown below.
81 +
82 +{{code language="nono"}}
83 +// Decode an uplink message from a buffer
84 +// payload - array of bytes
85 +// metadata - key/value object
86 +
87 +/** Decoder **/
88 +
89 +// decode payload to string
90 +var payloadStr = decodeToString(payload);
91 +
92 +// decode payload to JSON
93 +var data = decodeToJson(payload);
94 +
95 +var deviceName = 'Device A';
96 +var deviceType = 'thermostat';
97 +var customerName = 'Customer C';
98 +var groupName = 'thermostat devices';
99 +var manufacturer = 'Example corporation';
100 +// use assetName and assetType instead of deviceName and deviceType
101 +// to automatically create assets instead of devices.
102 +// var assetName = 'Asset A';
103 +// var assetType = 'building';
104 +
105 +// Result object with device/asset attributes/telemetry data
106 +var result = {
107 +// Use deviceName and deviceType or assetName and assetType, but not both.
108 +  deviceName: deviceName,
109 +   deviceType: deviceType,
110 +// assetName: assetName,
111 +// assetType: assetType,
112 +// customerName: customerName,
113 +  groupName: groupName,
114 +   attributes: {
115 +       model: 'Model A',
116 +       serialNumber: 'SN111',
117 +       integrationName: metadata['integrationName'],
118 +       manufacturer: manufacturer
119 +   },
120 +   telemetry: {
121 +       temperature: data.temperature,
122 +       humidity: data.humidity,
123 +       rawData: payloadStr
124 +   }
125 +};
126 +
127 +/** Helper functions 'decodeToString' and 'decodeToJson' are already built-in **/
128 +
129 +return result;
130 +{{/code}}
131 +
132 +Once you modify the decoder function, click on the **Add** button.
133 +
134 +[[image:https://wiki.dragino.com/xwiki/bin/download/Main/ThingsBoard/ul-data-converter-device-a.png?width=500&height=524&rev=1.1||alt="ul-data-converter-device-a.png"]]
135 +
136 +You should see that the newly added **MQTT Uplink converter **NB/CB is listed on the **Data Converters** page.
137 +
138 +[[image:https://wiki.dragino.com/xwiki/bin/download/Main/ThingsBoard/ul-data-converter-added.png?height=257&rev=1.1||alt="ul-data-converter-added.png"]]
139 +
140 += 5. Add Integration =
141 +
142 +== 5.1. Creat new MQTT integration ==
143 +
24 24  In the left navigation, click **Integrations center**, and then click **Integrations**.
25 25  
26 26  On the **Integrations** page, click on the '**+**' button.
... ... @@ -80,7 +80,7 @@
80 80  
81 81  [[image:1743579352961-586.png||height="507" width="502"]]
82 82  
83 -[[image:1743584347047-327.png]]
203 +[[image:1743580606618-281.png||height="495" width="504"]]
84 84  
85 85  
86 86  Click on the **Add** button.
... ... @@ -89,16 +89,13 @@
89 89  
90 90  Since we haven't received data from a device yet, the integration **Status** is shown as **Pending,  Active  instead if it have.**
91 91  
92 -[[image:1743580606618-281.png||height="495" width="504"]]
93 93  
94 94  
95 -= 4. Configure Thingseye's Data Converters =
96 96  
97 -First, you need to download the [[**MQTT uplink/downlink JS** **code**>>url:https://www.dropbox.com/scl/fo/d5s1wf36f4syv30a8laup/AK8FjVpNXYXCWodRnnQ1Hig?rlkey=jrz1ip0f0xwwq5z2m2gu1tuij&e=1&st=kl4caub0&dl=0]].
98 98  
99 -In **Thingseye**, **Data Converters** are components used to transform incoming or outgoing data between different formats, typically to convert raw telemetry data from devices into a structured format that Thingseye can understand, or vice versa.
216 +== 5.2. Setup uplink and downlink converters ==
100 100  
101 -== 4.1 Uplink ==
218 +First, you need to download the [[**MQTT uplink/downlink JS** **code**>>url:https://www.dropbox.com/scl/fo/d5s1wf36f4syv30a8laup/AK8FjVpNXYXCWodRnnQ1Hig?rlkey=jrz1ip0f0xwwq5z2m2gu1tuij&e=1&st=kl4caub0&dl=0]].
102 102  
103 103  * **Uplink Converter**
104 104  
... ... @@ -114,12 +114,8 @@
114 114  [[image:1743581965585-763.png]]
115 115  
116 116  
117 -== 4.2 Downlink ==
234 +* **Downlink Converter**
118 118  
119 -* (((
120 -**Downlink Converter**
121 -)))
122 -
123 123  Go to the **Integrations center** -> **Data converters** page, and find that MQTT downlink converter that was newly created when the integration was created.
124 124  
125 125  
... ... @@ -127,60 +127,165 @@
127 127  
128 128  [[image:1743582084494-111.png]]
129 129  
243 +[[image:https://wiki.dragino.com/xwiki/bin/download/Main/General%20Configure%20to%20Connect%20to%20IoT%20server%20for%20-NB%20%26%20-NS%20NB-IoT%20models/WebHome/image-20241126190737-17.png?width=1114&height=527&rev=1.1||alt="image-20241126190737-17.png" height="527" width="1114"]]
130 130  
131 -== 4.3 Simulate with MQTT.fx ==
132 132  
133 -[[image:https://wiki.dragino.com/xwiki/bin/download/Main/General%20Configure%20to%20Connect%20to%20IoT%20server%20for%20-NB%20%26%20-NS%20NB-IoT%20models/WebHome/image-20241126191118-18.png?width=835&height=605&rev=1.1||alt="image-20241126191118-18.png"]]
134 134  
135 -[[image:https://wiki.dragino.com/xwiki/bin/download/Main/General%20Configure%20to%20Connect%20to%20IoT%20server%20for%20-NB%20%26%20-NS%20NB-IoT%20models/WebHome/image-20241126193252-25.png?width=803&height=663&rev=1.1||alt="image-20241126193252-25.png"]]
247 +== ==
136 136  
249 +== 6. Verifying the receipt of data from virtual devices ==
137 137  
138 -= 5. Configure Physical NB-IoT Sensor =
251 +== 6.1 How does it work? ==
139 139  
140 -First you need to configure the certificate to the -NB node. Follow the instructions in this **[[link>>url:https://wiki.dragino.com/xwiki/bin/view/Dragino%20NB%20device%20connection%20to%20AWS%20platform%20instructions/#H4.1.2Configurecertificate]]** to configure the certificate.
253 +We use the Mosquitto MQTT client to simulate MQTT messages, acting as a virtual device. First, install the Mosquitto client on your computer from [[this link>>url:https://mosquitto.org/download/]]. The Mosquitto client publishes messages to the MQTT broker (HiveMQ) on a specified MQTT topic.
141 141  
142 -Screenshot of successful certificate configuration:
255 +The Mosquitto client publishes messages (payloads) on the topic **/device/a**. Of course, you can use any topic for testing.
143 143  
144 -* Configuring the CA Certificate
257 +The MQTT payload format is as follows:
145 145  
146 -[[image:https://wiki.dragino.com/xwiki/bin/download/Main/General%20Configure%20to%20Connect%20to%20IoT%20server%20for%20-NB%20%26%20-NS%20NB-IoT%20models/WebHome/image-20241126192009-19.png?width=697&height=431&rev=1.1||alt="image-20241126192009-19.png" height="431" width="697"]]
259 +{{code language="none"}}
260 +{"IMEI": "350693903995577", "temperature":25, "humidity":80, "pressure":1005}
261 +{{/code}}
147 147  
148 -[[image:https://wiki.dragino.com/xwiki/bin/download/Main/General%20Configure%20to%20Connect%20to%20IoT%20server%20for%20-NB%20%26%20-NS%20NB-IoT%20models/WebHome/image-20241126192130-21.png?width=694&height=426&rev=1.1||alt="image-20241126192130-21.png" height="426" width="694"]]
263 +Once Thingseye receives this message, it forwards this payload to the matching device through the integration.
149 149  
150 -* Configure client certificate
265 +== 5.2 Sending messages ==
151 151  
152 -[[image:https://wiki.dragino.com/xwiki/bin/download/Main/General%20Configure%20to%20Connect%20to%20IoT%20server%20for%20-NB%20%26%20-NS%20NB-IoT%20models/WebHome/image-20241126192246-22.png?width=693&height=397&rev=1.1||alt="image-20241126192246-22.png" height="397" width="693"]][[image:https://wiki.dragino.com/xwiki/bin/download/Main/General%20Configure%20to%20Connect%20to%20IoT%20server%20for%20-NB%20%26%20-NS%20NB-IoT%20models/WebHome/image-20241126192315-23.png?width=645&height=402&rev=1.1||alt="image-20241126192315-23.png" height="402" width="645"]]
267 +On your computer's terminal, issue the following MQTT command which simulates the device '**Device A'**. The message payload contains the fields IMEI, temperature, humidity, and pressure, which hold the values 350693903995577, 30, 80, and 1005 respectively. This payload is also (technically) known as telemetry.
153 153  
154 -* Configure client private key
269 +{{code language="none"}}
270 +mosquitto_pub -d -q 1 -h 011731f7928xxxxx.s1.eu.hivemq.cloud -p 8883 -u "xxxxx" -P "xxxxx" -t "device/a" -m '{"IMEI":"350693903995577", "temperature":30, "humidity":80, "pressure":1005}'
271 +{{/code}}
155 155  
156 -[[image:https://wiki.dragino.com/xwiki/bin/download/Main/General%20Configure%20to%20Connect%20to%20IoT%20server%20for%20-NB%20%26%20-NS%20NB-IoT%20models/WebHome/image-20241126192415-24.png?width=737&height=435&rev=1.1||alt="image-20241126192415-24.png" height="435" width="737"]]
273 +If the integration was performed without errors, the status of the integration changes to 'Active' after the first telemetry transmission.
157 157  
158 -When the certificate is configured, burn the boot program, burn the working firmware, and then restart the device.
275 +[[image:https://wiki.dragino.com/xwiki/bin/download/Main/ThingsBoard/integration-active.png?rev=1.2||alt="integration-active.png"]]
159 159  
160 -Then configure the -NB node to connect to the ThingsEye platform:
277 +== 6.3 Viewing messages ==
161 161  
162 -**AT Commands**
279 +Go back to the **Integrations** page.
163 163  
164 -* **AT+PRO=3,5      **~/~/ Use MQTT Connection & Json Payload
165 -* **AT+SERVADDR=lns1.thingseye.io,8883**
166 -* **AT+SUBTOPIC=8899     **~/~/ Consistent with the Topic of MQTT integration created by ThingsEye
167 -* **AT+PUBTOPIC=8899     **~/~/ Consistent with the Topic of MQTT integration created by ThingsEye
168 -* **AT+CLIENT=NULL**
169 -* **AT+UNAME=NULL**
170 -* **AT+PWD=NULL**
171 -* **AT+TLSMOD=1,2**
281 +Click on the **MQTT integration NB/CB** in the **Integrations** page to see its details.
172 172  
173 -(% class="box warningmessage" %)
283 +Click on the **Edit** button (//**pen icon**//).
284 +
285 +Click on the **Disabled** button in the upper-right corner.
286 +
287 +Turn on the **All messages (15 min)** option. This will enable displaying all messages in the **Events** tab. This setting will expire in 15 minutes, and you will need to repeat the same steps if you want to view the messages in the Events tab later.
288 +
289 +Click on the **Apply** button.
290 +
291 +Then click on the **Apply changes** (//**tick icon**//) button.
292 +
293 +[[image:https://wiki.dragino.com/xwiki/bin/download/Main/ThingsBoard/debug-enabled.png?width=700&height=301&rev=1.1||alt="debug-enabled.png"]]
294 +
295 +Now go to the **Events** tab.
296 +
297 +Select the **Event type** as **Debug** from the dropdown list.
298 +
299 +Publish another message (of course, you can repeat the previous message by pressing the UP arrow on your keyboard and then press Enter key) to your MQTT broker from your terminal, for example:
300 +
301 +mosquitto_pub -d -q 1 -h 011731f7928xxxxx.s1.eu.hivemq.cloud -p 8883 -u "xxxxx" -P "xxxxx" -t "device/a" -m '{"IMEI":"350693903995577", "temperature":30, "humidity":80, "pressure":1005}'
302 +
303 +Now you can see that uplink message in the **Events** tab (Click the **refresh** button if you didn't see any messages in the Events tab). The status should be **OK **if there is no errors in your integration.
304 +
305 +[[image:https://wiki.dragino.com/xwiki/bin/download/Main/ThingsBoard/Screenshot%202025-03-26%20at%2019.49.31.png?rev=1.1||alt="Screenshot 2025-03-26 at 19.49.31.png"]]
306 +
307 +Then click on the **three dots (...)** in the **Message** column. You can see the uplink message's **payload** in the **Message** window.
308 +
309 +[[image:https://wiki.dragino.com/xwiki/bin/download/Main/ThingsBoard/Screenshot%202025-03-26%20at%2019.47.52.png?rev=1.1||alt="Screenshot 2025-03-26 at 19.47.52.png"]]
310 +
311 +Now, you have successfully tested your integration with a simulated uplink payload and verified that it is received by Thingseye, and the device is provisioned.
312 +
313 += 7. Creating a Dashboard =
314 +
315 +Thingseye **Dashboards** provide a powerful way to visualize and monitor real-time and historical data from connected devices. They allow users to create interactive, customizable panels displaying telemetry data, device status, and other key metrics. With a variety of widgets, including charts, maps, and tables, dashboards help users gain insights, track trends, and manage IoT deployments efficiently.
316 +
317 +This section guides you on how to create a dashboard to display temperature and humidity data from the device on a time-series chart. You may also use other widgets in Thingseye to display data according to your requirements.
318 +
319 +First simulate a few messages using MQTT. This time, we have added the 'humidity' field to the payload. Eg:
320 +
321 +{{code language="none"}}
322 +mosquitto_pub -d -q 1 -h 011731f7928xxxxx.s1.eu.hivemq.cloud -p 8883 -u "xxxxx" -P "xxxxx" -t "device/a" -m '{"IMEI":"350693903995577", "temperature":22, "humidity":80, "pressure":1005}'
323 +
324 +{{/code}}
325 +
326 +In **Thingseye**, from the left navigation menu, click **Dashboards**. Then, click the **+** button and select **Create new dashboard** from the dropdown menu.
327 +
328 +[[image:https://wiki.dragino.com/xwiki/bin/download/Main/ThingsBoard/dashboard-1.png?rev=1.1||alt="dashboard-1.png"]]
329 +
330 +In the **Title** text box, enter **NB/CB Test Dashboard** as the title of the dashboard.
331 +
332 +Click on the **Add** button.
333 +
334 +[[image:https://wiki.dragino.com/xwiki/bin/download/Main/ThingsBoard/dashboard-2.png?width=500&height=526&rev=1.1||alt="dashboard-2.png"]]
335 +
336 +Click on the **Add widget / Add new widget** button.
337 +
338 +[[image:https://wiki.dragino.com/xwiki/bin/download/Main/ThingsBoard/dashboard-3.png?rev=1.1||alt="dashboard-3.png"]]
339 +
340 +In the **Select widgets bundle** window, click **Charts**.
341 +
342 +[[image:https://wiki.dragino.com/xwiki/bin/download/Main/ThingsBoard/dashboard-4.png?width=700&height=537&rev=1.1||alt="dashboard-4.png"]]
343 +
344 +In the **Charts: select widget** window, click **Time series chart**.
345 +
346 +[[image:https://wiki.dragino.com/xwiki/bin/download/Main/ThingsBoard/dashboard-5.png?width=700&height=525&rev=1.1||alt="dashboard-5.png"]]
347 +
348 +Configure the **Time series chart** widget as follows:
349 +
350 +* **Datasource** - select **Device A** device you provisioned.
351 +* **Series**:
352 +** **temperature** - you can see this key by default.
353 +** **humidity** - Click **Add series** button. Then add the **humidity** for the key and then type **%** as its unit.
354 +* Click on the **Add** button.
355 +
356 +(% class="box infomessage" %)
174 174  (((
175 -Be careful, “ Topic” should be same of device & serve. If your device not belongs Dragino, address should be same of the broker which using.
358 +You can add only the relevant fields from the device's payload to display data on a widget. These fields are called 'keys'.
176 176  )))
177 177  
178 -Test Uplink by click the button for 1~~3 seconds, the MQTT integration in ThingsEye allows you to view the data upstream from the device:
361 +[[image:https://wiki.dragino.com/xwiki/bin/download/Main/ThingsBoard/Screenshot%202025-03-31%20at%2006.51.15.png?width=700&height=485&rev=1.1||alt="Screenshot 2025-03-31 at 06.51.15.png"]]
179 179  
363 +The time-series chart will appear in edit mode. Resize it by clicking and dragging the lower-right corner.
180 180  
365 +Click the **Save** button to add the widget to the dashboard.
181 181  
182 -Go to **"Device" ** -> ** "Search Device"**, enter the ** IMEI** of the device to find the device.
367 +[[image:https://wiki.dragino.com/xwiki/bin/download/Main/ThingsBoard/timeseries-3.png?width=700&height=347&rev=1.1||alt="timeseries-3.png"]]
183 183  
369 +Now send the following MQTT messages from the terminal to simulate the data.
184 184  
371 +{{code language="none"}}
372 +mosquitto_pub -d -q 1 -h 011731f7928xxxxx.s1.eu.hivemq.cloud -p 8883 -u "xxxxx" -P "xxxxx" -t "device/a" -m '{"IMEI":"350693903995577", "temperature":22, "humidity":70, "pressure":1005}'
185 185  
374 +mosquitto_pub -d -q 1 -h 011731f7928xxxxx.s1.eu.hivemq.cloud -p 8883 -u "xxxxx" -P "xxxxx" -t "device/a" -m '{"IMEI":"350693903995577", "temperature":27, "humidity":72, "pressure":1005}'
375 +
376 +mosquitto_pub -d -q 1 -h 011731f7928xxxxx.s1.eu.hivemq.cloud -p 8883 -u "xxxxx" -P "xxxxx" -t "device/a" -m '{"IMEI":"350693903995577", "temperature":19, "humidity":80, "pressure":1005}'
377 +{{/code}}
378 +
379 +The chart will update with the values in realtime, as shown in the below image.
380 +
381 +[[image:https://wiki.dragino.com/xwiki/bin/download/Main/ThingsBoard/timeseries-4.png?width=700&height=316&rev=1.1||alt="timeseries-4.png"]]
382 +
383 += 8. Configure Physical NB-IoT Sensor =
384 +
385 +Now, let's experiment with sending data to Thingseye using a real NB-IoT device. For example, we will use the **TS01-NB**.
386 +
387 +First, configure the NB-IoT device with the necessary MQTT settings using AT commands. Below is a list of AT commands you can use.
388 +
389 +**AT Commands**
390 +
391 +* **AT+PRO=3,3    **~/~/ Use MQTT to connect to Thingseye. Payload Type set to 3.
392 +* **AT+SUBTOPIC=<MQTT subscribe topic> Eg: TS01-NB**
393 +* **AT+PUBTOPIC=<MQTT publish topic> Eg: TS01-NB**
394 +* **AT+CLIENT=null**
395 +* **AT+UNAME=<MQTT Username>**
396 +* **AT+PWD=<MQTT Password>**
397 +* **AT+SERVADDR=<Broker address, Port>**
398 +
399 +Test your uplink by pressing the ACT button for 1 second.
186 186  
401 +
402 +The following image shows the uplink payload of a real Dragino device. The publish topic is '**TS01-NB' that contains fields in the payload, IMEI, IMSI, Model, temperature, etc**. Note that we have created a device named **TS01-NB** in the **Devices** section in advance.
403 +
404 +[[image:https://wiki.dragino.com/xwiki/bin/download/Main/ThingsBoard/image-4.png?rev=1.2||alt="image-4.png"]]
1743584347047-327.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Alec
Size
... ... @@ -1,1 +1,0 @@
1 -126.3 KB
Content