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, 0 added, 1 removed)
Details
- Page properties
-
- Content
-
... ... @@ -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 2**47 +* Set to use ThingsEye UDP server: **AT+SERVADDR=server1.thingseye.io,11560** 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 ... ... @@ -71,12 +71,12 @@ 71 71 72 72 73 73 74 -= 3. Connect to The Things Stack =74 += 2. Connect to The Things Stack = 75 75 76 -== 3.1 Network Structure ==76 +== 2.1 Network Structure == 77 77 78 78 79 -== 3.2 Creat Integration for The Things Stack. ==79 +== 2.2 Creat Integration for The Things Stack. == 80 80 81 81 (% class="lead" %) 82 82 Add Integration ... ... @@ -95,17 +95,107 @@ 95 95 96 96 [[image:1728535941851-388.png||height="466" width="398"]] 97 97 98 -Demo JavaScriptCode:[[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]]98 +Demo Code as below: 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 +>} 100 100 131 + 101 101 (% class="lead" %) 102 102 Input Downlink Converter 103 103 104 104 [[image:1728536142721-488.png||height="470" width="407"]] 105 105 106 -Example JavascriptCode 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]]137 +Example Code as below: 107 107 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 +>} 108 108 198 + 109 109 (% class="lead" %) 110 110 Set up Connection to The Things Network application 111 111 ... ... @@ -123,7 +123,7 @@ 123 123 [[image:1728536420275-153.png||height="208" width="1404"]] 124 124 125 125 126 -== 3.3 Test Uplink ==216 +== 2.3 Test Uplink == 127 127 128 128 We can use Simulate Uplink to simulate an uplink in the things stack. Then we should be able to see the message in ThingsEye 129 129 ... ... @@ -131,11 +131,3 @@ 131 131 132 132 133 133 [[image:1728536541040-814.png]] 134 - 135 - 136 - 137 -= 4. Check Data Uplink Log = 138 - 139 -User can check the devices log in Intergration. 140 - 141 -[[image:1729562069134-315.png||height="587" width="723"]]
- 1729562069134-315.png
-
- Author
-
... ... @@ -1,1 +1,0 @@ 1 -XWiki.EdwinChen - Size
-
... ... @@ -1,1 +1,0 @@ 1 -67.5 KB - Content