Wiki source code of TCP Connection Instruction

Version 31.1 by Kilight Cao on 2024/01/22 09:54

Hide last authors
Xiaoling 16.9 1 **Table of Contents:**
Xiaoling 1.1 2
Xiaoling 16.12 3 (% aria-label="macro:toc widget" contenteditable="false" role="region" tabindex="-1" %)
4 (((
5 (% style="background-image:url(http://wiki.dragino.com/xwiki/webjars/wiki%3Axwiki/application-ckeditor-webjar/1.61/plugins/widget/images/handle.png); background:rgba(220,220,220,0.5); display:none" %)[[image:data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==||height="15" role="presentation" title="Click and drag to move" width="15"]]
6 )))
Xiaoling 16.2 7
Xiaoling 16.13 8 {{toc/}}
Xiaoling 16.2 9
Xiaoling 16.12 10
11
Xiaoling 1.2 12 = 1. Introduction =
Xiaoling 1.1 13
Xiaoling 16.16 14
Xiaoling 1.2 15 In the TCP IP Client mode, LoRa Gateway can accept LoRa or LoRaWAN packets and send it to the TCP/IP server.
Xiaoling 1.1 16
17
Xiaoling 16.11 18
Xiaoling 1.2 19 = 2. LoRaWAN Mode TCP Connection =
Xiaoling 1.1 20
Xiaoling 1.2 21 == 2.1 Support Hardware ==
Xiaoling 1.1 22
Xiaoling 16.16 23
Xiaoling 1.2 24 * [[LPS8>>url:http://www.dragino.com/products/lora-lorawan-gateway/item/148-lps8.html]]
25 * [[LG308>>url:http://www.dragino.com/products/lora-lorawan-gateway/item/140-lg308.html]], [[DLOS8>>url:http://www.dragino.com/products/lora-lorawan-gateway/item/160-dlos8.html]]
Xiaoling 1.1 26
Xiaoling 16.7 27
Xiaoling 1.2 28 == 2.2 Typology & Instruction ==
Xiaoling 1.1 29
Xiaoling 16.16 30
Xiaoling 25.3 31 (% aria-label="image-20220527144058-1.png image widget" contenteditable="false" role="region" tabindex="-1" %)[[image:image-20220527144058-1.png||data-widget="image"]]
Xiaoling 1.1 32
Xiaoling 25.3 33 (% style="background-image:url(http://wiki.dragino.com/xwiki/webjars/wiki%3Axwiki/application-ckeditor-webjar/1.61/plugins/widget/images/handle.png); background:rgba(220,220,220,0.5); display:none" %)[[image:data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==||draggable="true" height="15" role="presentation" title="Click and drag to move" width="15"]](% title="Click and drag to resize" %)​
34
Xiaoling 1.2 35 Network Structure
Xiaoling 1.1 36
37
Xiaoling 1.2 38 = 3. Raw LoRa Mode TCP Connection =
Xiaoling 1.1 39
Xiaoling 1.3 40 == 3.1 Support Hardware ==
Xiaoling 1.2 41
Xiaoling 16.16 42
Xiaoling 1.10 43 * [[LG01-N>>url:http://www.dragino.com/products/lora-lorawan-gateway/item/143-lg01n.html]], [[OLG01-N>>url:http://www.dragino.com/products/lora-lorawan-gateway/item/144-olg01n.html]]
44 * [[LG02>>url:http://www.dragino.com/products/lora-lorawan-gateway/item/135-lg02.html]], [[OLG02>>url:http://www.dragino.com/products/lora-lorawan-gateway/item/136-olg02.html]]
Xiaoling 1.2 45
Xiaoling 16.3 46
Xiaoling 16.11 47 == 3.2 Typology ==
Xiaoling 16.10 48
49
Xiaoling 1.2 50 The working topology is as below. In this mode, The Uplink LoRa packets should use a customized format.
51
52
Xiaoling 16.16 53 (% aria-label="image-20220527144300-2.png image widget" contenteditable="false" role="region" tabindex="-1" %)[[image:image-20220527144300-2.png||data-widget="image"]](% title="Click and drag to resize" %)​
54
Xiaoling 1.2 55 TCP/IP Forward working topology
56
57
Xiaoling 1.3 58 == 3.3 Instruction Before Firmware lgw~-~-build-v5.4.1606631585-20201129-1434 ==
Xiaoling 1.2 59
Xiaoling 1.3 60 === 3.3.1 Select TCP-IP Client mode ===
Xiaoling 1.2 61
62
Xiaoling 16.16 63 (% aria-label="image-20220527144723-3.png image widget" contenteditable="false" role="region" tabindex="-1" %)[[image:image-20220527144723-3.png||data-widget="image"]](% title="Click and drag to resize" %)​
64
Xiaoling 1.2 65 Select TCP-IP Client mode
66
67
Xiaoling 1.3 68 === 3.3.2 Configure the Radio channel ===
Xiaoling 1.2 69
70
Xiaoling 16.16 71 (% aria-label="image-20220527144755-4.png image widget" contenteditable="false" role="region" tabindex="-1" %)[[image:image-20220527144755-4.png||data-widget="image"]](% title="Click and drag to resize" %)​
72
Xiaoling 1.2 73 Configure the Radio channel with the match radio settings frequency as the LoRa End Node
74
75
Xiaoling 1.3 76 === 3.3.3 Configure TCP Server Info ===
Xiaoling 1.2 77
78
Xiaoling 16.16 79 (% style="color:red" %)**Note: Gateway may receive many LoRa packets, it will only transfer the packet with the same ID as specify in the channel.**
Xiaoling 16.11 80
Xiaoling 16.16 81 (% aria-label="image-20220527144837-5.png image widget" contenteditable="false" role="region" tabindex="-1" %)[[image:image-20220527144837-5.png||data-widget="image"]](% title="Click and drag to resize" %)​
Xiaoling 1.2 82
83 Configure TCP Server Info
84
85
Xiaoling 1.6 86 === 3.3.4 About uplink data format from End Node ===
Xiaoling 1.2 87
Xiaoling 16.11 88
Xiaoling 1.2 89 The LoRa end node should upload the data with below format:
90
Xiaoling 1.5 91 (% class="box" %)
92 (((
Xiaoling 6.3 93 Uplink Format:** (% style="color:#4f81bd" %)<Channel_ID>data(%%)**
Xiaoling 1.5 94 For example, if we have configured 2 channels 12345 and 34567.
Xiaoling 1.2 95 And there is are three LoRa End nodes sending: 12345,34567,78
96 The LG02 will accept the data from 12345 and 34567, it will ignore the data from Node 78
Xiaoling 25.3 97
98
Xiaoling 16.11 99 (% style="color:blue" %)**Case 1**:(%%)
Xiaoling 1.2 100 Node 12345 send <12345>field1=0.0&field2=1102.0
101 Node 34567 doesn’t send anyting
Xiaoling 1.5 102 The TCP/IP server will get {"12345":"field1=0.0&field2=1102.0"}
Xiaoling 25.3 103
104
Xiaoling 16.11 105 (% style="color:blue" %)**Case 2**:(%%)
Xiaoling 1.2 106 Node 12345 send <12345>field1=0.0&field2=1102.0
107 Node 34567 send <34567>temp=34
Xiaoling 1.5 108 The TCP/IP server will get {"34567":"temp=34","12345":"field1=0.0&field2=1102.0"}
109 )))
Xiaoling 1.2 110
Xiaoling 16.16 111 (% aria-label="image-20220527144959-6.png image widget" contenteditable="false" role="region" tabindex="-1" %)[[image:image-20220527144959-6.png||data-widget="image"]](% title="Click and drag to resize" %)​
Xiaoling 1.2 112
113 Configure TCP Server Info
114
Xiaoling 16.12 115
Xiaoling 1.7 116 LoRa End Device reference source code: [[check this link>>url:https://github.com/dragino/Arduino-Profile-Examples/blob/master/libraries/Dragino/examples/IoTServer/ThingSpeak/MQTT_Client/MQTT_DHT11_Client_updata_to_ThingSpeak_/MQTT_DHT11_Client_updata_to_ThingSpeak_.ino]].
Xiaoling 1.2 117
118
Xiaoling 1.3 119 == 3.4 Instruction After Firmware lgw~-~-build~-~-v5.4.1612428704~-~-20210204-1653 ==
Xiaoling 1.2 120
Xiaoling 1.3 121 === 3.4.1 Configure the Radio channel ===
Xiaoling 1.2 122
Xiaoling 16.16 123
Xiaoling 25.3 124 (% aria-label="image-20220527145111-7.png image widget" contenteditable="false" role="region" tabindex="-1" %)[[image:image-20220527145111-7.png||data-widget="image"]]
Xiaoling 1.2 125
Xiaoling 25.3 126 (% title="Click and drag to resize" %)​
127
Xiaoling 1.2 128 Configure the Radio channel with the match radio settings frequency as the LoRa End Node
129
130
Xiaoling 1.4 131 === 3.4.2 Configure TCP Server Info ===
Xiaoling 1.2 132
Xiaoling 16.12 133
Xiaoling 16.16 134 (% style="color:red" %)**Note: Gateway will transfer the packet if they arrive in the right format .**
Xiaoling 1.2 135
Xiaoling 25.3 136 (% aria-label="image-20220527145151-8.png image widget" contenteditable="false" role="region" tabindex="-1" %)[[image:image-20220527145151-8.png||data-widget="image"]]
Xiaoling 1.2 137
Xiaoling 25.3 138 (% title="Click and drag to resize" %)​
139
Xiaoling 1.2 140 Configure TCP Server Info
141
142
Xiaoling 1.4 143 === 3.4.3 About uplink data format from End Node ===
Xiaoling 1.2 144
Xiaoling 16.16 145
Xiaoling 1.2 146 The LoRa end node should upload the data with below format:
147
Xiaoling 1.8 148 (% class="box" %)
149 (((
Xiaoling 9.3 150 Uplink Format: (% style="color:#4f81bd" %)**<Channel_ID>data**(%%)
Xiaoling 1.2 151 And there is a LoRa End node sending below packets:
152 *<12345>Hello From Sensor1
Xiaoling 1.8 153 )))
Xiaoling 1.2 154
155
Xiaoling 1.8 156 (% class="box" %)
157 (((
158 LG01/LG02 will uplink 12345:Hello From Sensor1 and usr can use logread -f to check the log.
159 Thu Feb  4 08:21:49 2021 user.notice iot_keep_alive: use WAN or WiFi for internet access now
160 Thu Feb  4 08:21:53 2021 daemon.info tcp_process.sh[18564]: /var/iot/channels/ CREATE 12345
161 Thu Feb  4 08:21:53 2021 user.notice root: [IoT.TCP]: Check for sensor update
162 Thu Feb  4 08:21:53 2021 user.notice root: [IoT.TCP]: Found Data at Local Channels: 12345
163 Thu Feb  4 08:21:53 2021 user.notice root: [IoT.TCP]:
164 Thu Feb  4 08:21:53 2021 user.notice root: [IoT.TCP]:~-~-~-~--
165 Thu Feb  4 08:21:53 2021 user.notice root: [IoT.TCP]:server: 10.130.2.149
166 Thu Feb  4 08:21:53 2021 user.notice root: [IoT.TCP]:port: 60000
167 Thu Feb  4 08:21:53 2021 user.notice root: [IoT.TCP]:decoder: LG01/LG02 Raw Data
168 Thu Feb  4 08:21:53 2021 user.notice root: [IoT.TCP]:tcp_data: 12345:Hello From Sensor1;
169 Thu Feb  4 08:21:53 2021 user.notice root: [IoT.TCP]:~-~-~-~-~-~-
170 )))
Xiaoling 1.2 171
172
173 and TCP server get:
174
Xiaoling 16.12 175 (% aria-label="image-20220527145304-9.png image widget" contenteditable="false" role="region" tabindex="-1" %)[[image:image-20220527145304-9.png||data-widget="image"]](% style="background-image:url(http://wiki.dragino.com/xwiki/webjars/wiki%3Axwiki/application-ckeditor-webjar/1.61/plugins/widget/images/handle.png); background:rgba(220,220,220,0.5); display:none" %)[[image:data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==||draggable="true" height="15" role="presentation" title="Click and drag to move" width="15"]](% title="Click and drag to resize" %)​
Xiaoling 1.2 176
177 TCP Server
178
Xiaoling 16.15 179
Xiaoling 1.8 180 LoRa End Device reference source code: [[check this link>>url:https://github.com/dragino/Arduino-Profile-Examples/blob/master/libraries/Dragino/examples/IoTServer/ThingSpeak/MQTT_Client/MQTT_DHT11_Client_updata_to_ThingSpeak_/MQTT_DHT11_Client_updata_to_ThingSpeak_.ino]].
Xiaoling 1.2 181
Xiaoling 1.8 182
Kilight Cao 22.1 183 == 3.5 Instruction After Firmware lgw~-~-build-v5.4.1668567157-20221116-1054 ==
Xiaoling 16.14 184
Kilight Cao 22.1 185 === 3.5.1 Configure the Frequency Plan ===
186
Xiaoling 25.2 187
Kilight Cao 22.1 188 [[image:image-20230105114141-1.png||height="539" width="1128"]]
189
190 Configure the Frequency Plan with the match radio settings frequency as the LoRa End Node
191
192
193 === 3.5.2 Configure TCP Server Info ===
194
195
196 (% style="color:red" %)**Note: Gateway will transfer the packet if they arrive in the right format.**
197
198 (% aria-label="image-20220527145151-8.png image widget" contenteditable="false" role="region" tabindex="-1" %)[[image:image-20220527145151-8.png||data-widget="image"]]
199
200
201 === 3.5.3 Configure ABP Decryption ===
202
203
204 (% style="color:red" %)**Note: The End Node devices must use ABP join network mode.**
205
206 [[image:image-20230105170545-2.png||height="577" width="1087"]]
207
208
209 === 3.5.3 About uplink data format from End Node ===
210
211
Kilight Cao 25.1 212 [[image:image-20230105171605-5.png||height="513" width="1084"]]
Kilight Cao 22.1 213
Xiaoling 25.2 214
Kilight Cao 25.1 215 [[image:image-20230105171235-4.png||height="480" width="523"]]
Kilight Cao 22.1 216
Xiaoling 25.2 217
Kilight Cao 31.1 218 (% class="wikigeneratedid" %)
219 == 3.6 Example: Use TCP in LPS8v2 ==
220
221 LPS8v2 includes a local ChirpStack Server and Node-Red. This example shows how to configure LHT65N to use with the local Node-Red server. This example assumes users already have:
222
223 * LHT65N register on LPS8v2 Built-In ChirpStack server already
224 * The user is able to see the data on the built-in ChirpStack server device page.
225
226 Below are steps for LPS8v2 to transfer data from a node to the TCP server.
227
228 === 3.6.1 Link Node-Red to Local ChirpStack ===
229
230 Users can download the Node-Red decoder from this link and import it into the Node-Red platform: 
231
232 For more information on importing Input Flow, check out this link: **[[Import Input Flow for Dragino Sensors>>url:http://wiki.dragino.com/xwiki/bin/view/Main/Node-RED/#H3.A0ImportInputFlowforDraginoSensors]]**
233
234 After importing the Input Flow is complete, the user needs to edit the MQTT in the node
235
236
237 **~1. Change the Topic**
238
239 Topic modifies it to the following format:
240
241 **application/Application ID/device/End device ID/event/up**
242
243 Reference link: [[**Node-RED integration** >>url:https://www.chirpstack.io/docs/guides/node-red-integration.html]]
244
245 [[image:image-20240122094847-1.png||height="756" width="1232"]]
246
247
248 **2. Enter the MQTT configuration information**
249
250
251 [[image:image-20240122094930-2.png||height="767" width="1251"]]
252
253
254 **3.** **Click "Update" and Deploy**
255
256 "Connected" indicates that the Link Node-red to Local Chirpstack is normal.
257
258 [[image:image-20240122095122-3.png||height="765" width="1247"]]
259
260
261 **4. Connect to the TCP server**
262
263 [[image:image-20240122095313-4.png||height="767" width="1250"]]
264
265
266 **5. Finally, check the data**
267
268 [[image:image-20240122095424-5.png||height="779" width="1269"]]
269
270
Xiaoling 1.4 271 = 4. Reference =
Xiaoling 1.2 272
Xiaoling 16.16 273
Xiaoling 1.2 274 Set up a TCP/IP server use node.js: [[Reference Link>>url:http://www.dragino.com/downloads/index.php?dir=LoRa_Gateway/LG02-OLG02/Firmware/customized_script/&file=node_tcp_server.txt]]
Xiaoling 25.2 275
276
277