LoRaWAN 01a: Configure module EU IN ASIA-PAC / LATAM
This example shows how to configure the module and all general settings related to back-end registration process.

Required Materials

1 x Waspmote 1 x Battery 1 x LoRaWAN EU or LoRaWAN IN or LoRaWAN ASIA-PAC / LATAM module 1 x 868 MHz Antenna (for EU and IN modules) or 900 MHz Antenna (for ASIA-PAC / LATAM module)

Notes

- This example can be executed in Waspmote v12 and Waspmote v15

Code

1
/*
2
* ------ LoRaWAN Code Example --------
3
*
4
* Explanation: This example shows how to configure the module
5
* and all general settings related to back-end registration
6
* process.
7
*
8
* Copyright (C) 2018 Libelium Comunicaciones Distribuidas S.L.
9
* http://www.libelium.com
10
*
11
* This program is free software: you can redistribute it and/or modify
12
* it under the terms of the GNU General Public License as published by
13
* the Free Software Foundation, either version 3 of the License, or
14
* (at your option) any later version.
15
*
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
20
*
21
* You should have received a copy of the GNU General Public License
22
* along with this program. If not, see .
23
*
24
* Version: 3.4
25
* Design: David Gascon
26
* Implementation: Luismi Marti
27
*/
28
29
#include <WaspLoRaWAN.h>
30
31
//////////////////////////////////////////////
32
uint8_t socket = SOCKET0;
33
//////////////////////////////////////////////
34
35
// Device parameters for Back-End registration
36
////////////////////////////////////////////////////////////
37
char DEVICE_EUI[] = "0102030405060708";
38
char DEVICE_ADDR[] = "05060708";
39
char NWK_SESSION_KEY[] = "01020304050607080910111213141516";
40
char APP_SESSION_KEY[] = "000102030405060708090A0B0C0D0E0F";
41
char APP_KEY[] = "000102030405060708090A0B0C0D0E0F";
42
////////////////////////////////////////////////////////////
43
44
// variable
45
uint8_t error;
46
47
48
49
void setup()
50
{
51
USB.ON();
52
USB.println(F("LoRaWAN example - Module configuration"));
53
54
55
USB.println(F(" _____________________________________________________"));
56
USB.println(F("| |"));
57
USB.println(F("| It is not mandatory to configure channel parameters.|"));
58
USB.println(F("| Server should configure the module during the |"));
59
USB.println(F("| Over The Air Activation process. |"));
60
USB.println(F("|_____________________________________________________|"));
61
USB.println();
62
63
//////////////////////////////////////////////
64
// 1. switch on
65
//////////////////////////////////////////////
66
67
error = LoRaWAN.ON(socket);
68
69
// Check status
70
if( error == 0 )
71
{
72
USB.println(F("1. Switch ON OK"));
73
}
74
else
75
{
76
USB.print(F("1. Switch ON error = "));
77
USB.println(error, DEC);
78
}
79
80
81
//////////////////////////////////////////////
82
// 2. Reset to factory default values
83
//////////////////////////////////////////////
84
85
error = LoRaWAN.factoryReset();
86
87
// Check status
88
if( error == 0 )
89
{
90
USB.println(F("2. Reset to factory default values OK"));
91
}
92
else
93
{
94
USB.print(F("2. Reset to factory error = "));
95
USB.println(error, DEC);
96
}
97
98
99
//////////////////////////////////////////////
100
// 3. Set/Get Device EUI
101
//////////////////////////////////////////////
102
103
// Set Device EUI
104
error = LoRaWAN.setDeviceEUI(DEVICE_EUI);
105
106
// Check status
107
if( error == 0 )
108
{
109
USB.println(F("3.1. Set Device EUI OK"));
110
}
111
else
112
{
113
USB.print(F("3.1. Set Device EUI error = "));
114
USB.println(error, DEC);
115
}
116
117
// Get Device EUI
118
error = LoRaWAN.getDeviceEUI();
119
120
// Check status
121
if( error == 0 )
122
{
123
USB.print(F("3.2. Get Device EUI OK. "));
124
USB.print(F("Device EUI: "));
125
USB.println(LoRaWAN._devEUI);
126
}
127
else
128
{
129
USB.print(F("3.2. Get Device EUI error = "));
130
USB.println(error, DEC);
131
}
132
133
134
//////////////////////////////////////////////
135
// 4. Set/Get Device Address
136
//////////////////////////////////////////////
137
138
// Set Device Address
139
error = LoRaWAN.setDeviceAddr(DEVICE_ADDR);
140
141
// Check status
142
if( error == 0 )
143
{
144
USB.println(F("4.1. Set Device address OK"));
145
}
146
else
147
{
148
USB.print(F("4.1. Set Device address error = "));
149
USB.println(error, DEC);
150
}
151
152
// Get Device Address
153
error = LoRaWAN.getDeviceAddr();
154
155
// Check status
156
if( error == 0 )
157
{
158
USB.print(F("4.2. Get Device address OK. "));
159
USB.print(F("Device address: "));
160
USB.println(LoRaWAN._devAddr);
161
}
162
else
163
{
164
USB.print(F("4.2. Get Device address error = "));
165
USB.println(error, DEC);
166
}
167
168
169
//////////////////////////////////////////////
170
// 5. Set Network Session Key
171
//////////////////////////////////////////////
172
173
error = LoRaWAN.setNwkSessionKey(NWK_SESSION_KEY);
174
175
// Check status
176
if( error == 0 )
177
{
178
USB.println(F("5. Set Network Session Key OK"));
179
}
180
else
181
{
182
USB.print(F("5. Set Network Session Key error = "));
183
USB.println(error, DEC);
184
}
185
186
187
//////////////////////////////////////////////
188
// 6. Set Application Session Key
189
//////////////////////////////////////////////
190
191
error = LoRaWAN.setAppSessionKey(APP_SESSION_KEY);
192
193
// Check status
194
if( error == 0 )
195
{
196
USB.println(F("6. Set Application Session Key OK"));
197
}
198
else
199
{
200
USB.print(F("6. Set Application Session Key error = "));
201
USB.println(error, DEC);
202
}
203
204
205
//////////////////////////////////////////////
206
// 7. Set retransmissions for uplink confirmed packet
207
//////////////////////////////////////////////
208
209
// set retries
210
error = LoRaWAN.setRetries(7);
211
212
// Check status
213
if( error == 0 )
214
{
215
USB.println(F("7.1. Set Retransmissions for uplink confirmed packet OK"));
216
}
217
else
218
{
219
USB.print(F("7.1. Set Retransmissions for uplink confirmed packet error = "));
220
USB.println(error, DEC);
221
}
222
223
// Get retries
224
error = LoRaWAN.getRetries();
225
226
// Check status
227
if( error == 0 )
228
{
229
USB.print(F("7.2. Get Retransmissions for uplink confirmed packet OK. "));
230
USB.print(F("TX retries: "));
231
USB.println(LoRaWAN._retries, DEC);
232
}
233
else
234
{
235
USB.print(F("7.2. Get Retransmissions for uplink confirmed packet error = "));
236
USB.println(error, DEC);
237
}
238
239
240
//////////////////////////////////////////////
241
// 8. Set application key
242
//////////////////////////////////////////////
243
244
error = LoRaWAN.setAppKey(APP_KEY);
245
246
// Check status
247
if( error == 0 )
248
{
249
USB.println(F("8. Application key set OK"));
250
}
251
else
252
{
253
USB.print(F("8. Application key set error = "));
254
USB.println(error, DEC);
255
}
256
257
258
////////////////////////////////////////////////////////
259
// ______________________________________________________
260
// | |
261
// | It is not mandatory to configure channel parameters.|
262
// | Server should configure the module during the |
263
// | Over The Air Activation process. If channels aren't |
264
// | configured, please uncomment channel configuration |
265
// | functions below these lines. |
266
// |______________________________________________________|
267
//
268
////////////////////////////////////////////////////////
269
270
//////////////////////////////////////////////
271
// 9. Channel configuration. (Recommended)
272
// Consult your Network Operator and Backend Provider
273
//////////////////////////////////////////////
274
275
/////////////////////////////
276
// EU module
277
/////////////////////////////
278
// Set channel 3 -> 867.1 MHz
279
// Set channel 4 -> 867.3 MHz
280
// Set channel 5 -> 867.5 MHz
281
// Set channel 6 -> 867.7 MHz
282
// Set channel 7 -> 867.9 MHz
283
/////////////////////////////
284
// ASIA-PAC / LATAM module
285
/////////////////////////////
286
// Set channel 2 -> 923.6 MHz
287
// Set channel 3 -> 923.8 MHz
288
// Set channel 4 -> 924.0 MHz
289
// Set channel 5 -> 924.2 MHz
290
// Set channel 6 -> 924.4 MHz
291
/////////////////////////////
292
293
// uint32_t freq = 867100000;
294
//
295
// for (uint8_t ch = 3; ch <= 7; ch++)
296
// {
297
// error = LoRaWAN.setChannelFreq(ch, freq);
298
// freq += 200000;
299
//
300
// // Check status
301
// if( error == 0 )
302
// {
303
// USB.println(F("9. Frequency channel set OK"));
304
// }
305
// else
306
// {
307
// USB.print(F("9. Frequency channel set error = "));
308
// USB.println(error, DEC);
309
// }
310
//
311
//
312
// }
313
314
315
316
//////////////////////////////////////////////
317
// 10. Set Duty Cycle for specific channel. (Recommended)
318
// Consult your Network Operator and Backend Provider
319
//////////////////////////////////////////////
320
321
// for (uint8_t ch = 0; ch <= 2; ch++)
322
// {
323
// error = LoRaWAN.setChannelDutyCycle(ch, 33333);
324
//
325
// // Check status
326
// if( error == 0 )
327
// {
328
// USB.println(F("10. Duty cycle channel set OK"));
329
// }
330
// else
331
// {
332
// USB.print(F("10. Duty cycle channel set error = "));
333
// USB.println(error, DEC);
334
// }
335
// }
336
//
337
// for (uint8_t ch = 3; ch <= 7; ch++)
338
// {
339
// error = LoRaWAN.setChannelDutyCycle(ch, 40000);
340
//
341
// // Check status
342
// if( error == 0 )
343
// {
344
// USB.println(F("10. Duty cycle channel set OK"));
345
// }
346
// else
347
// {
348
// USB.print(F("10. Duty cycle channel set error = "));
349
// USB.println(error, DEC);
350
// }
351
// }
352
353
//////////////////////////////////////////////
354
// 11. Set Data Range for specific channel. (Recommended)
355
// Consult your Network Operator and Backend Provider
356
//////////////////////////////////////////////
357
358
// for (int ch = 0; ch <= 7; ch++)
359
// {
360
// error = LoRaWAN.setChannelDRRange(ch, 0, 5);
361
//
362
// // Check status
363
// if( error == 0 )
364
// {
365
// USB.println(F("11. Data rate range channel set OK"));
366
// }
367
// else
368
// {
369
// USB.print(F("11. Data rate range channel set error = "));
370
// USB.println(error, DEC);
371
// }
372
// }
373
374
375
376
//////////////////////////////////////////////
377
// 12. Set Data rate range for specific channel. (Recommended)
378
// Consult your Network Operator and Backend Provider
379
//////////////////////////////////////////////
380
381
// for (int ch = 0; ch <= 7; ch++)
382
// {
383
// error = LoRaWAN.setChannelStatus(ch, "on");
384
//
385
// // Check status
386
// if( error == 0 )
387
// {
388
// USB.println(F("12. Channel status set OK"));
389
// }
390
// else
391
// {
392
// USB.print(F("12. Channel status set error = "));
393
// USB.println(error, DEC);
394
// }
395
// }
396
397
398
//////////////////////////////////////////////
399
// 13. Set Adaptive Data Rate (recommended)
400
//////////////////////////////////////////////
401
402
// set ADR
403
error = LoRaWAN.setADR("on");
404
405
// Check status
406
if( error == 0 )
407
{
408
USB.println(F("13.1. Set Adaptive data rate status to on OK"));
409
}
410
else
411
{
412
USB.print(F("13.1. Set Adaptive data rate status to on error = "));
413
USB.println(error, DEC);
414
}
415
416
// Get ADR
417
error = LoRaWAN.getADR();
418
419
// Check status
420
if( error == 0 )
421
{
422
USB.print(F("13.2. Get Adaptive data rate status OK. "));
423
USB.print(F("Adaptive data rate status: "));
424
if (LoRaWAN._adr == true)
425
{
426
USB.println("on");
427
}
428
else
429
{
430
USB.println("off");
431
}
432
}
433
else
434
{
435
USB.print(F("13.2. Get Adaptive data rate status error = "));
436
USB.println(error, DEC);
437
}
438
439
440
//////////////////////////////////////////////
441
// 14. Set Automatic Reply
442
//////////////////////////////////////////////
443
444
// set AR
445
error = LoRaWAN.setAR("on");
446
447
// Check status
448
if( error == 0 )
449
{
450
USB.println(F("14.1. Set automatic reply status to on OK"));
451
}
452
else
453
{
454
USB.print(F("14.1. Set automatic reply status to on error = "));
455
USB.println(error, DEC);
456
}
457
458
// Get AR
459
error = LoRaWAN.getAR();
460
461
// Check status
462
if( error == 0 )
463
{
464
USB.print(F("14.2. Get automatic reply status OK. "));
465
USB.print(F("Automatic reply status: "));
466
if (LoRaWAN._ar == true)
467
{
468
USB.println("on");
469
}
470
else
471
{
472
USB.println("off");
473
}
474
}
475
else
476
{
477
USB.print(F("14.2. Get automatic reply status error = "));
478
USB.println(error, DEC);
479
}
480
481
482
//////////////////////////////////////////////
483
// 15. Save configuration
484
//////////////////////////////////////////////
485
486
error = LoRaWAN.saveConfig();
487
488
// Check status
489
if( error == 0 )
490
{
491
USB.println(F("15. Save configuration OK"));
492
}
493
else
494
{
495
USB.print(F("15. Save configuration error = "));
496
USB.println(error, DEC);
497
}
498
499
500
USB.println(F("------------------------------------"));
501
USB.println(F("Now the LoRaWAN module is ready for"));
502
USB.println(F("joining networks and send messages."));
503
USB.println(F("Please check the next examples..."));
504
USB.println(F("------------------------------------\n"));
505
506
}
507
508
509
void loop()
510
{
511
// do nothing
512
}
Copied!

Output

1
H#
2
LoRaWAN example - Module configuration
3
1. Switch ON OK
4
2. Reset to factory default values OK
5
3.1. Set Device EUI OK
6
3.2. Get Device EUI OK. Device EUI: 0102030405060708
7
4.1. Set Device address OK
8
4.2. Get Device address OK. Device address: 05060708
9
5. Set Network Session Key OK
10
6. Set Application Session Key OK
11
7.1. Set Retransmissions for uplink confirmed packet OK
12
7.2. Get Retransmissions for uplink confirmed packet OK. TX retries: 7
13
8. Application key set OK
14
9. Frequency channel set OK
15
9. Frequency channel set OK
16
9. Frequency channel set OK
17
9. Frequency channel set OK
18
9. Frequency channel set OK
19
10. Duty cycle channel set OK
20
10. Duty cycle channel set OK
21
10. Duty cycle channel set OK
22
10. Duty cycle channel set OK
23
10. Duty cycle channel set OK
24
10. Duty cycle channel set OK
25
10. Duty cycle channel set OK
26
10. Duty cycle channel set OK
27
11. Data rate range channel set OK
28
11. Data rate range channel set OK
29
11. Data rate range channel set OK
30
11. Data rate range channel set OK
31
11. Data rate range channel set OK
32
11. Data rate range channel set OK
33
11. Data rate range channel set OK
34
11. Data rate range channel set OK
35
12. Channel status set OK
36
12. Channel status set OK
37
12. Channel status set OK
38
12. Channel status set OK
39
12. Channel status set OK
40
12. Channel status set OK
41
12. Channel status set OK
42
12. Channel status set OK
Copied!
Last modified 1yr ago