Changes for page Connect Devices to ThingsEye
Last modified by Hera Guo on 2025/02/18 09:29
Summary
-
Page properties (1 modified, 0 added, 0 removed)
-
Attachments (0 modified, 1 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -14,7 +14,7 @@ 14 14 == 2.1 UDP Interface == 15 15 16 16 * Server Address: server1.thingseye.io 17 -* Port: 1156 017 +* 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"]]28 +[[image:1728566363151-470.png]] 29 29 30 30 In server side, Tenant Administrator can check this in Tenant UDP Server location. 31 31 ... ... @@ -71,12 +71,12 @@ 71 71 72 72 73 73 74 -= 2. Connect to The Things Stack =74 += 3. Connect to The Things Stack = 75 75 76 -== 2.1 Network Structure ==76 +== 3.1 Network Structure == 77 77 78 78 79 -== 2.2 Creat Integration for The Things Stack. ==79 +== 3.2 Creat Integration for The Things Stack. == 80 80 81 81 (% class="lead" %) 82 82 Add Integration ... ... @@ -95,107 +95,17 @@ 95 95 96 96 [[image:1728535941851-388.png||height="466" width="398"]] 97 97 98 -Demo Code as below :98 +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: 106 +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 ==126 +== 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 ... ... @@ -221,4 +221,3 @@ 221 221 222 222 223 223 [[image:1728536541040-814.png]] 224 -
- 1728566363151-470.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.EdwinChen - Size
-
... ... @@ -1,0 +1,1 @@ 1 +61.9 KB - Content