Wiki source code of Notes for ChirpStack

Version 1.2 by Xiaoling on 2022/05/16 11:21

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