Wiki source code of Notes for ChirpStack

Version 127.1 by Kilight Cao on 2022/12/22 14:07

Show last authors
1 **~ Table of Contents:**
2
3 {{toc/}}
4
5
6
7
8 = 1.  Introduction =
9
10
11 (% style="color:black" %)The ChirpStack open-source LoRaWAN Network Server stack provides open-source components for LoRaWAN networks And the Chirpstack supports the users in building a private LoRaWAN Server. For more info please refer to this [[link>>url:https://www.chirpstack.io/]]
12
13 (((
14 (% style="color:black" %)The dragino gateway can connect the ChirpStack server via Semtech UDP or Semtech Basic Station.
15
16
17 )))
18
19 (% style="color:blue" %)**Prerequisite:**
20
21 **1) Have a Chirstack Server.**
22
23 [[image:image-20220525100058-1.png]]
24
25 ChirpStack home page
26
27
28
29 **2) Gateway model support**
30
31 (% class="box" %)
32 (((
33 (((
34 Semtech UDP : **All Model**
35 Basic Station : [[LIG16>>url:http://www.dragino.com/products/lora-lorawan-gateway/item/171-lig16.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]] [[LPS8>>url:http://www.dragino.com/products/lora-lorawan-gateway/item/148-lps8.html]]
36 (% style="color:red" %)**Note** (%%): the firmware needs >[[lgw~~-~~-build-v5.4.1640315898>>url:https://www.dragino.com/downloads/index.php?dir=LoRa_Gateway/LPS8/Firmware/Release/]]  if use the Bais station
37 )))
38 )))
39
40
41
42 = 2.  Semtech UDP =
43
44 == 2.1  Step 1. Add the Network-servers ==
45
46
47 The network-Servers address varies depending on the ChirpStack server setup environment
48
49 (% class="box" %)
50 (((
51 Windows       ~-~->  Network-server server *  :  localhost:8000
52 Linux  ~-~->  Network-server server *  :  chirpstack-network-server:8000
53 )))
54
55
56 (% style="color:red" %)**If the user cannot add network-Servers, re-check the ChirpStack code or the server building process.**
57
58
59 [[image:image-20220531171609-1.png]]
60
61 Add the Network-servers
62
63
64
65 == 2.2  Step 2. Create Gateway-profiles ==
66
67
68 [[image:image-20220531171651-2.png]]
69
70 Create Gateway-profiles
71
72
73
74 == 2.3  Step 3. Create Service-profiles ==
75
76
77 [[image:image-20220531171809-3.png]]
78
79 Create Service-profiles
80
81
82 In Step 3. Create Service-profiles, the above parameters can be set. If necessary, you can set them by yourself. This is only an example.
83
84 (% style="color:red" %)**Note : Before add the gateway, the user needs to complete the preceding three steps.**
85
86 If the user has completed the preceding steps, proceed to the next step.(% style="display:none" %)
87
88
89
90 == 2.4  Step 4. Add the gateway ==
91
92
93 The example gateway id is: a840411e96744150
94
95 (((
96 (% style="color:red" %)**Note : The Gateway EUI and server addresses must match the ChirpStack configuration.**
97
98
99 )))
100
101 [[image:image-20220531171923-4.png]](% style="display:none" %)
102
103 Add the gateway
104
105
106
107 [[image:image-20220531172031-5.png]]
108
109 Configure the gateway
110
111
112
113 == 2.5  Step 5. Checking gateway Status ==
114
115
116 [[image:image-20220531172158-6.png]](% style="display:none" %)
117
118
119
120 gateway Status
121
122 [[image:image-20220531172304-7.png]]
123
124 gateway Status
125
126
127
128 = 3.  Gateway Registration for Basics Station =
129
130 == 3.1  Introduction ==
131
132
133 The [[Semtech Basic Station>>url:https://doc.sm.tc/station/]] backend implements the [[LNS protocol>>url:https://doc.sm.tc/station/tcproto.html]]. It exposes a WebSocket handler to which Basic Station powered gateways can connect.
134
135 ChirpStack Open-Source LoRaWAN® Network Server needs to set up a configuration that can use Semtech BasicStation.
136
137
138 (% style="color:blue" %)**Below list the support products and Requirements:**
139
140 1. LoRaWAN Gateway model: [[LIG16>>url:http://www.dragino.com/products/lora-lorawan-gateway/item/171-lig16.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]] ,[[LPS8>>url:http://www.dragino.com/products/lora-lorawan-gateway/item/148-lps8.html]]
141 1. Firmware version since :[[lgw~~-~~-build-v5.4.1651822913>>url:https://www.dragino.com/downloads/index.php?dir=LoRa_Gateway/LPS8/Firmware/Test_Firmware/lgw--build-v5.4.1651822913-20220506-1543/]]
142
143 (% style="color:blue" %)**How to set up chirpStack Basic Station**
144
145 Users can check out the ChirpStack Basic Station [[link>>https://www.chirpstack.io/gateway-bridge/backends/basic-station/]] and [[forum>>https://forum.chirpstack.io/search?q=basic%20station]]
146
147
148 (% style="color:blue" %)**What do you need to prepare**
149
150 A gateway that can access the internet normally
151
152
153 == 3.2  Add Gateway ==
154
155
156 [[image:image-20220524164205-10.png]]
157
158
159 == 3.3  Access the gateway GUI ==
160
161
162 Access the gateway GUI interface of LoRaWAN~-~->LoRaWAN ~-~- Basic Station
163
164 [[image:image-20220524164319-11.png]]
165
166
167 User need to Choose the ChirpStack/Senet ~-~- Basic Station , input Server URI and Upload the TLS Certificate
168
169 (% class="box" %)
170 (((
171 Service Provider  ~-~->  Choose the ChirpStack/Senet ~-~- Basic Station
172
173 LNS URI  ~-~->  Enter the LNS URI address, For example : wss:~/~/xxxx.chirpstack.com:433 or ws:~/~/xxxx.chirpstack.com:3001
174
175 LNS TLS trust  ~-~->  Upload the TLS Certificate
176 )))
177
178 (% class="wikigeneratedid" %)
179 [[image:image-20220524164341-12.png]]
180
181
182 == 3.4  Start Station ==
183
184
185 When the user has finished the configuration, Please click **Sace&Apply** to start station to connect ChirpStack.
186
187
188 == 3.5  Successful Connection ==
189
190
191 If user completes the above steps, which will see live date in the ChirpStack.
192
193 [[image:image-20220524164448-13.png]]
194
195
196 == 3.6  Trouble Shooting ==
197
198
199 User can check the station log in the logread/system log page.
200
201 [[image:image-20220531172837-8.png]]
202
203
204 and recode the station log in the system/Recode log page.
205
206 [[image:image-20220531172857-9.png]]
207
208
209 = 4. How the gateway connects to Chirpstack v4 via gateway-bridge =
210
211
212 == 4.1 Configure Packet Forwarder ==
213
214 In the Dragino gateway web interface, you need to configure the Packet Forwarder so that it forwards its data to the port. localhost:1700 or 127.0.0.1:1700
215
216 * In the **LoRaWAN** menu, click on **LoRaWAN ~-~- Semtech UDP**
217 * Make sure the following settings are set:
218 ** **Service Provider:** //~-~-Custom/Private LoRaWAN~-~-//
219 ** **LoRaWAN Server Address:** //localhost or 127.0.0.1//
220 ** **Server port for upstream:** //1700//
221 ** **Server port for downstream:** //1700//
222
223 Click **Save & Apply**.
224
225 [[image:image-20221222114220-2.png||height="748" width="931"]]
226
227
228 == 4.2 Configuring gateway frequency ==
229
230 Note: Gateway frequencies must match
231
232 [[image:image-20221222134830-3.png||height="408" width="923"]]
233
234
235 == 4.3 Modify the gateway-bridge configuration file ==
236
237
238 Run the gateway command line command to modify the gateway-bridge configuration file:
239
240 (% class="box infomessage" %)
241 (((
242 root@dragino-1d27d4:~~#  vim /etc/chirpstack-gateway-bridge/chirpstack-gateway-bridge.toml
243 )))
244
245 [[image:image-20221222113302-1.png]]
246
247 [[image:image-20221222140203-4.png||height="875" width="806"]]
248
249
250 (% class="wikigeneratedid" id="H" %)
251 After the modification, run the following command: **/etc/init.d/chirpstack-gateway-bridge restart**
252
253 == 4.3 (Re)start and stop gateway-bridge ==
254
255 Use the following commands to (re)start and stop the ChirpStack Gateway Bridge Service:
256
257 (% class="box infomessage" %)
258 (((
259 **# start**
260
261 /etc/init.d/chirpstack-gateway-bridge start
262
263 **# stop**
264
265 /etc/init.d/chirpstack-gateway-bridge stop
266
267 **# restart**
268
269 /etc/init.d/chirpstack-gateway-bridge restart
270 )))
271
272 = 5.  Downlink =
273
274 == 5.1 Convert HEX to Base64 ==
275
276
277 (% style="color:red" %)**Note: Chirpstack uses base64 to downlink, the end node user manual provides HEX format of the downlink commands. So user needs to convert the HEX to Base64.**
278
279 **[[Online HEX to Base64 Converter>>https://base64.guru/converter/encode/hex]]:**
280
281 [[image:image-20221010193350-1.png]]
282
283
284
285 **[[Online Base64 to Hex converter>>https://base64.guru/converter/decode/hex]]**
286
287 [[image:image-20221010193621-2.png]]
288
289
290 == 5.2  Chirpstack Downlink Note ==
291
292
293 [[image:image-20220601102543-2.png]]
294
295 **Convert the data to Base64**
296
297 (% style="display:none" %) (%%)
298
299
300 [[image:image-20220531173236-10.png||height="597" width="1215"]]
301
302 **Check ChripStack downlink DataRate**
303
304
305
306 [[image:image-20220525101326-11.png]]
307
308 **Make sure the RX2DR is the same in the end node**
309
310
311 == 5.3  Loraserver Downlink Note ==
312
313
314 User can use MQTT to send downlink payload to ChirpStack to perform downstream to LoRaWAN End
315
316 (((
317 **Below is examples:**
318 )))
319
320 (% class="box" %)
321 (((
322 Connect to your server via MQTT:
323 MQTT Client ID: Any   
324 Protocol:mqtt/tcp   Server IP:loraserver_ip:1883
325 User name: User name Password: password
326 )))
327
328 [[image:image-20220531173419-11.png]]
329
330 (((
331 **MQTT Connect to ChirpStack**
332
333
334
335 )))
336
337 (((
338 **After connect**
339 )))
340
341 (% class="box" %)
342 (((
343 Subscribe : Format:application/ID/device/ Device EUI/rx
344 Example: application/7/device/00aedb3da649cb23/rx
345 )))
346
347 (% class="box" %)
348 (((
349 Publish:
350 Format: Top: application/ID/device/ Device EUI/tx
351 Payload: {"confirmed":true or false,"fPort":XX,"data":"xxxx"}
352 Example: Top: application/7/device/00aedb3da649cb23/tx
353 Payload: {"confirmed":true,"fPort":2,"data":"AwEB"}
354 )))
355
356 [[image:image-20220531173519-12.png]]
357
358 **MQTT Connect to ChirpStack**
359
360
361 **If we want to send downstream hex 030101 to end node, the BASE64 payload is AwEB**
362
363 [[image:image-20220531173658-14.png]]
364
365
366 (((
367 Downlink payload encode javescript code: 可以在网站上运行以下Javsscript代码:
368 )))
369
370 (% class="box" %)
371 (((
372 function sha1_to_base64(sha1)
373 {
374 var digits="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
375 var base64_rep = "";
376 var cnt = 0;
377 var bit_arr = 0;
378 var bit_num = 0;
379 \\ for(var n = 0; n < sha1.length; ++n)
380 {
381 if(sha1[n] >= 'A' && sha1[n] <= 'Z')
382 {
383 ascv = sha1.charCodeAt( n ) - 55;
384 }
385 else if(sha1[n] >= 'a' && sha1[n] <= 'z')
386 {
387 ascv = sha1.charCodeAt( n ) - 87;
388 }
389 else
390 {
391 ascv = sha1.charCodeAt( n ) - 48;
392 }
393 \\ bit_arr = (bit_arr << 4) | ascv;
394 bit_num += 4;
395 if(bit_num >= 6)
396 {
397 bit_num -= 6;        
398 base64_rep += digits[bit_arr >>> bit_num];
399 bit_arr &= ~~(-1 << bit_num);
400 }
401 }
402 \\ if(bit_num > 0)
403 {
404 bit_arr <<= 6 - bit_num;
405 base64_rep += digits[bit_arr];
406 }
407 \\ var padding = base64_rep.length % 4;   
408 \\ if(padding > 0)
409 {
410 for(var n = 0; n < 4 - padding; ++n)
411 {
412 base64_rep += "=";
413 }
414 }
415 return base64_rep;
416 }
417 \\console.log(sha1_to_base64("data"));
418 \\data is downlink payload required by end node.
419 e.g console.log(sha1_to_base64("030101"));
420 ​result: AwEB     
421 AwEB is the 0x030101's base 64 Encode.
422 \\​e.g console.log(sha1_to_base64("030000"));
423 ​result: AwAA     
424 AwAA is 0x030000's base 64 Encode.
425 )))
426
427
428
429 == 4.3  Add the decode function in Chirpstack for the payload ==
430
431
432 User enters the payload code according to the steps.
433
434 [[image:image-20220531173754-15.png||height="474" width="1334"]]
435
436
437 [[image:image-20220531173856-16.png]]
438
439
440 [[image:image-20220531174120-20.png]]
441
442 [[image:image-20220531174046-19.png]]
443
444
445 = 6.  Multiply Uplink in ChirpStack =
446
447
448 (((
449 nbtrans field is the value to determine the re-transmission time for unconfirmed uplink data.
450 )))
451
452 (((
453 ChirpStack will auto adjust nbtrans according to uplink rssi. [[link to source>>url:https://github.com/brocaar/chirpstack-network-server/blob/master/internal/adr/adr.go]]
454
455
456 )))
457
458 [[image:image-20220526091912-7.png||height="241" width="1336"]]
459
460
461 (((
462 nbtrans is a field of ADR message, in unconfirm mode, it tells end node how many time it needs to transmit for every frame.
463
464
465 )))
466
467 [[image:image-20220525104359-21.png]]
468
469 (((
470 Above behaviour will cause the platform shows below two cases of error:
471
472
473 )))
474
475 (((
476 Error of duplicate Frame Counter
477 )))
478
479 [[image:image-20220525104437-22.png]]
480
481
482
483 **Duplicate transmission in short time**
484
485 [[image:image-20220601102430-1.png||height="598" width="1319"]]
486
487
488
489 == 6.1  Solution ==
490
491
492 This example uses the Windows version as a template, other versions can refer to this. Similiar reference: [[https:~~/~~/confluence.alitecs.de/plugins/servlet/mobile?contentId=79790102#content/view/79790102>>url:https://confluence.alitecs.de/plugins/servlet/mobile?contentId=79790102#content/view/79790102]]
493
494
495 (((
496 (% style="color:blue" %)**1.  Install the GO compilation environment: Download the corresponding version of the Go compiler at [[https:~~/~~/go.dev/dl/>>url:https://go.dev/dl/]] and install it.**
497
498
499 )))
500
501 [[image:image-20220525104532-24.png]]
502
503
504 **installation path:**
505
506 [[image:image-20220525104554-25.png]]
507
508
509
510 (((
511 (% style="color:blue" %)**2.  Environment variable settings:**
512 )))
513
514 (((
515 1) Open Computer -> Properties -> Advanced System Settings -> Environment Variables and add a "new" system variable:
516 )))
517
518 (((
519 2) Set the variable name GOROOT and the variable value C:\Go\ (installation directory)
520 )))
521
522 [[image:image-20220524165433-33.png]]
523
524
525 3) Modify the system variable Path and add C:\Go\bin\:
526
527 [[image:image-20220524165452-34.png]]
528
529
530 User variable setting file generation directory: D:\go:
531
532 [[image:image-20220524165517-35.png]]
533
534
535
536 (% style="color:blue" %)**3.  Modify the ADR configuration file according to your own needs, adr.setting.go is an example of the ADR configuration file.**
537
538 The name of the plugin: Example ADR plugin:
539
540 [[image:image-20220524165540-36.png]]
541
542 Set Nbtrans: Nbtrans=1 (Nbtrans is the number of retransmissions, if it is 1, no retransmission, it is recommended to be 1). To enable it, you need to uncomment.
543
544 [[image:image-20220524165557-37.png]]
545
546
547
548 (% style="color:blue" %)**4.  Compile the ADR configuration file and generate the exe file.**
549
550 1) Create a folder named adr-setting
551
552 2) Open the adr-setting folder
553
554 3) Put adr.setting.go in this folder.
555
556 4) Open the computer cmd and run the following commands in sequencecd adr-setting
557
558 go mod init adr-setting
559
560 go get github.com/brocaar/chirpstack-network-server/v3/adr
561
562 go get github.com/hashicorp/go-plugin
563
564 go get adr-setting
565
566 go build
567
568 5) Finally generate this file:
569
570 [[image:image-20220524165623-38.png]]
571
572
573
574 (% style="color:blue" %)**5.  Add the plugin and run the plugin.**
575
576 (((
577 The exe file generated in the previous step is placed in the same root directory as chirpstack-network-server.toml, and the ADR plugin is added to the toml file. The location of the addition is as follows:
578 )))
579
580 [[image:image-20220524165641-39.png]]
581
582 (((
583 (((
584 For example: adr_plugins=[“adr-setting”]
585 )))
586 )))
587
588 * (((
589 (((
590 Adding a single plugin format is adr_plugins=["filename"]
591 )))
592 )))
593
594 * (((
595 (((
596 Adding multiple plugins The format is adr_plugins=["file name 1", "file name 2",...]
597 )))
598 )))
599
600 (((
601 (((
602 Finally, re-run chirpstack-network-server.exe, and then select the plugin you just compiled in Device-profiles,
603 )))
604 )))
605
606 [[image:image-20220525104647-26.png]]
607
608 Finish.
609
610
611 = 7.  How to store/get all data traffic for a specific sensor, including raw payload, and uplink/ downlink history. =
612
613
614 All data is published to the MQTT topics. if you want to store/get the data, you would have to create an MQTT handler and store the data yourself.
615
616 This example will be shown how to store/get all the data in two ways:
617
618 **//1). Chirpstack ~-~-> Node-red//**
619
620
621 [[image:image-20221012184501-1.png]]
622
623
624 Use MQTT in Nore-red to subscribe to topics published by the chirpstack-application and then continuously write to a file
625
626 [[image:image-20221012174220-2.png]]
627
628
629 [[image:image-20221012184655-3.png||height="395" width="1049"]]
630
631
632 **Each message is continuously logged to a specified file**
633
634 [[image:image-20221012174352-3.png]]
635
636
637 **//2). MQTT  Sub//**
638
639 If you don't want to store the information via node-red, you can get the output via the subscribe command.
640
641
642 **If connecting from the same machine, you can use the following command to receive data:**
643
644 (% class="box infomessage" %)
645 (((
646 mosquitto_sub -h localhost -t "application/#" -v
647 )))
648
649
650 **Different host**
651
652 (% class="box infomessage" %)
653 (((
654 mosquitto_sub -h IPADDRESS -p 8883 ~-~-insecure ~-~-cafile ca.pem ~-~-cert cert.pem ~-~-key key.pem -t "application/#" -v
655 )))
656
657 [[image:image-20221012173639-1.png]]
658
659
660 = 8.  Trouble Shooting =
661
662 == 8.1  MIC Mismatch or MIC Failed ==
663
664
665 (((
666 When the device is registered or the device is working normally, the problem of MIC mismatch and MIC failed occurs.
667 )))
668
669 (((
670 Under normal circumstances, users need to change the APPKEY to solve this problem.
671 )))