LoRaWAN 02c: Channels JP or KR
This example shows how to configure the channels settings for LoRaWAN JP or LoRaWAN KR

Required Materials

1 x Waspmote 1 x Battery 1 x LoRaWAN JP/KR module 1 x 900 MHz antenna

Code

1
/*
2
------ LoRaWAN Code Example --------
3
4
Explanation: TThis example shows how to configure the channels settings.
5
6
Copyright (C) 2019 Libelium Comunicaciones Distribuidas S.L.
7
http://www.libelium.com
8
9
This program is free software: you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation, either version 3 of the License, or
12
(at your option) any later version.
13
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
18
19
You should have received a copy of the GNU General Public License
20
along with this program. If not, see .
21
22
Version: 3.0
23
Design: David Gascon
24
Implementation: Luismi Marti
25
*/
26
27
#include <WaspLoRaWAN.h>
28
29
//////////////////////////////////////////////
30
uint8_t socket = SOCKET0;
31
//////////////////////////////////////////////
32
33
// variable
34
uint8_t error;
35
36
/*
37
JAPAN = BAND_JP923
38
KOREA = BAND_KR920
39
*/
40
uint8_t band = BAND_JP923;
41
42
43
void setup()
44
{
45
USB.ON();
46
USB.println(F("LoRaWAN example - LoRaWAN JP/KR Channels Configuration"));
47
48
//////////////////////////////////////////////
49
// 1. switch on
50
//////////////////////////////////////////////
51
52
error = LoRaWAN.ON(socket);
53
54
// Check status
55
if ( error == 0 )
56
{
57
USB.println(F("1. Switch ON OK"));
58
}
59
else
60
{
61
USB.print(F("1. Switch ON error = "));
62
USB.println(error, DEC);
63
}
64
65
if (LoRaWAN._version != ABZ_MODULE)
66
{
67
USB.println(F("\n---------------------------------------------------------------"));
68
USB.println(F("Module version error"));
69
USB.println(F("This is not a JP/KR LoRaWAN module"));
70
USB.println(F("Please open the example 01a or 01b related to your module"));
71
USB.println(F("\n---------------------------------------------------------------"));
72
while (1);
73
}
74
75
//////////////////////////////////////////////
76
// 2. Configure region and channels
77
//////////////////////////////////////////////
78
79
// Set band
80
error = LoRaWAN.setBand(band);
81
82
// Check status
83
if ( error == 0 )
84
{
85
USB.println(F("2.1. Set band OK"));
86
}
87
else
88
{
89
USB.print(F("2.1. Set band error = "));
90
USB.println(error, DEC);
91
}
92
93
// Get band
94
error = LoRaWAN.getBand();
95
96
// Check status
97
if ( error == 0 )
98
{
99
USB.print(F("2.2. Get band OK. "));
100
USB.print(F("Band: "));
101
USB.print(LoRaWAN._bandABZ, DEC);
102
}
103
else
104
{
105
USB.print(F("2.2. Get band error = "));
106
USB.println(error, DEC);
107
}
108
109
switch (LoRaWAN._bandABZ)
110
{
111
112
case BAND_JP923:
113
//////////////////////////////////////////////
114
// 3. Configure LoRaWAN JP channels
115
//////////////////////////////////////////////
116
117
USB.println(F(" - Region is AS923 JAPAN"));
118
119
error = LoRaWAN.setChannelFreq(0, 923200000);
120
if ( error == 0 )
121
{
122
USB.print(F("3.0. Set channel frequency OK. "));
123
USB.print(F("Frequency in channel 0: "));
124
USB.println(LoRaWAN._freq[0]);
125
}
126
else
127
{
128
USB.print(F("3.0. Set channel frequency error = "));
129
USB.println(error, DEC);
130
}
131
132
error = LoRaWAN.setChannelFreq(1, 923400000);
133
if ( error == 0 )
134
{
135
USB.print(F("3.1. Set channel frequency OK. "));
136
USB.print(F("Frequency in channel 1: "));
137
USB.println(LoRaWAN._freq[1]);
138
}
139
else
140
{
141
USB.print(F("3.1. Set channel frequency error = "));
142
USB.println(error, DEC);
143
}
144
145
error = LoRaWAN.setChannelFreq(2, 923600000);
146
if ( error == 0 )
147
{
148
USB.print(F("3.2. Set channel frequency OK. "));
149
USB.print(F("Frequency in channel 2: "));
150
USB.println(LoRaWAN._freq[2]);
151
}
152
else
153
{
154
USB.print(F("3.2. Set channel frequency error = "));
155
USB.println(error, DEC);
156
}
157
158
error = LoRaWAN.setChannelFreq(3, 923800000);
159
if ( error == 0 )
160
{
161
USB.print(F("3.3. Set channel frequency OK. "));
162
USB.print(F("Frequency in channel 3: "));
163
USB.println(LoRaWAN._freq[3]);
164
}
165
else
166
{
167
USB.print(F("3.3. Set channel frequency error = "));
168
USB.println(error, DEC);
169
}
170
171
error = LoRaWAN.setChannelFreq(4, 924000000);
172
if ( error == 0 )
173
{
174
USB.print(F("3.4. Set channel frequency OK. "));
175
USB.print(F("Frequency in channel 4: "));
176
USB.println(LoRaWAN._freq[4]);
177
}
178
else
179
{
180
USB.print(F("3.4. Set channel frequency error = "));
181
USB.println(error, DEC);
182
}
183
184
error = LoRaWAN.setChannelFreq(5, 924200000);
185
if ( error == 0 )
186
{
187
USB.print(F("3.5. Set channel frequency OK. "));
188
USB.print(F("Frequency in channel 5: "));
189
USB.println(LoRaWAN._freq[5]);
190
}
191
else
192
{
193
USB.print(F("3.5. Set channel frequency error = "));
194
USB.println(error, DEC);
195
}
196
197
error = LoRaWAN.setChannelFreq(6, 924400000);
198
if ( error == 0 )
199
{
200
USB.print(F("3.6. Set channel frequency OK. "));
201
USB.print(F("Frequency in channel 6: "));
202
USB.println(LoRaWAN._freq[6]);
203
}
204
else
205
{
206
USB.print(F("3.6. Set channel frequency error = "));
207
USB.println(error, DEC);
208
}
209
210
break;
211
212
213
case BAND_KR920:
214
//////////////////////////////////////////////
215
// 3. Configure LoRaWAN KR channels
216
//////////////////////////////////////////////
217
218
USB.println(F(" - Region is KR920"));
219
220
error = LoRaWAN.setChannelFreq(0, 922100000);
221
if ( error == 0 )
222
{
223
USB.print(F("3.0. Set channel frequency OK. "));
224
USB.print(F("Frequency in channel 0: "));
225
USB.println(LoRaWAN._freq[0]);
226
}
227
else
228
{
229
USB.print(F("3.0. Set channel frequency error = "));
230
USB.println(error, DEC);
231
}
232
233
error = LoRaWAN.setChannelFreq(1, 922300000);
234
if ( error == 0 )
235
{
236
USB.print(F("3.1. Set channel frequency OK. "));
237
USB.print(F("Frequency in channel 1: "));
238
USB.println(LoRaWAN._freq[1]);
239
}
240
else
241
{
242
USB.print(F("3.1. Set channel frequency error = "));
243
USB.println(error, DEC);
244
}
245
246
error = LoRaWAN.setChannelFreq(2, 922500000);
247
if ( error == 0 )
248
{
249
USB.print(F("3.2. Set channel frequency OK. "));
250
USB.print(F("Frequency in channel 2: "));
251
USB.println(LoRaWAN._freq[2]);
252
}
253
else
254
{
255
USB.print(F("3.2. Set channel frequency error = "));
256
USB.println(error, DEC);
257
}
258
259
error = LoRaWAN.setChannelFreq(3, 921900000);
260
if ( error == 0 )
261
{
262
USB.print(F("3.3. Set channel frequency OK. "));
263
USB.print(F("Frequency in channel 3: "));
264
USB.println(LoRaWAN._freq[3]);
265
}
266
else
267
{
268
USB.print(F("3.3. Set channel frequency error = "));
269
USB.println(error, DEC);
270
}
271
272
error = LoRaWAN.setChannelFreq(4, 922700000);
273
if ( error == 0 )
274
{
275
USB.print(F("3.4. Set channel frequency OK. "));
276
USB.print(F("Frequency in channel 4: "));
277
USB.println(LoRaWAN._freq[4]);
278
}
279
else
280
{
281
USB.print(F("3.4. Set channel frequency error = "));
282
USB.println(error, DEC);
283
}
284
285
error = LoRaWAN.setChannelFreq(5, 922900000);
286
if ( error == 0 )
287
{
288
USB.print(F("3.5. Set channel frequency OK. "));
289
USB.print(F("Frequency in channel 5: "));
290
USB.println(LoRaWAN._freq[5]);
291
}
292
else
293
{
294
USB.print(F("3.5. Set channel frequency error = "));
295
USB.println(error, DEC);
296
}
297
298
error = LoRaWAN.setChannelFreq(6, 923100000);
299
if ( error == 0 )
300
{
301
USB.print(F("3.6. Set channel frequency OK. "));
302
USB.print(F("Frequency in channel 6: "));
303
USB.println(LoRaWAN._freq[6]);
304
}
305
else
306
{
307
USB.print(F("3.6. Set channel frequency error = "));
308
USB.println(error, DEC);
309
}
310
311
error = LoRaWAN.setChannelFreq(7, 923300000);
312
if ( error == 0 )
313
{
314
USB.print(F("3.7. Set channel frequency OK. "));
315
USB.print(F("Frequency in channel 7: "));
316
USB.println(LoRaWAN._freq[7]);
317
}
318
else
319
{
320
USB.print(F("3.7. Set channel frequency error = "));
321
USB.println(error, DEC);
322
}
323
324
325
break;
326
327
}
328
329
//////////////////////////////////////////////
330
// 4. Set Data rate range for specific channel
331
//////////////////////////////////////////////
332
333
error = LoRaWAN.setChannelDRRange(3, 0, 2);
334
335
// Check status
336
if ( error == 0 )
337
{
338
USB.print(F("4. Data Rate range set OK. "));
339
USB.print(F("Data Rate min:"));
340
USB.print(LoRaWAN._drrMin[3], DEC);
341
USB.print(F(". Data Rate max:"));
342
USB.println(LoRaWAN._drrMax[3], DEC);
343
}
344
else
345
{
346
USB.print(F("4. Data rate range set error = "));
347
USB.println(error, DEC);
348
}
349
350
351
///////////////////////////////////////////////////////////
352
// show configuration for all channels available
353
///////////////////////////////////////////////////////////
354
355
USB.println(F("\n----------------------------"));
356
357
for ( int i = 0; i < 16; i++)
358
{
359
LoRaWAN.getChannelFreq(i);
360
LoRaWAN.getChannelDRRange(i);
361
362
USB.print(F("Channel: "));
363
USB.println(i);
364
USB.print(F(" Freq: "));
365
USB.println(LoRaWAN._freq[i]);
366
USB.print(F(" DR min: "));
367
USB.println(LoRaWAN._drrMin[i], DEC);
368
USB.print(F(" DR max: "));
369
USB.println(LoRaWAN._drrMax[i], DEC);
370
USB.println(F("----------------------------"));
371
}
372
373
}
374
375
376
void loop()
377
{
378
// do nothing
379
}
Copied!

Output

1
J#
2
LoRaWAN example - LoRaWAN JP/KR Channels Configuration
3
1. Switch ON OK
4
2.1. Set band OK
5
2.2. Get band OK. Band: 0 - Region is AS923 JAPAN
6
3.0. Set channel frequency OK. Frequency in channel 0: 923200000
7
3.1. Set channel frequency OK. Frequency in channel 1: 923400000
8
3.2. Set channel frequency OK. Frequency in channel 2: 923600000
9
3.3. Set channel frequency OK. Frequency in channel 3: 923800000
10
3.4. Set channel frequency OK. Frequency in channel 4: 924000000
11
3.5. Set channel frequency OK. Frequency in channel 5: 924200000
12
3.6. Set channel frequency OK. Frequency in channel 6: 924400000
13
4. Data Rate range set OK. Data Rate min:0. Data Rate max:2
14
15
----------------------------
16
Channel: 0
17
Freq: 923200000
18
DR min: 0
19
DR max: 5
20
----------------------------
21
Channel: 1
22
Freq: 923400000
23
DR min: 0
24
DR max: 5
25
----------------------------
26
Channel: 2
27
Freq: 923600000
28
DR min: 0
29
DR max: 5
30
----------------------------
31
Channel: 3
32
Freq: 923800000
33
DR min: 0
34
DR max: 2
35
----------------------------
36
Channel: 4
37
Freq: 924000000
38
DR min: 0
39
DR max: 5
40
----------------------------
41
Channel: 5
42
Freq: 924200000
43
DR min: 0
44
DR max: 5
45
----------------------------
46
Channel: 6
47
Freq: 924400000
48
DR min: 0
49
DR max: 5
50
----------------------------
51
Channel: 7
52
Freq: 0
53
DR min: 0
54
DR max: 5
55
----------------------------
56
Channel: 8
57
Freq: 0
58
DR min: 0
59
DR max: 5
60
----------------------------
61
Channel: 9
62
Freq: 0
63
DR min: 0
64
DR max: 5
65
----------------------------
66
Channel: 10
67
Freq: 0
68
DR min: 0
69
DR max: 5
70
----------------------------
71
Channel: 11
72
Freq: 0
73
DR min: 0
74
DR max: 5
75
----------------------------
76
Channel: 12
77
Freq: 0
78
DR min: 0
79
DR max: 5
80
----------------------------
81
Channel: 13
82
Freq: 0
83
DR min: 0
84
DR max: 5
85
----------------------------
86
Channel: 14
87
Freq: 0
88
DR min: 0
89
DR max: 5
90
----------------------------
91
Channel: 15
92
Freq: 0
93
DR min: 0
94
DR max: 5
95
----------------------------
Copied!
Last modified 1yr ago