Wiki source code of Notes for ChirpStack

Version 1.4 by Xiaoling on 2022/05/16 11:44

Show last authors
1 **Contents:**
2
3 {{toc/}}
4
5 = 1. Introduction =
6
7 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/]]
8
9 The dragino gateway can connect the ChirpStack server via Semtech UDP or Semtech Basic Station.
10
11 **Prerequisite**
12
13 1) Have a Chirstack Server.
14
15 [[image:https://wiki.dragino.com/images/thumb/f/f4/ChirpStack_home_page.png/600px-ChirpStack_home_page.png||height="320" width="600"]]
16
17 ChirpStack home page
18
19 2) Gateway model support
20
21 (% class="box" %)
22 (((
23 Semtech UDP : **All Model**
24 Basic Station : , , 
25 **Note** : the firmware needs >  if use the Bais station
26 )))
27
28 = 2. Semtech UDP =
29
30 == 2.1 Step 1. Add the Network-servers ==
31
32 The network-Servers address varies depending on the ChirpStack server setup environment
33
34 (% class="box" %)
35 (((
36 Windows       ~-~->Network-server server * : localhost:8000
37 Linux         ~-~->Network-server server * : chirpstack-network-server:8000
38 )))
39
40 If the user cannot add network-Servers, re-check the ChirpStack code or the server building process.
41
42 [[image:https://wiki.dragino.com/images/thumb/6/6b/Add_the_Network-servers.png/600px-Add_the_Network-servers.png||height="363" width="600"]]
43
44 Add the Network-servers
45
46 == 2.2 Step 2. Create Gateway-profiles ==
47
48 [[image:https://wiki.dragino.com/images/thumb/a/a9/Create_Gateway-profiles.png/600px-Create_Gateway-profiles.png||height="363" width="600"]]
49
50 Create Gateway-profiles
51
52 == 2.3 Step 3. Create Service-profiles ==
53
54 [[image:https://wiki.dragino.com/images/thumb/1/1f/Create_Service-profiles.png/600px-Create_Service-profiles.png||height="363" width="600"]]
55
56 Create Service-profiles
57
58 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.
59
60 (% style="color:red" %)**Note : Before add the gateway, the user needs to complete the preceding three steps.**
61
62 If the user has completed the preceding steps, proceed to the next step.
63
64 == 2.4 Step 4. Add the gateway ==
65
66 The example gateway id is: a840411e96744150
67
68 (% style="color:red" %)**Note : The Gateway EUI and server addresses must match the ChirpStack configuration.**
69
70 [[image:https://wiki.dragino.com/images/thumb/c/c6/Add_the_gateway.png/600px-Add_the_gateway.png||height="363" width="600"]]
71
72 Add the gateway
73
74 [[image:https://wiki.dragino.com/images/thumb/1/14/ChirpStack_Configure_the_gateway.png/600px-ChirpStack_Configure_the_gateway.png||height="304" width="600"]]
75
76 Configure the gateway
77
78 == 2.5 Step 5. Checking gateway Status ==
79
80 [[image:https://wiki.dragino.com/images/thumb/2/2c/Gateway_Status_cao_1.png/600px-Gateway_Status_cao_1.png||height="363" width="600"]]
81
82 gateway Status
83
84 [[image:https://wiki.dragino.com/images/thumb/1/11/Gateway_Status_cao_2.png/600px-Gateway_Status_cao_2.png||height="363" width="600"]]
85
86 gateway Status
87
88 = 3. Semtech Basic Station =
89
90 = 4. Downlink =
91
92 == 4.1 Chirpstack Downlink Note ==
93
94 [[image:https://wiki.dragino.com/images/thumb/b/ba/ChirpStack_Down_5.png/600px-ChirpStack_Down_5.png||height="293" width="600"]]
95
96 Convert the data to Base64
97
98 [[image:https://wiki.dragino.com/images/thumb/2/2c/ChirpStack_Down_6.png/600px-ChirpStack_Down_6.png||height="300" width="600"]]
99
100 Check ChripStack downlink DataRate
101
102 [[image:https://wiki.dragino.com/images/thumb/d/dc/ChirpStack_Down_7.png/600px-ChirpStack_Down_7.png||height="711" width="600"]]
103
104 Make sure the RX2DR is the same in the end node
105
106 == 4.2 Loraserver Downlink Note ==
107
108 User can use MQTT to send downlink payload to ChirpStack to perform downstream to LoRaWAN End
109
110 Below is examples:
111
112 (% class="box" %)
113 (((
114 Connect to your server via MQTT:
115 MQTT Client ID: Any   
116 Protocol:mqtt/tcp   Server IP:loraserver_ip:1883
117 User name: User name Password: password
118 )))
119
120 [[image:https://wiki.dragino.com/images/thumb/0/06/ChirpStack_Down_1.png/600px-ChirpStack_Down_1.png||height="578" width="600"]]
121
122 MQTT Connect to ChirpStack
123
124 After connect
125
126 (% class="box" %)
127 (((
128 Subscribe : Format:application/ID/device/ Device EUI/rx
129 Example: application/7/device/00aedb3da649cb23/rx
130 )))
131
132 (% class="box" %)
133 (((
134 Publish:
135 Format: Top: application/ID/device/ Device EUI/tx
136 Payload: {"confirmed":true or false,"fPort":XX,"data":"xxxx"}
137 Example: Top: application/7/device/00aedb3da649cb23/tx
138 Payload: {"confirmed":true,"fPort":2,"data":"AwEB"}
139 )))
140
141 [[image:https://wiki.dragino.com/images/thumb/c/c8/ChirpStack_Down_2.png/600px-ChirpStack_Down_2.png||height="342" width="600"]]
142
143 MQTT Connect to ChirpStack
144
145 (((
146 (% style="color:red" %)Note: Chirpstack use base64 to downlink, so need to convert the downlink payload from HEX to base64 [[https:~~/~~/base64.us/>>url:https://base64.us/]]
147 )))
148
149 [[image:https://wiki.dragino.com/images/thumb/f/f8/ChirpStack_Down_3.png/600px-ChirpStack_Down_3.png||height="309" width="600"]]
150
151 Choose to Use Hex for Encode
152
153 If we want send downstream hex 030101 to end node, the BASE64 payload is AwEB
154
155 [[image:https://wiki.dragino.com/images/thumb/d/d2/ChirpStack_Down_4.png/600px-ChirpStack_Down_4.png||alt="ChirpStack Down 4.png" height="344" width="600"]]
156
157 Downlink payload encode javescript code: 可以在网站上运行以下Javsscript代码:
158
159 (% class="box" %)
160 (((
161 function sha1_to_base64(sha1)
162 {
163 var digits="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
164 var base64_rep = "";
165 var cnt = 0;
166 var bit_arr = 0;
167 var bit_num = 0;
168
169 for(var n = 0; n < sha1.length; ++n)
170 {
171 if(sha1[n] >= 'A' && sha1[n] <= 'Z')
172 {
173 ascv = sha1.charCodeAt(n) - 55;
174 }
175 else if(sha1[n] >= 'a' && sha1[n] <= 'z')
176 {
177 ascv = sha1.charCodeAt(n) - 87;
178 }
179 else
180 {
181 ascv = sha1.charCodeAt(n) - 48;
182 }
183
184 bit_arr = (bit_arr << 4) | ascv;
185 bit_num += 4;
186 if(bit_num >= 6)
187 {
188 bit_num -= 6;        
189 base64_rep += digits[bit_arr >>> bit_num];
190 bit_arr &= ~~(-1 << bit_num);
191 }
192 }
193
194 if(bit_num > 0)
195 {
196 bit_arr <<= 6 - bit_num;
197 base64_rep += digits[bit_arr];
198 }
199
200 var padding = base64_rep.length % 4;   
201
202 if(padding > 0)
203 {
204 for(var n = 0; n < 4 - padding; ++n)
205 {
206 base64_rep += "=";
207 }
208 }
209 return base64_rep;
210 }
211
212 console.log(sha1_to_base64("data"));
213
214 data is downlink payload required by end node.
215 e.g console.log(sha1_to_base64("030101"));
216 ​result: AwEB     
217 AwEB is the 0x030101's base 64 Encode.
218
219 ​e.g console.log(sha1_to_base64("030000"));
220 ​result: AwAA     
221 AwAA is 0x030000's base 64 Encode.
222 )))
223
224 == 4.3 Add the decode function in Chirpstack for the payload ==
225
226 User enters the payload code according to the steps.
227
228 [[image:https://wiki.dragino.com/images/thumb/9/9f/Step2.png/600px-Step2.png||alt="Step2.png" height="224" width="600"]]
229
230 [[image:https://wiki.dragino.com/images/thumb/0/08/Step3.png/600px-Step3.png||alt="Step3.png" height="289" width="600"]]
231
232 [[image:https://wiki.dragino.com/images/thumb/8/83/Step6.png/600px-Step6.png||alt="Step6.png" height="259" width="600"]]
233
234 [[image:https://wiki.dragino.com/images/thumb/4/4f/Step5.png/600px-Step5.png||alt="Step5.png" height="221" width="600"]]
235
236 = 5. Multiply Uplink in ChirpStack =
237
238 (((
239 nbtrans field is the value to determine the re-transmission time for unconfirmed uplink data.
240 )))
241
242 (((
243 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]]
244 )))
245
246 [[image:https://wiki.dragino.com/images/thumb/6/63/Nbtrans_1.png/600px-Nbtrans_1.png||alt="Nbtrans 1.png" height="103" width="600"]]
247
248 nbtrans is a field of ADR message, in unconfirm mode, it tells end node how many time it needs to transmit for every frame.
249
250 [[image:https://wiki.dragino.com/images/thumb/1/17/Nbtrans_2.png/300px-Nbtrans_2.png||alt="Nbtrans 2.png" height="462" width="300"]]
251
252 (((
253 Above behaviour will cause the platform shows below two cases of error:
254 )))
255
256 (((
257 Error of duplicate Frame Counter
258 )))
259
260 [[image:https://wiki.dragino.com/images/7/7e/Nbtrans_3.png||alt="Nbtrans 3.png" height="677" width="600"]]
261
262 Duplicate transmission in short time
263
264 [[image:https://wiki.dragino.com/images/thumb/c/c4/Nbtrans_4.png/600px-Nbtrans_4.png||alt="Nbtrans 4.png" height="301" width="600"]]
265
266 == 5.1 Solution ==
267
268 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]]
269
270 ~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.
271
272 [[image:https://wiki.dragino.com/images/3/37/Chirpstacksolution-1.png||alt="Chirpstacksolution-1.png" height="199" width="554"]]
273
274 installation path:
275
276 [[image:https://wiki.dragino.com/images/c/ca/Chirpstacksolution-2.png||alt="Chirpstacksolution-2.png" height="283" width="361"]]
277
278 2. Environment variable settings:.
279
280 1) Open Computer -> Properties -> Advanced System Settings -> Environment Variables and add a "new" system variable:
281
282 2)Set the variable name GOROOT and the variable value C:\Go\ (installation directory)
283
284 [[image:https://wiki.dragino.com/images/f/f9/Chirpstacksolution-3.png||alt="Chirpstacksolution-3.png" height="152" width="554"]]
285
286 3)Modify the system variable Path and add C:\Go\bin\:
287
288 [[image:https://wiki.dragino.com/images/1/1b/Chirpstacksolution-4.png||alt="Chirpstacksolution-4.png" height="152" width="554"]]
289
290 User variable setting file generation directory: D:\go:
291
292 [[image:https://wiki.dragino.com/images/9/9b/Chirpstacksolution-5.png||alt="Chirpstacksolution-5.png" height="278" width="371"]]
293
294 3. Modify the ADR configuration file according to your own needs, adr.setting.go is an example of the ADR configuration file.
295
296 The name of the plugin: Example ADR plugin:
297
298 [[image:https://wiki.dragino.com/images/1/12/Chirpstacksolution-6.jpg||alt="Chirpstacksolution-6.jpg" height="89" width="554"]]
299
300 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.
301
302 [[image:https://wiki.dragino.com/images/2/25/Chirpstacksolution-7.png||alt="Chirpstacksolution-7.png" height="98" width="426"]]
303
304 4. Compile the ADR configuration file and generate the exe file.
305
306 1) Create a folder named adr-setting
307
308 2) Open the adr-setting folder
309
310 3) Put adr.setting.go in this folder.
311
312 4) Open the computer cmd and run the following commands in sequencecd adr-setting
313
314 go mod init adr-setting
315
316 go get github.com/brocaar/chirpstack-network-server/v3/adr
317
318 go get github.com/hashicorp/go-plugin
319
320 go get adr-setting
321
322 go build
323
324 5) Finally generate this file:
325
326 [[image:https://wiki.dragino.com/images/6/66/Chirpstacksolution-8.png||alt="Chirpstacksolution-8.png" height="96" width="554"]]
327
328 5. Add the plugin and run the plugin.
329
330 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:
331
332 [[image:https://wiki.dragino.com/images/8/82/Chirpstacksolution-9.png||alt="Chirpstacksolution-9.png" height="73" width="554"]]
333
334 (((
335 For example: adr_plugins=[“adr-setting”]
336 )))
337
338 * (((
339 Adding a single plugin format is adr_plugins=["filename"]
340 )))
341
342 * (((
343 Adding multiple plugins The format is adr_plugins=["file name 1", "file name 2",...]
344 )))
345
346 (((
347 Finally, re-run chirpstack-network-server.exe, and then select the plugin you just compiled in Device-profiles,
348 )))
349
350 [[image:https://wiki.dragino.com/images/3/39/Chirpstacksolution-10.png||alt="Chirpstacksolution-10.png" height="275" width="554"]]
351
352 Finish.
353
354 = 6. Trouble Shooting =
355
356 == 6.1 MIC Mismatch or MIC Failed ==
357
358 (((
359 When the device is registered or the device is working normally, the problem of MIC mismatch and MIC failed occurs.
360 )))
361
362 (((
363 Under normal circumstances, users need to change the APPKEY to solve this problem.
364 )))