Version 18.2 by Xiaoling on 2022/07/22 11:52

Show last authors
1 **Table of Contents:**
2
3 {{toc/}}
4
5
6
7 = 1. Introduction =
8
9
10 The Dragino LoRaWAN gateway can commuicate with LoRaWAN ABP End Node without the need of LoRaWAN server. It can be used in some cases such as:
11
12 * No internet connection.
13 * User wants to get data forward in gateway and forward to their server base on MQTT/HTTP, etc. (Combine ABP communication method and [[MQTT forward together>>MQTT Forward Instruction]]).
14
15 (((
16 The basic of this feature is the decoding of (% style="color:red" %)**LoRaWAN ABP End Node**(%%). Requirements:
17 )))
18
19 1. LoRaWAN End Node in ABP mode. Make sure your end node works in this mode. End node most are default set to OTAA mode
20 1. LoRaWAN Gateway model: [[LPS8>>url:http://www.dragino.com/products/lora-lorawan-gateway/item/148-lps8.html]], [[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]] ,[[LIG16>>url:http://www.dragino.com/products/lora-lorawan-gateway/item/171-lig16.html]]
21 1. Firmware version for below instruction:**[[(% style="color:purple" %)Since LG02_LG08~~-~~-build-v5.4.1593400722-20200629-1120>>url:http://www.dragino.com/downloads/index.php?dir=LoRa_Gateway/LPS8/Firmware/Release/]](%%)**
22
23
24 = 2. How it works =
25
26
27 (% style="color:#037691" %)**Video Instruction**(%%): **[[https:~~/~~/youtu.be/ZBjXwmp7rwM>>url:https://youtu.be/ZBjXwmp7rwM]]**
28
29
30 Assume we have the LoRaWAN tracker LGT92 which works in ABP mode and US915 band. It has below keys:
31
32 (% class="box infomessage" %)
33 (((
34 **AT+NWKSKEY=72 32 63 95 dd 8f e2 b2 13 66 e4 35 93 8f 55 df
35 AT+APPSKEY=b3 17 f8 14 7a 43 27 8a 6a 31 c4 47 3d 55 5d 33
36 AT+DADDR=2602111D**
37 )))
38
39 (((
40 and we have the LG308 works and US915 band and support ABP decryption. User can input these keys in LG308 so the LG308 can communicate with LGT92.
41
42
43 )))
44
45 We need to input above keys in LG308 and enable ABP decryption.
46
47 [[image:image-20220527161119-1.png]]
48
49 Input the ABP keys in LG308
50
51
52 == 2.1 Upstream ==
53
54
55 Now when this End Node (Dev Addr=2602111D) send a uplink packet. When this packet arrive LG308, LG308 will decode it and put the decode data on the file /var/iot/channels/2602111D . So we have this data for further process with other applications in LG308.
56
57 (((
58 We can see the log of LG308 to know this packet arrive
59 )))
60
61 [[image:image-20220527161149-2.png]]
62
63 LG308 log by "(% style="color:red" %)**logread -f**" (%%)command
64
65
66 The data of End Node is stored in the file /var/iot/channels/2602111D. We can use hexdump command to check it.
67
68 (% class="box" %)
69 (((
70 root@dragino-1d25dc:~~# hexdump /var/iot/channels/2602111D
71 0000000 (% style="color:#037691" %)**4646 4646 4646 3946 3030 3030 3030 3546**(%%)      ~-~-> Got RSSI and SNR    
72 0000010 (% style="color:#037691" %)**cc0c 0b63 0266 017f ff7f ff00 **(%%) ~-~-> Payload
73 000001c
74 )))
75
76 * **RSSI**: 4646 4646 4646 3946 = 0xFFFF FF9F : So RSSI = (0xFFFF FF9F - 0x100000000) = -97
77 * **SNR**: 3030 3030 3030 3546 = 0x0000 005F = 95, need to divide 10 so SNR is 9.5
78 * **Payload**: 0xcc0c 0b63 0266 017f ff7f ff00
79
80
81 (% class="box" %)
82 (((
83 (% style="color:red" %)**Notice 1**(%%): The data file stored in LG308 for the end node is bin file. If the end node sends ASCII string to gateway, the output will as below:
84 in LGT92, use (% style="color:#037691" %)**AT+SEND=12:hello world** (%%)to send ASCII string
85 root@dragino-1d25dc:~~# hexdump /var/iot/channels/2602111D
86 0000000 4646 4646 4646 3946 3030 3030 3030 3546
87 0000010 6865 6c6c 6f20 776f 726c 6400      ~-~-> Got ASCII code "hello world"    
88 000001c
89 )))
90
91 (% class="box" %)
92 (((
93 (% style="color:red" %)**Notice 2**(%%): The upstream payload length should match the LoRaWAN length requirement (max length depends on Frequency and DR), otherwise the gateway can't decode the payload.
94 )))
95
96
97 === 2.2.1 Decode Method ===
98
99
100 The decode methods: (% style="color:#037691" %)**ASCII String, Decode_LHT65**(%%) doesn't affect how the sensor data is stored, they are to define how should the sensor data to be sent.
101
102 For example we have a LHT65 , works in ABP mode and gateway successful get the data, which are:
103
104 (% class="box" %)
105 (((
106 root@dragino-1baf44:~~# hexdump /var/iot/channels/01826108
107 0000000 4646 4646 4646 4537 3030 3030 3030 3438
108 0000010 ccd1 7fff 7fff 017f ff7f ff00         
109 000001c
110 )))
111
112
113 If we choose ASCII decoder, the MQTT process will send out with mqtt-data:
114
115 (% class="box" %)
116 (((
117 Sun Sep 27 04:33:16 2020 user.notice root: [IoT.MQTT]:pub_topic[-t]: dragino-1baf44/01826108/data
118 Sun Sep 27 04:33:16 2020 user.notice root: [IoT.MQTT]:decoder: ASCII
119 Sun Sep 27 04:33:16 2020 user.notice root: [IoT.MQTT]:mqtt_data[-m]: (% style="color:#037691" %)**ffffffe700000048ccd17fff7fff017fff7fff00**
120 )))
121
122
123 If we choose Decode_LHT65, the MQTT process will send out with mqtt-data
124
125 (% class="box" %)
126 (((
127 Sun Sep 27 04:36:45 2020 user.notice root: [IoT.MQTT]:pub_topic[-t]: dragino-1baf44/01826108/data
128 Sun Sep 27 04:36:45 2020 user.notice root: [IoT.MQTT]:decoder: Dragino_LHT65
129 Sun Sep 27 04:36:45 2020 user.notice root: [IoT.MQTT]:mqtt_data[-m]:** (% style="color:#037691" %){"Hum_SHT":32.7,"BatV":3.281,"TempC_DS":32.9,
130 "EXT":"Temperature Sensor","RSSI":-24,"TempC_SHT":85.0,"SNR":8.2,"ext_sensor":0}(%%)**
131 )))
132
133 Above scripts are store in /etc/lora/decoder/. User can put their scripts here and select it in the UI.
134
135
136
137 === 2.2.2 How to Decode My End Node ===
138
139
140 **1.** Configure the ABP keys for your end node in the gateway. enable ABP decode in Web UI
141
142 **2. **Don't choose MQTT service, use LoRaWAN.
143
144 **3.** When your end node send a message to the gateway, there will be a file store in /var/iot/channels. full path should be /var/iot/channels/END_NODE_DEV_ADDR
145
146 **4.** Use the /etc/lora/decoder/Dragino_LHT65 as template to decode your payload. This script is written in Lua language. User can manually call this script when you see the data file in /var/iot/channels by running:
147
148 {{{/etc/lora/decoder/Dragino_LHT65 END_NODE_DEV_ADDR
149 }}}
150
151 **5.** What you see as output is the MQTT data device will upload, user's end node has different payload compare with LHT65, most properly this file will report with error. User need to modify to match the actual payload.
152
153
154 (% style="color:red" %)
155 **Some notice:**
156
157 * RSSI and SNR are added when gateway receive the packet, so there is always this field.
158 * If you rename the file, please make it executable.
159 * See this link for lua.bit module: [[http:~~/~~/luaforge.net/projects/bit/>>url:http://luaforge.net/projects/bit/]]
160 * Lua json module: [[http:~~/~~/json.luaforge.net/>>url:http://json.luaforge.net/]]
161 * the last line return is what will be used for MQTT
162 * User can use other language ,not limited to Lua, just make sure the return is what you want to send.
163
164
165
166 == 2.2 Downstream ==
167
168
169 In LG308, we can create a file in the directory /var/iot/push for downstream purpose. We recommend using each command to generate this file. This file will be used for transmission and auto-deleted after used
170
171 The file should use below format:
172
173 (% style="color:#037691" %)**dev_addr,imme/time,txt/hex,payload**
174
175 Since fimware > Dragino-v2 lgw-5.4.1608518541 . Support more option
176
177 (% style="color:#037691" %)**dev_addr,imme/time,txt/hex,payload,txpw,txbw,SF,frequency,rxwindow**
178
179 * **dev_addr:** Inptu the device address
180 * **imme/time:**
181 ** imme: send downstream immediately,For Class C end node.
182 ** time: send downstream after receive device's uplink. For Class A end node
183 * **txt/hex:**
184 ** txt: send payload in ASCII
185 ** hex: send payload in HEX
186 * **payload: **payload to be sent, payload lenght should match the LoRaWAN protocol requirement.
187 * **txpw:** Transmit Power. example: 20
188 * **txbw:** bandwidth:
189 ** 1: 500 kHz
190 ** 2: 250 kHz
191 ** 3: 125 kHz
192 ** 4: 62.5 kHz
193 * **SF:** Spreading Factor : SF7/SF8/SF9/SF10/SF11/SF12
194 * **Frequency:** Transmit Frequency: example: 923300000
195 * **rxwindow:** transmit on Rx1Window or Rx2Window.
196
197
198
199 (% style="color:blue" %)**Completely exmaple:**
200
201 * **Old version:** echo 018193F4,imme,hex,0101 > /var/iot/push/test
202 * **New version:** echo 018193F4,imme,hex,0101,20,1,SF12,923300000,2 > /var/iot/push/test
203
204
205
206 (% style="color:#037691" %)**Downstream Frequency**
207
208 The LG308 will use the RX2 window info to send the downstream payload, use the default LoRaWAN settings, as below:
209
210 * EU868: 869.525Mhz, DR0(SF12BW125)
211 * US915: 923.3Mhz, SF12 BW500
212 * CN470: 505.3Mhz, SF12 BW125
213 * AU915: 923.3Mhz, SF12 BW500
214 * AS923: 923.2Mhz, SF10 BW125
215 * KR920: 921.9Mhz, SF12 BW125
216 * IN865: 866.55Mhz, SF10 BW125
217 * RU864: 869.1Mhz, SF12 BW125
218
219
220
221 (% style="color:#037691" %)**Examples:**
222
223 (% class="box" %)
224 (((
225 we can use echo command to create files in LG308 for downstream.
226 root@dragino-1d25dc:~~# echo 2602111D,time,hex,12345678 > /var/iot/push/test
227
228
229 **1)** From logread -f of gateway, we can see it has been added as pedning.
230 lora_pkt_fwd[4286]: INFO~~ [DNLK]Looking file : test
231 lora_pkt_fwd[4286]: INFO~~ [DNLK]devaddr:2602111D, txmode:time, pdfm:hex, size:4, payload1:4Vx,payload_hex:77C1BB90
232 lora_pkt_fwd[4286]: INFO~~ [DNLK] DNLINK PENDING!(1 elems).
233
234
235 **2)** When there is an upstrea from end node, this downstream will be sent and shows:
236 lora_pkt_fwd[4286]: INFO: tx_start_delay=1497 (1497.000000) - (1497, bw_delay=0.000000, notch_delay=0.000000)
237 lora_pkt_fwd[4286]: [LGWSEND]lgw_send done: count_us=3537314420, freq=923300000, size=17
238
239
240 **3)** and the end node will got:
241 [5764825]~*~*~*~** UpLinkCounter= 98 ~*~*~*~**
242 [5764827]TX on freq 905300000 Hz at DR 0
243 Update Interval: 60000 ms
244 [5765202]txDone
245 [5766193]RX on freq 927500000 Hz at DR 10
246 [5766225]rxTimeOut
247 [5767205]RX on freq 923300000 Hz at DR 8
248 [5767501]rxDone
249 Rssi= -41
250 Receive data
251 (% style="color:#037691" %)**2:12345678**  (%%) ~-~-> Hex
252
253
254 **4) **If we use the command "echo 2602111D,time,txt,12345678 > /var/iot/push/test" for downstream, the end node will got:
255 [5955877]~*~*~*~** UpLinkCounter= 102 ~*~*~*~**
256 [5955879]TX on freq 904100000 Hz at DR 0
257 Update Interval: 60000 ms
258 [5956254]txDone
259 [5957246]RX on freq 923900000 Hz at DR 10
260 [5957278]rxTimeOut
261 [5958257]RX on freq 923300000 Hz at DR 8
262 [5958595]rxDone
263 Rssi= -37
264 Receive data
265 (% style="color:#037691" %)**2:3132333435363738**(%%) ~-~-> ASCII string "12345678"
266 )))
267
268
269 = 3. Example 1: Communicate with LT-22222-L =
270
271
272 Script can be download from: [[Example Script 1>>url:http://www.dragino.com/downloads/index.php?dir=LoRa_Gateway/LPS8/Firmware/customized_script/&file=talk_to_lt-22222-l_v0.1.sh]]
273
274 (% class="box" %)
275 (((
276 //#!/bin/sh
277 # This scripts shows how to use LPS8/LG308/DLOS8 to communicate with two LoRaWAN End Nodes, without the use of internet or LoRaWAN server
278 #
279 # Hardware Prepare:
280 # 1. LT-22222-L x 2, both are configured to work in
281 #   a) Class C ;
282 # b) ABP Mode ;
283 # c) AT+Mod=1
284 # 2. LPS8,
285 #   a) Firmware version >
286 #   b) Input the LT-22222-L keys in LPS so LPS8 can talk with them.
287 #   c) Lorawan server choose built-in
288 #   d) in Custom page, select custom script to point to this script. (put this script in /etc/iot/scripts directory)
289 #
290 # How it works?
291 #   a) Devices 1 sends a uplink payload to LPS8. LPS8 will get the DI1 and DI2 info from the payload
292 #   b) LPS8 will send a message to Device 2 to set the Device2 DO1 = Device1 DI1, and Device DO2 = Device DI2.
293 #   c) Device2 will change DO1 and DO2 to according to the message from LPS8, and send back a message to LPS8 with the its DO1
294 #   and DO2 value. LPS8 will ask Device1 to change its DO1 to same as Device 2, and change the DO2 to the same as Device 2.
295 #   ( The purpose of this step is to show that the Device2 has already do the change there).
296 #
297 #  For example: If current status of Device1 and Device2 leds shows:
298 #  Device1: DI1: ON, DI2: ON , DO1: OFF,  DO2: OFF
299 #  Device2: DI1: OFF, DI2: OFF , DO1: OFF,  DO2: OFF
300 #
301 #  Step2  will cause below change:
302 #  Device1: DI1: ON, DI2: ON , DO1: OFF,  DO2: OFF
303 #  Device2: DI1: OFF, DI2: OFF , DO1: ON,  DO2: ON
304
305 #  Step3 will cause below change:
306 #  Device1: DI1: ON, DI2: ON , DO1: ON,  DO2: ON
307 #  Device2: DI1: OFF, DI2: OFF , DO1: ON,  DO2: ON
308 #  So if a person is in the Device 1 location, he can check if the DO LED match DI LEDs on Device 1 to confirm
309 #  whether the Device 2 has been changed.//
310 )))
311
312
313 **~1. Input keys**
314
315 [[image:image-20220527162450-3.png]]
316
317 Input Keys in LPS8
318
319
320 **2. Make sure the LPS8 and LT use the same frequency bands, choose EU868 in this test.**
321
322
323 **3. Choose Built-in server**
324
325 [[image:image-20220527162518-4.png]]
326
327 Choose Built-in server
328
329
330 **4. Run the script.**
331
332 [[image:image-20220722115213-2.png]]
333
334 Run the script
335
336
337 **5. Output:**
338
339 [[image:image-20220722115133-1.png]]
340
341 Output from LPS8
342
343
344 = 4. Example 2: Communicate to TCP Server =
345
346
347 [[image:image-20220527162648-7.png]]
348
349 Network Structure
350
351
352 Full instruction video inlcude how to write scripts to fit server needed is here:
353
354
355 (% style="color:#037691" %)**Video Instruction**(%%): **[[https:~~/~~/youtu.be/-nevW6U2TsE>>url:https://youtu.be/-nevW6U2TsE]]**
356
357
358 (% style="color:red" %)**Note: Firmware version must be higher than lgw-5.4.1607519907**
359
360
361 Assume we already set up ABP keys in the gateway:
362
363 [[image:image-20220527162852-8.png]]
364
365 Input Keys in LPS8
366
367
368
369 **run socket tool in PC**
370
371 [[image:image-20220527163028-9.png]]
372
373
374 Socket tool
375
376
377
378 **Input Server address and port**
379
380 [[image:image-20220527163106-10.png]]
381
382 Input Server address and port
383
384
385
386 **See value receive in socket tool:**
387
388 [[image:image-20220527163144-11.png]]
389
390 value receive in socket tool
391
392
393 If user want to modify the TCP connection method. He can refer: [[https:~~/~~/github.com/dragino/dragino-packages/blob/lg02/haserl-ui/root/usr/bin/tcp_process.sh>>url:https://github.com/dragino/dragino-packages/blob/lg02/haserl-ui/root/usr/bin/tcp_process.sh]]. Same script is on /usr/bin of gateway.