Wiki source code of Connect Devices to ThingsEye

Version 26.1 by Alec Chen on 2025/11/19 15:54

Show last authors
1 (% _mstvisible="1" %)
2
3
4 (% _mstvisible="1" %)
5 (% _msthash="777" _msttexthash="303537" _mstvisible="2" %)**Table of Contents:**
6
7 {{toc/}}
8
9
10 (% _mstvisible="1" %)
11 = (% _msthash="757" _msttexthash="149552" _mstvisible="2" %)1. Overview(%%) =
12
13 (% _msthash="756" _msttexthash="7978490" _mstvisible="1" %)
14 This instructions will show you how to connect a device that has been registered to the server to the Thingseye platform.
15
16
17 = (% _msthash="755" _msttexthash="40707030" _mstvisible="2" %)2. UDP Protocol – Direct Connection(%%) =
18
19 (% _msthash="755" _msttexthash="40707030" _mstvisible="2" %)2.1 UDP Interface
20 **Server Address: server1.thingseye.io
21 Port: 11560**
22 Data sent to the above UDP interface will not directly enter the client's database.
23
24 (% _msthash="755" _msttexthash="40707030" _mstvisible="2" %)For detailed information on how to forward data to clients, please contact the ThingsEye team.
25
26 (% _msthash="755" _msttexthash="40707030" _mstvisible="2" %)Note: Currently, UDP connections require port forwarding. Please contact the ThingsEye team before connecting and provide them with your device's IMEI.
27
28
29 (% _mstvisible="1" %)
30 ----
31
32 == (% _msthash="748" _msttexthash="55449407" _mstvisible="2" %)2.2 Testing with Dragino NB Device(%%) ==
33
34 === (% _msthash="748" _msttexthash="55449407" _mstvisible="2" %)2.2.1 Configuring the NB-IoT End Node(%%) ===
35
36 (% _msthash="748" _msttexthash="55449407" _mstvisible="2" %)The device here is an S31-NB, and it has been configured as follows:
37
38 (% _msthash="748" _msttexthash="55449407" _mstvisible="2" %)**Set to use the ThingsEye UDP server: AT+SERVADDR=server1.thingseye.io,11560**
39
40 (% _msthash="748" _msttexthash="55449407" _mstvisible="2" %)**Use UDP uplink and JSON protocol: AT+PRO=2,5**
41
42 (% _msthash="748" _msttexthash="55449407" _mstvisible="2" %)Equipped with an NB-IoT card to access the NB-IoT network.
43
44 (% _msthash="748" _msttexthash="55449407" _mstvisible="2" %)The S31-NB's cellular module IMEI is: 863663062789483
45
46 (% class="wikigeneratedid" _mstvisible="1" id="H2.2.268C067E54E0A884C6570636E" %)
47 (% _msthash="741" _msttexthash="30173117" _mstvisible="2" %)2.2.2 Check Uplink Data
48 Enable Debug Module
49
50 (% _mstvisible="1" %)
51 (% _mstvisible="3" %)[[image:1758762334133-608.png||_mstalt="294801" _msthash="584" _mstvisible="5" height="494" width="1003"]]
52
53 (% _mstvisible="1" %)
54 ----
55
56 (% _msthash="739" _msttexthash="156775723" _mstvisible="1" %)
57 After reactivating the S31-NB, we can see it in the debug window:
58
59 (% _mstvisible="1" %)
60 (% _mstvisible="3" %)[[image:1758762371290-726.png||_mstalt="296088" _msthash="586" _mstvisible="5" height="528" width="1005"]]
61
62 (% _mstvisible="1" %)
63 (% _mstvisible="3" %)[[image:1728378218744-800.png||_mstalt="295269" _msthash="588" _mstvisible="5" height="431" width="1003"]]
64
65 ----
66
67 === 2.2.4 Automatic Device Creation
68 The default tenant UDP server is already configured to decode Dragino-NB/-CB NB-IoT nodes. Therefore, each end node sends data to the server. The tenant will automatically create devices on the server. ===
69
70 (% _mstvisible="1" %)
71 (% _mstvisible="3" %)[[image:1728378968101-683.png||_mstalt="297154" _msthash="590" _mstvisible="5" height="210" width="1005"]]
72
73 (% _mstvisible="1" %)
74 (% _mstvisible="3" %)[[image:1728379050044-764.png||_mstalt="295282" _msthash="592" _mstvisible="5" height="326" width="1009"]]
75
76
77 (% _mstvisible="1" %)
78 ----
79
80 (% _mstvisible="1" %)
81 = (% _msthash="736" _msttexthash="622947" _mstvisible="2" %)3.  Connect to The Things Stack(%%) =
82
83 (% _mstvisible="1" %)
84 == (% _msthash="735" _msttexthash="410280" _mstvisible="2" %)3.1 Network Structure(%%) ==
85
86 (% _msthash="734" _msttexthash="14835652" _mstvisible="1" %)
87 The network diagram below illustrates the connection between the devices and The Things Stack, as well as how the data can be integrated with the ThingsEye IoT platform.
88
89 (% _mstvisible="1" %)
90 (% _mstvisible="3" %)[[image:1732679444539-853.jpg||_mstalt="296933" _msthash="594" _mstvisible="5" height="388" width="1452"]]
91
92 (% _mstvisible="1" %)
93 == (% _msthash="733" _msttexthash="1191008" _mstvisible="2" %)3.2 Creat Integration for The Things Stack.(%%) ==
94
95 (% class="lead" _msthash="732" _msttexthash="255775" _mstvisible="1" %)
96 Add Integration
97
98 (% _mstvisible="1" %)
99 (% _mstvisible="3" %)[[image:1728535775119-971.png||_mstalt="297661" _msthash="596" _mstvisible="5" height="423" width="1007"]]
100
101
102 (% class="lead" _msthash="731" _msttexthash="448994" _mstvisible="1" %)
103 Choose Connection Type
104
105 (% _mstvisible="1" %)
106 (% _mstvisible="3" %)[[image:1728535857345-950.png||_mstalt="297154" _msthash="598" _mstvisible="5" height="257" width="403"]]
107
108
109 (% class="lead" _msthash="730" _msttexthash="762996" _mstvisible="1" %)
110 Input Uplink Data Converter Code
111
112 (% _mstvisible="1" %)
113 (% _mstvisible="3" %)[[image:1728535941851-388.png||_mstalt="297856" _msthash="600" _mstvisible="5" height="466" width="398"]]
114
115 (% _msthash="729" _msttexthash="16454490" _mstvisible="1" %)
116 Demo JavaScript Code: [[https:~~/~~/raw.githubusercontent.com/ThingsEye-io/te-platform/refs/heads/main/Data%20Converters/The_Things_Network_MQTT_Uplink_Converter.js >>https://raw.githubusercontent.com/ThingsEye-io/te-platform/refs/heads/main/Data%20Converters/The_Things_Network_MQTT_Uplink_Converter.js]]
117
118
119 (% class="lead" _msthash="728" _msttexthash="532480" _mstvisible="1" %)
120 Input Downlink Converter
121
122 (% _mstvisible="1" %)
123 (% _mstvisible="3" %)[[image:1728536142721-488.png||_mstalt="296127" _msthash="602" _mstvisible="5" height="470" width="407"]]
124
125 (% _msthash="727" _msttexthash="19064695" _mstvisible="1" %)
126 Example Javascript Code as below: [[https:~~/~~/raw.githubusercontent.com/ThingsEye-io/te-platform/refs/heads/main/Data%20Converters/The_Things_Network_MQTT_Downlink_Converter.js>>https://raw.githubusercontent.com/ThingsEye-io/te-platform/refs/heads/main/Data%20Converters/The_Things_Network_MQTT_Downlink_Converter.js]]
127
128
129 (% class="lead" _msthash="726" _msttexthash="1724853" _mstvisible="1" %)
130 Set up Connection to The Things Network application
131
132 (% _mstvisible="1" %)
133 (% _mstvisible="3" %)[[image:1728536305503-380.png||_mstalt="293254" _msthash="604" _mstvisible="5" height="431" width="1019"]]
134
135
136
137 (% class="lead" _msthash="725" _msttexthash="851097" _mstvisible="1" %)
138 Test Connection & Add iIntegration
139
140 (% _mstvisible="1" %)
141 (% _mstvisible="3" %)[[image:1728536374214-962.png||_mstalt="295893" _msthash="606" _mstvisible="5" height="380" width="1024"]]
142
143 (% _msthash="724" _msttexthash="1177579" _mstvisible="1" %)
144 After add , we can see the integration here:
145
146 (% _mstvisible="1" %)
147 (% _mstvisible="3" %)[[image:1728536420275-153.png||_mstalt="293748" _msthash="608" _mstvisible="5" height="152" width="1026"]]
148
149
150 (% _mstvisible="1" %)
151 == (% _msthash="723" _msttexthash="213447" _mstvisible="2" %)3.3 Test Uplink(%%) ==
152
153 (% _msthash="722" _msttexthash="7855835" _mstvisible="1" %)
154 We can use Simulate Uplink to simulate an uplink in the things stack. Then we should be able to see the message in ThingsEye
155
156 (% _mstvisible="1" %)
157 (% _mstvisible="3" %)[[image:1728536524638-768.png||_mstalt="298870" _msthash="610" _mstvisible="5" height="473" width="1028"]]
158
159
160 (% _mstvisible="1" %)
161 (% _mstvisible="3" %)[[image:1728536541040-814.png||_mstalt="293215" _msthash="612" _mstvisible="5" height="424" width="1026"]]
162
163
164 (% _mstvisible="1" %)
165 ----
166
167 (% _mstvisible="1" %)
168 = (% _msthash="721" _msttexthash="1472211" _mstvisible="2" %)4.Connect chirpstack to Thingseye by way of MQTT(%%) =
169
170 (% _mstvisible="1" %)
171 * (% _msthash="720" _msttexthash="4693741" _mstvisible="3" %)**How to connect chirpstack to Thingseye by way of MQTT? The following tutorial will show you**
172
173 (% _mstvisible="1" %)
174 == (% _msthash="719" _msttexthash="410371" _mstvisible="2" %)4.1 Network Structure(%%) ==
175
176 (% _msthash="718" _msttexthash="14117480" _mstvisible="1" %)
177 The network diagram below illustrates the connection between the devices andchirpstack, as well as how the data can be integrated with the ThingsEye IoT platform.
178
179 (% _mstvisible="1" %)
180 (% _mstvisible="3" %)[[image:1732679647697-982.jpg||_mstalt="299884" _msthash="614" _mstvisible="5" height="399" width="1492"]]
181
182 (% _mstvisible="1" %)
183 == (% _msthash="717" _msttexthash="897286" _mstvisible="2" %)4.2 Thingseye adds MQTT integration(%%) ==
184
185 (% _msthash="716" _msttexthash="15186782" _mstvisible="1" %)
186 Go to the Integrations page in the Integrations center section. Click the plus button to start adding a new integration. Select the type "MQTT" integration and click "Next";
187
188 (% _mstvisible="1" %)
189 (% _mstvisible="3" %)[[image:1758762634175-353.png||_mstalt="295893" _msthash="616" _mstvisible="5" height="783" width="1020"]]
190
191 (% _mstvisible="1" %)
192 == (% _msthash="715" _msttexthash="1329445" _mstvisible="2" %)4.3 Add an uplink and downlink data converter(%%) ==
193
194 (% _msthash="714" _msttexthash="4516408" _mstvisible="1" %)
195 In the function decoder field, specify the uplink script to parse and transform the data.
196
197 (% _mstvisible="1" %)
198 (% _mstvisible="3" %)[[image:1758763061703-634.png||_mstalt="294671" _msthash="618" _mstvisible="5" height="783" width="1020"]]
199
200 (% _mstvisible="1" %)
201 * (% _msthash="713" _msttexthash="24445408" _mstvisible="3" %)**Uplink——JavaScript:**
202
203 (% _msthash="712" _msttexthash="792233" _mstvisible="1" %)
204 var data = decodeToJson(payload);
205
206 (% _msthash="711" _msttexthash="1379794" _mstvisible="1" %)
207 var deviceName = data.deviceInfo.deviceName;
208
209 (% _msthash="710" _msttexthash="1079247" _mstvisible="1" %)
210 var deviceType = data.applicationName;
211
212 (% _msthash="709" _msttexthash="909376" _mstvisible="1" %)
213 var devEui = data.deviceInfo.devEui
214
215 (% _msthash="708" _msttexthash="861510" _mstvisible="1" %)
216 var label = data.deviceInfo.devEui
217
218 (% _msthash="707" _msttexthash="195442" _mstvisible="1" %)
219 var model = {};
220
221 (% _msthash="706" _msttexthash="435448" _mstvisible="1" %)
222 var data2 = data.object;
223
224 (% _msthash="705" _msttexthash="326274" _mstvisible="1" %)
225 var flg = data.fPort
226
227 (% _msthash="704" _msttexthash="380965" _mstvisible="1" %)
228 for (var key in data2) {
229
230 (% _msthash="703" _msttexthash="43058977" _mstvisible="1" %)
231 ~/~/ 将属性名存入新对象中
232
233 (% _msthash="702" _msttexthash="475553" _mstvisible="1" %)
234 model[key] = data2[key];
235
236 (% _mstvisible="1" %)
237 }
238
239 (% _msthash="701" _msttexthash="757653" _mstvisible="1" %)
240 ~/~/var obj = {"devid":deviceName}
241
242 (% _msthash="700" _msttexthash="183287" _mstvisible="1" %)
243 var result = {
244
245 (% _msthash="699" _msttexthash="473265" _mstvisible="1" %)
246 deviceName: deviceName,
247
248 (% _msthash="698" _msttexthash="489918" _mstvisible="1" %)
249 deviceType: deviceType,
250
251 (% _msthash="697" _msttexthash="297271" _mstvisible="1" %)
252 telemetry: model,
253
254 (% _msthash="696" _msttexthash="446498" _mstvisible="1" %)
255 groupName: "Case Study",
256
257 (% _msthash="695" _msttexthash="217633" _mstvisible="1" %)
258 ~/~/label:label,
259
260 (% _msthash="694" _msttexthash="685984" _mstvisible="1" %)
261 attributes:{"devEui":devEui,
262
263 (% _msthash="693" _msttexthash="386308" _mstvisible="1" %)
264 ~/~/"timevalue":"test",
265
266 (% _msthash="692" _msttexthash="551772" _mstvisible="1" %)
267 "inactivityTimeout":1260000
268
269 (% _msthash="691" _msttexthash="894530" _mstvisible="1" %)
270 ~/~/ "High_humidity_alarm":"not set",
271
272 (% _msthash="690" _msttexthash="1052753" _mstvisible="1" %)
273 ~/~/ "High_temperature_alarm":"not set",
274
275 (% _msthash="689" _msttexthash="848783" _mstvisible="1" %)
276 ~/~/ "Low_humidity_alarm":"not set",
277
278 (% _msthash="688" _msttexthash="1002833" _mstvisible="1" %)
279 ~/~/ "Low_temperature_alarm":"not set",
280
281 (% _msthash="687" _msttexthash="773682" _mstvisible="1" %)
282 ~/~/ "Low_voltage_alarm":"not set"
283
284 (% _msthash="686" _msttexthash="2381015" _mstvisible="1" %)
285 ~/~/"customerName": "Civionic Engineering & Consulting (2014) Inc."
286
287 (% _mstvisible="1" %)
288 }
289
290 (% _mstvisible="1" %)
291 };
292
293 (% _msthash="685" _msttexthash="937586" _mstvisible="1" %)
294 function decodeToString(payload) {
295
296 (% _msthash="684" _msttexthash="1818154" _mstvisible="1" %)
297 return String.fromCharCode.apply(String, payload);
298
299 (% _mstvisible="1" %)
300 }
301
302 (% _msthash="683" _msttexthash="834496" _mstvisible="1" %)
303 function decodeToJson(payload) {
304
305 (% _msthash="682" _msttexthash="850616" _mstvisible="1" %)
306 var str = decodeToString(payload);
307
308 (% _msthash="681" _msttexthash="512044" _mstvisible="1" %)
309 var data = JSON.parse(str);
310
311 (% _msthash="680" _msttexthash="173511" _mstvisible="1" %)
312 return data;
313
314 (% _mstvisible="1" %)
315 }
316
317 (% _msthash="679" _msttexthash="233116" _mstvisible="1" %)
318 return result;
319
320 (% _mstvisible="1" %)
321 ----
322
323 (% _msthash="678" _msttexthash="4743882" _mstvisible="1" %)
324 In the function decoder field, specify the downlink script to parse and transform the data.
325
326 (% _mstvisible="1" %)
327 (% _mstvisible="3" %)[[image:1758763019466-819.png||_mstalt="298311" _msthash="620" _mstvisible="5" height="787" width="1022"]]
328
329 (% _mstvisible="1" %)
330 * (% _msthash="677" _msttexthash="26632970" _mstvisible="3" %)**Dowblink——JavaScript:**
331
332 (% _msthash="676" _msttexthash="2052284" _mstvisible="1" %)
333 ~/~/ Encode downlink data from incoming Rule Engine message
334
335 (% _msthash="675" _msttexthash="1638546" _mstvisible="1" %)
336 ~/~/ msg - JSON message payload downlink message json
337
338 (% _msthash="674" _msttexthash="3854773" _mstvisible="1" %)
339 ~/~/ msgType - type of message, for ex. 'ATTRIBUTES_UPDATED', 'POST_TELEMETRY_REQUEST', etc.
340
341 (% _msthash="673" _msttexthash="3368742" _mstvisible="1" %)
342 ~/~/ metadata - list of key-value pairs with additional data about the message
343
344 (% _msthash="672" _msttexthash="8087157" _mstvisible="1" %)
345 ~/~/ integrationMetadata - list of key-value pairs with additional data defined in Integration executing this converter
346
347 (% _msthash="671" _msttexthash="199069" _mstvisible="1" %)
348 ~/~/ /~*~* Encoder ~*~*/
349
350 (% _msthash="670" _msttexthash="455715" _mstvisible="1" %)
351 ~/~/var data = {"value":99};
352
353 (% _msthash="669" _msttexthash="1757431" _mstvisible="1" %)
354 ~/~/ ~/~/ Process data from incoming message and metadata
355
356 (% _msthash="668" _msttexthash="1852279" _mstvisible="1" %)
357 ~/~/ data.tempFreq = msg.temperatureUploadFrequency;
358
359 (% _msthash="667" _msttexthash="1572038" _mstvisible="1" %)
360 ~/~/ data.humFreq = msg.humidityUploadFrequency;
361
362 (% _msthash="666" _msttexthash="2049957" _mstvisible="1" %)
363 ~/~/ data.devSerialNumber = metadata['ss_serialNumber'];
364
365 (% _msthash="665" _msttexthash="1576731" _mstvisible="1" %)
366 ~/~/ ~/~/ Result object with encoded downlink payload
367
368 (% _msthash="664" _msttexthash="183287" _mstvisible="1" %)
369 var result = {
370
371 (% _msthash="663" _msttexthash="2331082" _mstvisible="1" %)
372 ~/~/ downlink data content type: JSON, TEXT or BINARY (base64 format)
373
374 (% _msthash="662" _msttexthash="322049" _mstvisible="1" %)
375 contentType: "TEXT",
376
377 (% _msthash="661" _msttexthash="249210" _mstvisible="1" %)
378 ~/~/ downlink data
379
380 (% _msthash="660" _msttexthash="1524952" _mstvisible="1" %)
381 data: msg.shared_value ,~/~/JSON.stringify(data),
382
383 (% _msthash="659" _msttexthash="2147704" _mstvisible="1" %)
384 ~/~/ Optional metadata object presented in key/value format
385
386 (% _msthash="658" _msttexthash="150189" _mstvisible="1" %)
387 metadata: {
388
389 (% _msthash="657" _msttexthash="1241370" _mstvisible="1" %)
390 topic: '/test/down/'+metadata.deviceName
391
392 (% _mstvisible="1" %)
393 }
394
395 (% _mstvisible="1" %)
396 };
397
398 (% _msthash="656" _msttexthash="233116" _mstvisible="1" %)
399 return result;
400
401 (% _mstvisible="1" %)
402 ----
403
404 (% _mstvisible="1" %)
405 == (% _msthash="655" _msttexthash="640094" _mstvisible="2" %)4.4 Configure the connection(%%) ==
406
407 (% _msthash="654" _msttexthash="1780675" _mstvisible="1" %)
408 Generate MQTT certificate integrated on chirpstack
409
410 (% _msthash="653" _msttexthash="3723447" _mstvisible="1" %)
411 Chirpstack generates CA certificate, TLS certificate, and TLS key respectively
412
413 (% _msthash="652" _msttexthash="5123092" _mstvisible="1" %)
414 They correspond to the CA certificate file, Certificate file, and Private key file on thingseye
415
416 (% _mstvisible="1" %)
417 (% _mstvisible="3" %)[[image:图片4.png||_mstalt="5131737" _msthash="622" _mstvisible="5" height="504" width="1016"]]
418
419 (% _mstvisible="1" %)
420 (% _mstvisible="3" %)[[image:图片5.png||_mstalt="5131854" _msthash="624" _mstvisible="5" height="505" width="1017"]]
421
422 (% _mstvisible="1" %)
423 * Copy the contents of the certificates and paste them into the linked file below, a total of three certificates are required
424
425 (% _mstvisible="1" %)
426 (% _msthash="650" _msttexthash="44967858" _mstvisible="2" %)**Integrated Certificate File demo Download Address:**
427
428 (% _mstvisible="1" %)
429 [[https:~~/~~/github.com/ThingsEye-io/te-platform/tree/main/chirpstack>>https://github.com/ThingsEye-io/te-platform/tree/main/chirpstack||_msthash="649" _msttexthash="3132909" _mstvisible="2"]]
430
431 (% _msthash="648" _msttexthash="4037631" _mstvisible="1" %)
432 Enter the server address Host: lns1.thingseye.io on the Connection configuration
433
434 (% _msthash="647" _msttexthash="93873" _mstvisible="1" %)
435 Port: 8883
436
437 (% _msthash="646" _msttexthash="380666" _mstvisible="1" %)
438 Credentials type: PEM
439
440 (% _msthash="645" _msttexthash="880399" _mstvisible="1" %)
441 Upload the certificate and key file
442
443 (% _mstvisible="1" %)
444 (% _mstvisible="3" %)[[image:图片6.png||_mstalt="5131971" _msthash="626" _mstvisible="5" height="509" width="1026"]]
445
446 (% _mstvisible="1" %)
447 (% _mstvisible="3" %)[[image:图片7.png||_mstalt="5132088" _msthash="628" _mstvisible="5" height="509" width="1025"]]
448
449 (% _mstvisible="1" %)
450 ----
451
452 (% _msthash="644" _msttexthash="472992" _mstvisible="1" %)
453 The default for Topic is:
454
455 (% _msthash="643" _msttexthash="2223559" _mstvisible="1" %)
456 application/**chirpstack application id**/device/+/event/up
457
458 (% _mstvisible="1" %)
459 (% _mstvisible="3" %)[[image:图片8.png||_mstalt="5132205" _msthash="630" _mstvisible="5" height="508" width="1024"]]
460
461
462 (% class="wikigeneratedid" _mstvisible="1" %)
463 (% _mstvisible="3" %)[[image:屏幕截图 2024-11-25 095805.png||_mstalt="10831028" _msthash="632" _mstvisible="5" height="301" width="1024"]]
464
465 (% _mstvisible="1" %)
466 ----
467
468 (% _mstvisible="1" %)
469 == (% _msthash="642" _msttexthash="471978" _mstvisible="2" %)4.5 Check the connection(%%) ==
470
471 (% _mstvisible="1" %)
472 (% _mstvisible="3" %)[[image:图片9.png||_mstalt="5132322" _msthash="634" _mstvisible="5" height="509" width="1025"]]
473
474 (% _mstvisible="1" %)
475 (% _mstvisible="3" %)[[image:图片10.png||_mstalt="5142449" _msthash="636" _mstvisible="5" height="509" width="1026"]]
476
477
478 (% _mstvisible="1" %)
479 ----
480
481 (% _mstvisible="1" %)
482 = (% _msthash="641" _msttexthash="418145" _mstvisible="2" %)5. Check Data Uplink Log(%%) =
483
484 (% _msthash="640" _msttexthash="1422681" _mstvisible="1" %)
485 User can check the devices log in Intergration.
486
487 (% _mstvisible="1" %)
488 (% _mstvisible="3" %)[[image:1729562069134-315.png||_mstalt="294190" _msthash="638" _mstvisible="5" height="587" width="723"]]