LoRaWAN 02a: Channels EU or IN or ASIA-PAC / LATAM
This example shows how to configure the channels settings. There are 16 channels. The first three of them are always preconfigured and cannot be changed: 868.1 MHz, 868.3 MHz and 868.5 MHz. Besides other parameters can be changed in all channels: Duty Cycle, Data rate range and channel status

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 channels settings.
5
* There are 16 channels. The first three of them are always preconfigured
6
* and cannot be changed: 868.1 MHz, 868.3 MHz and 868.5 MHz. Besides other
7
* parameters can be changed in all channels: Duty Cycle, Data rate range
8
* and channel status
9
*
10
* Copyright (C) 2018 Libelium Comunicaciones Distribuidas S.L.
11
* http://www.libelium.com
12
*
13
* This program is free software: you can redistribute it and/or modify
14
* it under the terms of the GNU General Public License as published by
15
* the Free Software Foundation, either version 3 of the License, or
16
* (at your option) any later version.
17
*
18
* This program is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
22
*
23
* You should have received a copy of the GNU General Public License
24
* along with this program. If not, see .
25
*
26
* Version: 3.4
27
* Design: David Gascon
28
* Implementation: Luismi Marti
29
*/
30
31
#include <WaspLoRaWAN.h>
32
33
//////////////////////////////////////////////
34
uint8_t socket = SOCKET0;
35
//////////////////////////////////////////////
36
37
// variable
38
uint8_t error;
39
40
41
void setup()
42
{
43
USB.ON();
44
USB.println(F("LoRaWAN example - LoRaWAN EU Channel configuration"));
45
46
//////////////////////////////////////////////
47
// 1. switch on
48
//////////////////////////////////////////////
49
50
error = LoRaWAN.ON(socket);
51
52
// Check status
53
if( error == 0 )
54
{
55
USB.println(F("1. Switch ON OK"));
56
}
57
else
58
{
59
USB.print(F("1. Switch ON error = "));
60
USB.println(error, DEC);
61
}
62
63
64
//////////////////////////////////////////////
65
// 2. Set frequency for specific channel
66
//////////////////////////////////////////////
67
68
error = LoRaWAN.setChannelFreq(3, 865000000);
69
70
// Check status
71
if( error == 0 )
72
{
73
USB.print(F("2. Frequency set OK. "));
74
USB.print(F("Frequency:"));
75
USB.println(LoRaWAN._freq[3]);
76
}
77
else
78
{
79
USB.print(F("2. Frequency set error = "));
80
USB.println(error, DEC);
81
}
82
83
84
//////////////////////////////////////////////
85
// 3. Set Duty Cycle for specific channel
86
//////////////////////////////////////////////
87
88
error = LoRaWAN.setChannelDutyCycle(3, 999);
89
90
// Check status
91
if( error == 0 )
92
{
93
USB.print(F("3. Adaptive Data Rate disabled OK. "));
94
USB.print(F("Duty Cycle:"));
95
USB.println(LoRaWAN._dCycle[3], DEC);
96
}
97
else
98
{
99
USB.print(F("3. Duty cycle set error = "));
100
USB.println(error, DEC);
101
}
102
103
104
//////////////////////////////////////////////
105
// 4. Set Data rate range for specific channel
106
//////////////////////////////////////////////
107
108
error = LoRaWAN.setChannelDRRange(3, 0, 2);
109
110
// Check status
111
if( error == 0 )
112
{
113
USB.print(F("4. Data Rate range set OK. "));
114
USB.print(F("Data Rate min:"));
115
USB.print(LoRaWAN._drrMin[3], DEC);
116
USB.print(F(". Data Rate max:"));
117
USB.println(LoRaWAN._drrMax[3], DEC);
118
}
119
else
120
{
121
USB.print(F("4. Data rate range set error = "));
122
USB.println(error, DEC);
123
}
124
125
126
//////////////////////////////////////////////
127
// 5. Set Data rate range for specific channel
128
//////////////////////////////////////////////
129
130
error = LoRaWAN.setChannelStatus(3, "on");
131
132
// Check status
133
if( error == 0 )
134
{
135
USB.print(F("5. Channel status set OK: "));
136
USB.println(LoRaWAN._status[3], DEC);
137
}
138
else
139
{
140
USB.print(F("5. Channel status set error = "));
141
USB.println(error, DEC);
142
}
143
144
145
//////////////////////////////////////////////
146
// 6. Save configuration
147
//////////////////////////////////////////////
148
149
error = LoRaWAN.saveConfig();
150
151
// Check status
152
if( error == 0 )
153
{
154
USB.println(F("4. Save configuration OK"));
155
}
156
else
157
{
158
USB.print(F("4. Save configuration error = "));
159
USB.println(error, DEC);
160
}
161
162
163
///////////////////////////////////////////////////////////
164
// show configuration for all channels available
165
///////////////////////////////////////////////////////////
166
167
USB.println(F("\n----------------------------"));
168
169
for( int i=0; i<16; i++)
170
{
171
LoRaWAN.getChannelFreq(i);
172
LoRaWAN.getChannelDutyCycle(i);
173
LoRaWAN.getChannelDRRange(i);
174
LoRaWAN.getChannelStatus(i);
175
176
USB.print(F("Channel: "));
177
USB.println(i);
178
USB.print(F(" Freq: "));
179
USB.println(LoRaWAN._freq[i]);
180
USB.print(F(" Duty cycle: "));
181
USB.println(LoRaWAN._dCycle[i]);
182
USB.print(F(" DR min: "));
183
USB.println(LoRaWAN._drrMin[i], DEC);
184
USB.print(F(" DR max: "));
185
USB.println(LoRaWAN._drrMax[i], DEC);
186
USB.print(F(" Status: "));
187
if (LoRaWAN._status[i] == 1)
188
{
189
USB.println(F("on"));
190
}
191
else
192
{
193
USB.println(F("off"));
194
}
195
USB.println(F("----------------------------"));
196
}
197
198
199
}
200
201
202
void loop()
203
{
204
205
206
}
Copied!

Output

1
H#
2
LoRaWAN example - Channels configuration
3
1. Switch ON OK
4
2. Frequency set OK. Frequency:865000000
5
3. Adaptive Data Rate disabled OK. Duty Cycle:999
6
4. Data Rate range set OK. Data Rate min:0. Data Rate max:2
7
5. Channel status set OK: 1
8
4. Save configuration OK
9
10
----------------------------
11
Channel: 0
12
Freq: 868100000
13
Duty cycle: 302
14
DR min: 0
15
DR max: 5
16
Status: 1
17
----------------------------
18
Channel: 1
19
Freq: 868300000
20
Duty cycle: 302
21
DR min: 0
22
DR max: 5
23
Status: 1
24
----------------------------
25
Channel: 2
26
Freq: 868500000
27
Duty cycle: 302
28
DR min: 0
29
DR max: 5
30
Status: 1
31
----------------------------
32
Channel: 3
33
Freq: 865000000
34
Duty cycle: 999
35
DR min: 0
36
DR max: 2
37
Status: 1
38
----------------------------
39
Channel: 4
40
Freq: 0
41
Duty cycle: 65535
42
DR min: 15
43
DR max: 15
44
Status: 0
45
----------------------------
46
Channel: 5
47
Freq: 0
48
Duty cycle: 65535
49
DR min: 15
50
DR max: 15
51
Status: 0
52
----------------------------
53
Channel: 6
54
Freq: 0
55
Duty cycle: 65535
56
DR min: 15
57
DR max: 15
58
Status: 0
59
----------------------------
60
Channel: 7
61
Freq: 0
62
Duty cycle: 65535
63
DR min: 15
64
DR max: 15
65
Status: 0
66
----------------------------
67
Channel: 8
68
Freq: 0
69
Duty cycle: 65535
70
DR min: 15
71
DR max: 15
72
Status: 0
73
----------------------------
74
Channel: 9
75
Freq: 0
76
Duty cycle: 65535
77
DR min: 15
78
DR max: 15
79
Status: 0
80
----------------------------
81
Channel: 10
82
Freq: 0
83
Duty cycle: 65535
84
DR min: 15
85
DR max: 15
86
Status: 0
87
----------------------------
88
Channel: 11
89
Freq: 0
90
Duty cycle: 65535
91
DR min: 15
92
DR max: 15
93
Status: 0
94
----------------------------
95
Channel: 12
96
Freq: 0
97
Duty cycle: 65535
98
DR min: 15
99
DR max: 15
100
Status: 0
101
----------------------------
102
Channel: 13
103
Freq: 0
104
Duty cycle: 65535
105
DR min: 15
106
DR max: 15
107
Status: 0
108
----------------------------
109
Channel: 14
110
Freq: 0
111
Duty cycle: 65535
112
DR min: 15
113
DR max: 15
114
Status: 0
115
----------------------------
116
Channel: 15
117
Freq: 0
118
Duty cycle: 65535
119
DR min: 15
120
DR max: 15
121
Status: 0
122
----------------------------
Copied!
Last modified 1yr ago