Changes for page Connect Devices to ThingsEye
Last modified by Hera Guo on 2025/02/18 09:29
Summary
-
Page properties (2 modified, 0 added, 0 removed)
-
Attachments (0 modified, 16 added, 0 removed)
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. EdwinChen1 +XWiki.hera - Content
-
... ... @@ -7,14 +7,18 @@ 7 7 8 8 = 1. Overview = 9 9 10 +The instructions in this chapter will show you how to connect a device that has been registered to the server to the Thingseye platform. 10 10 12 +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. 11 11 14 +[[image:1732679080974-799.jpg||height="444" width="1660"]] 15 + 12 12 = 2. UDP Procotol ~-~- Directly Connection = 13 13 14 14 == 2.1 UDP Interface == 15 15 16 16 * Server Address: server1.thingseye.io 17 -* Port: 1156 021 +* Port: 11562 18 18 19 19 The data sent to above UDP interface will not go directly to client's database. 20 20 ... ... @@ -25,7 +25,7 @@ 25 25 26 26 Download the UDP Test Tool from: [[https:~~/~~/sourceforge.net/projects/sockettest/ >>https://sourceforge.net/projects/sockettest/]]. Run this tool, and input the server address and UDP port as below and click send. 27 27 28 -[[image:1728 362612869-443.png||height="454" width="540"]]32 +[[image:1728566363151-470.png]] 29 29 30 30 In server side, Tenant Administrator can check this in Tenant UDP Server location. 31 31 ... ... @@ -44,7 +44,7 @@ 44 44 45 45 Device here is **[[S31-NB>>https://www.dragino.com/products/temperature-humidity-sensor/item/288-s31-nb-s31b-nb.html]]** : and have been configure below 46 46 47 -* Set to use ThingsEye UDP server: **AT+SERVADDR=server1.thingseye.io,1156 0**51 +* Set to use ThingsEye UDP server: **AT+SERVADDR=server1.thingseye.io,11562** 48 48 * Use UDP Uplink & Json protocol:** AT+PRO=2,5** 49 49 * Equip with a NB-IoT SIM Card to access to NB-IoT Network. 50 50 ... ... @@ -69,15 +69,13 @@ 69 69 70 70 **So we have this device in the Tenant Device List. The next step will be how to use these value to make a nice dashboard for user's application.** 71 71 76 += 3. Connect to The Things Stack = 72 72 78 +== 3.1 Network Structure == 73 73 74 -= 2. Connect to The Things Stack = 75 75 76 -== 2.1NetworkStructure ==81 +== 3.2 Creat Integration for The Things Stack. == 77 77 78 - 79 -== 2.2 Creat Integration for The Things Stack. == 80 - 81 81 (% class="lead" %) 82 82 Add Integration 83 83 ... ... @@ -95,107 +95,17 @@ 95 95 96 96 [[image:1728535941851-388.png||height="466" width="398"]] 97 97 98 -Demo Code as below :100 +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]] 99 99 100 ->var data = decodeToJson(payload); 101 ->var deviceName = data.end_device_ids.device_id; 102 ->var deviceType = data.end_device_ids.application_ids.application_id; 103 ->var model = {}; 104 ->var data2 = data.uplink_message.decoded_payload; 105 ->var flg = data.uplink_message.f_port 106 ->for (var key in data2) { 107 -> model[key] = data2[key]; 108 ->} 109 ->var obj = {"devid":deviceName} 110 ->var result = { 111 -> deviceName: deviceName, 112 -> deviceType: deviceType, 113 -> telemetry: model, 114 -> groupName: "Case Study", 115 -> attributes:{"devid":deviceName, 116 -> "timevalue":"test", 117 -> "inactivityTimeout":1260000 118 -> } 119 ->}; 120 ->function decodeToString(payload) { 121 -> return String.fromCharCode.apply(String, payload); 122 ->}function decodeToJson(payload) { 123 -> var str = decodeToString(payload); 124 -> var data = JSON.parse(str); 125 -> return data; 126 ->} 127 ->if (flg===2){ 128 ->return result; 129 ->} 130 130 131 - 132 132 (% class="lead" %) 133 133 Input Downlink Converter 134 134 135 135 [[image:1728536142721-488.png||height="470" width="407"]] 136 136 137 -Example Code as below: 108 +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]] 138 138 139 ->function hexToBase64(hexString) { 140 -> var bytes = hexString.match(/.{2}/g); 141 -> var binaryString = bytes.map(function(byte) { 142 -> return String.fromCharCode(parseInt(byte, 16)); 143 -> }).join(''); 144 -> 145 -> return btoa(binaryString); 146 ->} 147 ->var flg = "shared_value" in metadata 148 ->var value2 = parseInt(metadata.ss_timevalue).toString(16)if (value2.length==1){ 149 -> value2 = "00000"+parseInt(metadata.ss_timevalue).toString(16) 150 ->} 151 ->else if (value2.length==2){ 152 -> value2 = "0000"+parseInt(metadata.ss_timevalue).toString(16) 153 ->} 154 ->else if (value2.length==3){ 155 -> value2 = "000"+parseInt(metadata.ss_timevalue).toString(16) 156 ->} 157 ->else if (value2.length==4){ 158 -> value2 = "00"+parseInt(metadata.ss_timevalue).toString(16) 159 ->} 160 ->else if (value2.length==5){ 161 -> value2 = "0"+parseInt(metadata.ss_timevalue).toString(16) 162 ->} 163 ->else { 164 -> value2 = value2 165 ->} 166 ->var data = "01"+value2 167 ->if (flg === true){ 168 ->data = { 169 -> downlinks: [{ 170 -> f_port: 1, 171 -> confirmed: false, 172 -> frm_payload: hexToBase64(metadata.shared_value), 173 -> priority: "NORMAL" 174 -> }] 175 -> }; 176 ->} 177 ->else{ 178 -> data = { 179 -> downlinks: [{ 180 -> f_port: 1, 181 -> confirmed: false, 182 -> frm_payload: hexToBase64(data), 183 -> priority: "NORMAL" 184 -> }] 185 -> }; 186 ->} 187 ->var result = { 188 -> contentType: "JSON", 189 -> data: JSON.stringify(data), 190 -> metadata: { 191 -> devId: metadata.ss_devid 192 -> } 193 ->}; 194 ->if (metadata.shared_timevalue!=="test" || metadata.ss_timevalue!=="test"){ 195 ->return result; 196 ->} 197 197 198 - 199 199 (% class="lead" %) 200 200 Set up Connection to The Things Network application 201 201 ... ... @@ -213,7 +213,7 @@ 213 213 [[image:1728536420275-153.png||height="208" width="1404"]] 214 214 215 215 216 -== 2.3 Test Uplink ==128 +== 3.3 Test Uplink == 217 217 218 218 We can use Simulate Uplink to simulate an uplink in the things stack. Then we should be able to see the message in ThingsEye 219 219 ... ... @@ -222,3 +222,200 @@ 222 222 223 223 [[image:1728536541040-814.png]] 224 224 137 += 4.Connect chirpstack to Thingseye by way of MQTT = 138 + 139 +* **How to connect chirpstack to Thingseye by way of MQTT? The following tutorial will show you** 140 + 141 +== 4.1 Thingseye adds MQTT integration == 142 + 143 +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"; 144 + 145 +[[image:图片1.png]] 146 + 147 +== 4.2 Add an uplink and downlink data converter == 148 + 149 +In the function decoder field, specify the script to parse and transform the data. 150 + 151 +[[image:图片2.png]] 152 + 153 +* **Uplink——JavaScript:** 154 + 155 +var data = decodeToJson(payload); 156 + 157 +var deviceName = data.deviceInfo.deviceName; 158 + 159 +var deviceType = data.applicationName; 160 + 161 +var devEui = data.deviceInfo.devEui 162 + 163 +var label = data.deviceInfo.devEui 164 + 165 +var model = {}; 166 + 167 +var data2 = data.object; 168 + 169 +var flg = data.fPort 170 + 171 +for (var key in data2) { 172 + 173 + ~/~/ 将属性名存入新对象中 174 + 175 + model[key] = data2[key]; 176 + 177 +} 178 + 179 +~/~/var obj = {"devid":deviceName} 180 + 181 +var result = { 182 + 183 + deviceName: deviceName, 184 + 185 + deviceType: deviceType, 186 + 187 + telemetry: model, 188 + 189 + groupName: "Case Study", 190 + 191 + ~/~/label:label, 192 + 193 + attributes:{"devEui":devEui, 194 + 195 + ~/~/"timevalue":"test", 196 + 197 + "inactivityTimeout":1260000 198 + 199 + ~/~/ "High_humidity_alarm":"not set", 200 + 201 + ~/~/ "High_temperature_alarm":"not set", 202 + 203 + ~/~/ "Low_humidity_alarm":"not set", 204 + 205 + ~/~/ "Low_temperature_alarm":"not set", 206 + 207 + ~/~/ "Low_voltage_alarm":"not set" 208 + 209 + ~/~/"customerName": "Civionic Engineering & Consulting (2014) Inc." 210 + 211 + } 212 + 213 +}; 214 + 215 +function decodeToString(payload) { 216 + 217 + return String.fromCharCode.apply(String, payload); 218 + 219 +} 220 + 221 +function decodeToJson(payload) { 222 + 223 + var str = decodeToString(payload); 224 + 225 + var data = JSON.parse(str); 226 + 227 + return data; 228 + 229 +} 230 + 231 +return result; 232 + 233 +[[image:图片3.png]] 234 + 235 +* **Dowblink——JavaScript:** 236 + 237 +~/~/ Encode downlink data from incoming Rule Engine message 238 + 239 +~/~/ msg - JSON message payload downlink message json 240 + 241 +~/~/ msgType - type of message, for ex. 'ATTRIBUTES_UPDATED', 'POST_TELEMETRY_REQUEST', etc. 242 + 243 +~/~/ metadata - list of key-value pairs with additional data about the message 244 + 245 +~/~/ integrationMetadata - list of key-value pairs with additional data defined in Integration executing this converter 246 + 247 +~/~/ /~*~* Encoder ~*~*/ 248 + 249 +~/~/var data = {"value":99}; 250 + 251 +~/~/ ~/~/ Process data from incoming message and metadata 252 + 253 +~/~/ data.tempFreq = msg.temperatureUploadFrequency; 254 + 255 +~/~/ data.humFreq = msg.humidityUploadFrequency; 256 + 257 +~/~/ data.devSerialNumber = metadata['ss_serialNumber']; 258 + 259 +~/~/ ~/~/ Result object with encoded downlink payload 260 + 261 +var result = { 262 + 263 + ~/~/ downlink data content type: JSON, TEXT or BINARY (base64 format) 264 + 265 + contentType: "TEXT", 266 + 267 + ~/~/ downlink data 268 + 269 + data: msg.shared_value ,~/~/JSON.stringify(data), 270 + 271 + ~/~/ Optional metadata object presented in key/value format 272 + 273 + metadata: { 274 + 275 + topic: '/test/down/'+metadata.deviceName 276 + 277 + } 278 + 279 +}; 280 + 281 +return result; 282 + 283 +== 4.3 Configure the connection == 284 + 285 +Generate MQTT certificate integrated on chirpstack 286 + 287 +Chirpstack generates CA certificate, TLS certificate, and TLS key respectively 288 + 289 +They correspond to the CA certificate file, Certificate file, and Private key file on thingseye 290 + 291 +[[image:图片4.png]] 292 + 293 +[[image:图片5.png||height="630" width="1269"]] 294 + 295 +* Copy the contents of the certificates and paste them into the linked file below, a total of three certificates are required 296 + 297 +**Integrated Certificate File demo Download Address:** 298 + 299 +[[https:~~/~~/github.com/ThingsEye-io/te-platform/tree/main/chirpstack>>https://github.com/ThingsEye-io/te-platform/tree/main/chirpstack]] 300 + 301 +Enter the server address Host: lns1.thingseye.io on the Connection configuration 302 + 303 +Port: 8883 304 + 305 +Credentials type: PEM 306 + 307 +Upload the certificate and key file 308 + 309 +[[image:图片6.png]] 310 + 311 +[[image:图片7.png]] 312 + 313 +The default for Topic is: 314 + 315 +application/**chirpstack application id**/device/+/event/up 316 + 317 +[[image:图片8.png]] 318 + 319 + 320 +(% class="wikigeneratedid" %) 321 +[[image:屏幕截图 2024-11-25 095805.png||height="374" width="1272"]] 322 + 323 +== 4.4 Check the connection == 324 + 325 +[[image:图片9.png]] 326 + 327 +[[image:图片10.png]] 328 + 329 += 5. Check Data Uplink Log = 330 + 331 +User can check the devices log in Intergration. 332 + 333 +[[image:1729562069134-315.png||height="587" width="723"]]
- 1728566363151-470.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.EdwinChen - Size
-
... ... @@ -1,0 +1,1 @@ 1 +61.9 KB - Content
- 1729562069134-315.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.EdwinChen - Size
-
... ... @@ -1,0 +1,1 @@ 1 +67.5 KB - Content
- 1732678750938-753.jpg
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.hera - Size
-
... ... @@ -1,0 +1,1 @@ 1 +173.5 KB - Content
- 1732679080974-799.jpg
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.hera - Size
-
... ... @@ -1,0 +1,1 @@ 1 +176.4 KB - Content
- 图片1.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.hera - Size
-
... ... @@ -1,0 +1,1 @@ 1 +123.1 KB - Content
- 图片10.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.hera - Size
-
... ... @@ -1,0 +1,1 @@ 1 +173.4 KB - Content
- 图片2.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.hera - Size
-
... ... @@ -1,0 +1,1 @@ 1 +163.3 KB - Content
- 图片3.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.hera - Size
-
... ... @@ -1,0 +1,1 @@ 1 +124.8 KB - Content
- 图片4.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.hera - Size
-
... ... @@ -1,0 +1,1 @@ 1 +68.8 KB - Content
- 图片5.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.hera - Size
-
... ... @@ -1,0 +1,1 @@ 1 +98.5 KB - Content
- 图片6.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.hera - Size
-
... ... @@ -1,0 +1,1 @@ 1 +136.5 KB - Content
- 图片7.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.hera - Size
-
... ... @@ -1,0 +1,1 @@ 1 +143.5 KB - Content
- 图片8.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.hera - Size
-
... ... @@ -1,0 +1,1 @@ 1 +151.0 KB - Content
- 图片9.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.hera - Size
-
... ... @@ -1,0 +1,1 @@ 1 +134.6 KB - Content
- 屏幕截图 2024-11-25 095805.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.hera - Size
-
... ... @@ -1,0 +1,1 @@ 1 +45.7 KB - Content
- 屏幕截图 2024-11-27 113616.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.hera - Size
-
... ... @@ -1,0 +1,1 @@ 1 +117.5 KB - Content