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

From version 3.1
edited by Alec Chen
on 2025/04/02 16:29
Change comment: There is no comment for this version
To version 7.1
edited by Alec Chen
on 2025/04/02 17:18
Change comment: There is no comment for this version

Summary

Details

Page properties
Title
... ... @@ -1,1 +1,1 @@
1 -How to communice Dragino -NB and -CB series devices data by MQTT with Thingseye
1 +How to Uplink -NB and -CB series devices data by MQTT with Thingseye
Content
... ... @@ -1,5 +1,7 @@
1 1  **Table of Contents:**
2 2  
3 +{{toc/}}
4 +
3 3  = 1. Introduction =
4 4  
5 5  This document guides you on integrating Dragino **-NB** and **-CB** series devices data with Thingseye.
... ... @@ -15,132 +15,10 @@
15 15  [[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"]]
16 16  
17 17  
18 -= 3.General MQTT Connection =
20 += (% style="color:#333333; font-family:inherit; font-size:max(23px, min(29px, 12.3333px + 1.38889vw))" %)3. Configure Thingseye's Integration(%%) =
19 19  
20 -The NB-IoT Sensor can send packet to server use MQTT protocol.
22 +== 3.1 Creat new MQTT integration ==
21 21  
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 -
144 144  In the left navigation, click **Integrations center**, and then click **Integrations**.
145 145  
146 146  On the **Integrations** page, click on the '**+**' button.
... ... @@ -200,7 +200,7 @@
200 200  
201 201  [[image:1743579352961-586.png||height="507" width="502"]]
202 202  
203 -[[image:1743580606618-281.png||height="495" width="504"]]
83 +[[image:1743584347047-327.png]]
204 204  
205 205  
206 206  Click on the **Add** button.
... ... @@ -209,13 +209,16 @@
209 209  
210 210  Since we haven't received data from a device yet, the integration **Status** is shown as **Pending,  Active  instead if it have.**
211 211  
92 +[[image:1743580606618-281.png||height="495" width="504"]]
212 212  
213 213  
95 += 4. Configure Thingseye's Data Converters =
214 214  
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]].
215 215  
216 -== 5.2. Setup uplink and downlink converters ==
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.
217 217  
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]].
101 +== 4.1 Uplink ==
219 219  
220 220  * **Uplink Converter**
221 221  
... ... @@ -231,8 +231,12 @@
231 231  [[image:1743581965585-763.png]]
232 232  
233 233  
234 -* **Downlink Converter**
117 +== 4.2 Downlink ==
235 235  
119 +* (((
120 +**Downlink Converter**
121 +)))
122 +
236 236  Go to the **Integrations center** -> **Data converters** page, and find that MQTT downlink converter that was newly created when the integration was created.
237 237  
238 238  
... ... @@ -241,27 +241,58 @@
241 241  [[image:1743582084494-111.png]]
242 242  
243 243  
131 +== 4.3 Simulate with MQTT.fx ==
244 244  
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"]]
245 245  
246 -= 8. Configure Physical NB-IoT Sensor =
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 247  
248 -Now, let's experiment with sending data to Thingseye using a real NB-IoT device. For example, we will use the **TS01-NB**.
249 249  
250 -First, configure the NB-IoT device with the necessary MQTT settings using AT commands. Below is a list of AT commands you can use.
138 += 5. Configure Physical NB-IoT Sensor =
251 251  
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.
141 +
142 +Screenshot of successful certificate configuration:
143 +
144 +* Configuring the CA Certificate
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"]]
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"]]
149 +
150 +* Configure client certificate
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"]]
153 +
154 +* Configure client private key
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"]]
157 +
158 +When the certificate is configured, burn the boot program, burn the working firmware, and then restart the device.
159 +
160 +Then configure the -NB node to connect to the ThingsEye platform:
161 +
252 252  **AT Commands**
253 253  
254 -* **AT+PRO=3,3    **~/~/ Use MQTT to connect to Thingseye. Payload Type set to 3.
255 -* **AT+SUBTOPIC=<MQTT subscribe topic> Eg: TS01-NB**
256 -* **AT+PUBTOPIC=<MQTT publish topic> Eg: TS01-NB**
257 -* **AT+CLIENT=null**
258 -* **AT+UNAME=<MQTT Username>**
259 -* **AT+PWD=<MQTT Password>**
260 -* **AT+SERVADDR=<Broker address, Port>**
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**
261 261  
262 -Test your uplink by pressing the ACT button for 1 second.
263 -
173 +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:
264 264  
265 -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.
175 +[[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-20241126193458-26.png?width=1012&height=375&rev=1.1||alt="image-20241126193458-26.png" height="375" width="1012"]]
266 266  
267 -[[image:https://wiki.dragino.com/xwiki/bin/download/Main/ThingsBoard/image-4.png?rev=1.2||alt="image-4.png"]]
177 +[[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-20241126193609-27.png?width=1014&height=424&rev=1.1||alt="image-20241126193609-27.png" height="424" width="1014"]]
178 +
179 +Go to **"Device" ** -> ** "Search Device"**, enter the ** IMEI** of the device to find the device.
180 +
181 +[[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-20241126194018-28.png?width=1076&height=318&rev=1.1||alt="image-20241126194018-28.png" height="318" width="1076"]]
182 +
183 +You can view the data that has just been uplink on the device:
184 +
185 +[[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-20241126194123-29.png?width=1073&height=486&rev=1.1||alt="image-20241126194123-29.png" height="486" width="1073"]]
1743584347047-327.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Alec
Size
... ... @@ -1,0 +1,1 @@
1 +126.3 KB
Content