LoRaWAN 01b: Configure module US or AU
This example shows how to configure the module and all general settings related to back-end registration process for LoRaWAN US and LoRaWAN AU modules

Required Materials

1 x Waspmote 1 x Battery 1 x LoRaWAN US or LoRaWAN AU module 1 x 900 MHz Antenna

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) 2017 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.1
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
//////////////////////////////////////////////
56
// 1. switch on
57
//////////////////////////////////////////////
58
59
error = LoRaWAN.ON(socket);
60
61
// Check status
62
if( error == 0 )
63
{
64
USB.println(F("1. Switch ON OK"));
65
}
66
else
67
{
68
USB.print(F("1. Switch ON error = "));
69
USB.println(error, DEC);
70
}
71
72
73
//////////////////////////////////////////////
74
// 2. Reset to factory default values
75
//////////////////////////////////////////////
76
77
error = LoRaWAN.factoryReset();
78
79
// Check status
80
if( error == 0 )
81
{
82
USB.println(F("2. Reset to factory default values OK"));
83
}
84
else
85
{
86
USB.print(F("2. Reset to factory error = "));
87
USB.println(error, DEC);
88
}
89
90
91
//////////////////////////////////////////////
92
// 3. Set/Get Device EUI
93
//////////////////////////////////////////////
94
95
// Set Device EUI
96
error = LoRaWAN.setDeviceEUI(DEVICE_EUI);
97
98
// Check status
99
if( error == 0 )
100
{
101
USB.println(F("3.1. Set Device EUI OK"));
102
}
103
else
104
{
105
USB.print(F("3.1. Set Device EUI error = "));
106
USB.println(error, DEC);
107
}
108
109
// Get Device EUI
110
error = LoRaWAN.getDeviceEUI();
111
112
// Check status
113
if( error == 0 )
114
{
115
USB.print(F("3.2. Get Device EUI OK. "));
116
USB.print(F("Device EUI: "));
117
USB.println(LoRaWAN._devEUI);
118
}
119
else
120
{
121
USB.print(F("3.2. Get Device EUI error = "));
122
USB.println(error, DEC);
123
}
124
125
126
//////////////////////////////////////////////
127
// 4. Set/Get Device Address
128
//////////////////////////////////////////////
129
130
// Set Device Address
131
error = LoRaWAN.setDeviceAddr(DEVICE_ADDR);
132
133
// Check status
134
if( error == 0 )
135
{
136
USB.println(F("4.1. Set Device address OK"));
137
}
138
else
139
{
140
USB.print(F("4.1. Set Device address error = "));
141
USB.println(error, DEC);
142
}
143
144
// Get Device Address
145
error = LoRaWAN.getDeviceAddr();
146
147
// Check status
148
if( error == 0 )
149
{
150
USB.print(F("4.2. Get Device address OK. "));
151
USB.print(F("Device address: "));
152
USB.println(LoRaWAN._devAddr);
153
}
154
else
155
{
156
USB.print(F("4.2. Get Device address error = "));
157
USB.println(error, DEC);
158
}
159
160
161
//////////////////////////////////////////////
162
// 5. Set Network Session Key
163
//////////////////////////////////////////////
164
165
error = LoRaWAN.setNwkSessionKey(NWK_SESSION_KEY);
166
167
// Check status
168
if( error == 0 )
169
{
170
USB.println(F("5. Set Network Session Key OK"));
171
}
172
else
173
{
174
USB.print(F("5. Set Network Session Key error = "));
175
USB.println(error, DEC);
176
}
177
178
179
//////////////////////////////////////////////
180
// 6. Set Application Session Key
181
//////////////////////////////////////////////
182
183
error = LoRaWAN.setAppSessionKey(APP_SESSION_KEY);
184
185
// Check status
186
if( error == 0 )
187
{
188
USB.println(F("6. Set Application Session Key OK"));
189
}
190
else
191
{
192
USB.print(F("6. Set Application Session Key error = "));
193
USB.println(error, DEC);
194
}
195
196
197
//////////////////////////////////////////////
198
// 7. Set retransmissions for uplink confirmed packet
199
//////////////////////////////////////////////
200
201
// set retries
202
error = LoRaWAN.setRetries(7);
203
204
// Check status
205
if( error == 0 )
206
{
207
USB.println(F("7.1. Set Retransmissions for uplink confirmed packet OK"));
208
}
209
else
210
{
211
USB.print(F("7.1. Set Retransmissions for uplink confirmed packet error = "));
212
USB.println(error, DEC);
213
}
214
215
// Get retries
216
error = LoRaWAN.getRetries();
217
218
// Check status
219
if( error == 0 )
220
{
221
USB.print(F("7.2. Get Retransmissions for uplink confirmed packet OK. "));
222
USB.print(F("TX retries: "));
223
USB.println(LoRaWAN._retries, DEC);
224
}
225
else
226
{
227
USB.print(F("7.2. Get Retransmissions for uplink confirmed packet error = "));
228
USB.println(error, DEC);
229
}
230
231
232
//////////////////////////////////////////////
233
// 8. Set application key
234
//////////////////////////////////////////////
235
236
error = LoRaWAN.setAppKey(APP_KEY);
237
238
// Check status
239
if( error == 0 )
240
{
241
USB.println(F("8. Application key set OK"));
242
}
243
else
244
{
245
USB.print(F("8. Application key set error = "));
246
USB.println(error, DEC);
247
}
248
249
//////////////////////////////////////////////
250
// 9. For 900MHz US bands with gateways limited
251
// to 8 channels, disable the unavailable channels
252
//////////////////////////////////////////////
253
254
for (int ch = 8; ch <= 64; ch++)
255
{
256
error = LoRaWAN.setChannelStatus(ch, "off");
257
258
// Check status
259
if( error == 0 )
260
{
261
USB.println(F("9. Channel status set OK"));
262
}
263
else
264
{
265
USB.print(F("9. Channel status set error = "));
266
USB.println(error, DEC);
267
}
268
}
269
270
271
//////////////////////////////////////////////
272
// 10. Set Adaptive Data Rate
273
//////////////////////////////////////////////
274
275
// set ADR
276
error = LoRaWAN.setADR("on");
277
278
// Check status
279
if( error == 0 )
280
{
281
USB.println(F("10.1. Set Adaptive data rate status to on OK"));
282
}
283
else
284
{
285
USB.print(F("10.1. Set Adaptive data rate status to on error = "));
286
USB.println(error, DEC);
287
}
288
289
// Get ADR
290
error = LoRaWAN.getADR();
291
292
// Check status
293
if( error == 0 )
294
{
295
USB.print(F("10.2. Get Adaptive data rate status OK. "));
296
USB.print(F("Adaptive data rate status: "));
297
if (LoRaWAN._adr == true)
298
{
299
USB.println("on");
300
}
301
else
302
{
303
USB.println("off");
304
}
305
}
306
else
307
{
308
USB.print(F("10.2. Get Adaptive data rate status error = "));
309
USB.println(error, DEC);
310
}
311
312
313
//////////////////////////////////////////////
314
// 11. Set Automatic Reply
315
//////////////////////////////////////////////
316
317
// set AR
318
error = LoRaWAN.setAR("on");
319
320
// Check status
321
if( error == 0 )
322
{
323
USB.println(F("11.1. Set automatic reply status to on OK"));
324
}
325
else
326
{
327
USB.print(F("11.1. Set automatic reply status to on error = "));
328
USB.println(error, DEC);
329
}
330
331
// Get AR
332
error = LoRaWAN.getAR();
333
334
// Check status
335
if( error == 0 )
336
{
337
USB.print(F("11.2. Get automatic reply status OK. "));
338
USB.print(F("Automatic reply status: "));
339
if (LoRaWAN._ar == true)
340
{
341
USB.println("on");
342
}
343
else
344
{
345
USB.println("off");
346
}
347
}
348
else
349
{
350
USB.print(F("11.2. Get automatic reply status error = "));
351
USB.println(error, DEC);
352
}
353
354
//////////////////////////////////////////////
355
// 12. Save configuration
356
//////////////////////////////////////////////
357
358
error = LoRaWAN.saveConfig();
359
360
// Check status
361
if( error == 0 )
362
{
363
USB.println(F("12. Save configuration OK"));
364
}
365
else
366
{
367
USB.print(F("12. Save configuration error = "));
368
USB.println(error, DEC);
369
}
370
}
371
372
373
void loop()
374
{
375
// do nothing
376
}
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. Channel status set OK
15
9. Channel status set OK
16
9. Channel status set OK
17
9. Channel status set OK
18
9. Channel status set OK
19
9. Channel status set OK
20
9. Channel status set OK
21
9. Channel status set OK
22
9. Channel status set OK
23
9. Channel status set OK
24
9. Channel status set OK
25
9. Channel status set OK
26
9. Channel status set OK
27
9. Channel status set OK
28
9. Channel status set OK
29
9. Channel status set OK
30
9. Channel status set OK
31
9. Channel status set OK
32
9. Channel status set OK
33
9. Channel status set OK
34
9. Channel status set OK
35
9. Channel status set OK
36
9. Channel status set OK
37
9. Channel status set OK
38
9. Channel status set OK
39
9. Channel status set OK
40
9. Channel status set OK
41
9. Channel status set OK
42
9. Channel status set OK
43
9. Channel status set OK
44
9. Channel status set OK
45
9. Channel status set OK
46
9. Channel status set OK
47
9. Channel status set OK
48
9. Channel status set OK
49
9. Channel status set OK
50
9. Channel status set OK
51
9. Channel status set OK
52
9. Channel status set OK
53
9. Channel status set OK
54
9. Channel status set OK
55
9. Channel status set OK
56
9. Channel status set OK
57
9. Channel status set OK
58
9. Channel status set OK
59
9. Channel status set OK
60
9. Channel status set OK
61
9. Channel status set OK
62
9. Channel status set OK
63
9. Channel status set OK
64
9. Channel status set OK
65
9. Channel status set OK
66
9. Channel status set OK
67
9. Channel status set OK
68
9. Channel status set OK
69
9. Channel status set OK
70
9. Channel status set OK
71
10. Save configuration OK
Copied!
Last modified 1yr ago