LoRaWAN 04: Data rate
This example shows how to configure the data rate.

Required Materials

1 x Waspmote 1 x Battery 1 x LoRaWAN EU or US or AU or IN or ASIA-PAC / LATAM or JP/KR module 1 x 868/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 data rate.
5
The possibilities are:
6
7
LoRaWAN EU or IN or ASIA-PAC / LATAM:
8
9
0: SF = 12, BW = 125 kHz, BitRate = 250 bps
10
1: SF = 11, BW = 125 kHz, BitRate = 440 bps
11
2: SF = 10, BW = 125 kHz, BitRate = 980 bps
12
3: SF = 9, BW = 125 kHz, BitRate = 1760 bps
13
4: SF = 8, BW = 125 kHz, BitRate = 3125 bps
14
5: SF = 7, BW = 125 kHz, BitRate = 5470 bps
15
16
LoRaWAN US or AU:
17
18
0: SF = 10, BW = 125 kHz, BitRate = 980 bps
19
1: SF = 9, BW = 125 kHz, BitRate = 1760 bps
20
2: SF = 8, BW = 125 kHz, BitRate = 3125 bps
21
3: SF = 7, BW = 125 kHz, BitRate = 5470 bps
22
23
LoRaWAN JP:
24
25
0: SF = 12, BW = 125 kHz, BitRate = 250 bps
26
1: SF = 11, BW = 125 kHz, BitRate = 440 bps
27
2: SF = 10, BW = 125 kHz, BitRate = 980 bps
28
3: SF = 9, BW = 125 kHz, BitRate = 1760 bps
29
4: SF = 8, BW = 125 kHz, BitRate = 3125 bps
30
5: SF = 7, BW = 125 kHz, BitRate = 5470 bps
31
6: SF = 7, BW = 250 kHz, BitRate = 11000 bps
32
33
LoRaWAN KR:
34
35
0: SF = 12, BW = 125 kHz, BitRate = 250 bps
36
1: SF = 11, BW = 125 kHz, BitRate = 440 bps
37
2: SF = 10, BW = 125 kHz, BitRate = 980 bps
38
3: SF = 9, BW = 125 kHz, BitRate = 1760 bps
39
4: SF = 8, BW = 125 kHz, BitRate = 3125 bps
40
5: SF = 7, BW = 125 kHz, BitRate = 5470 bps
41
42
Copyright (C) 2019 Libelium Comunicaciones Distribuidas S.L.
43
http://www.libelium.com
44
45
This program is free software: you can redistribute it and/or modify
46
it under the terms of the GNU General Public License as published by
47
the Free Software Foundation, either version 3 of the License, or
48
(at your option) any later version.
49
50
This program is distributed in the hope that it will be useful,
51
but WITHOUT ANY WARRANTY; without even the implied warranty of
52
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
53
GNU General Public License for more details.
54
55
You should have received a copy of the GNU General Public License
56
along with this program. If not, see .
57
58
Version: 3.6
59
Design: David Gascon
60
Implementation: Luismi Marti
61
*/
62
63
#include <WaspLoRaWAN.h>
64
65
//////////////////////////////////////////////
66
uint8_t socket = SOCKET0;
67
//////////////////////////////////////////////
68
69
// variable
70
uint8_t error;
71
72
73
void setup()
74
{
75
USB.ON();
76
USB.println(F("LoRaWAN example - Data Rate configuration"));
77
USB.println(F("\nData Rate options:"));
78
79
//////////////////////////////////////////////
80
// 1. switch on
81
//////////////////////////////////////////////
82
83
error = LoRaWAN.ON(socket);
84
85
// Check status
86
if ( error == 0 )
87
{
88
USB.println(F("1. Switch ON OK"));
89
}
90
else
91
{
92
USB.print(F("1. Switch ON error = "));
93
USB.println(error, DEC);
94
}
95
96
if (LoRaWAN._version == RN2483_MODULE || LoRaWAN._version == RN2903_IN_MODULE || LoRaWAN._version == RN2903_AS_MODULE)
97
{
98
USB.println(F("------------------------------------------------------"));
99
USB.println(F(" 0: SF = 12, BW = 125 kHz, BitRate = 250 bps"));
100
USB.println(F(" 1: SF = 11, BW = 125 kHz, BitRate = 440 bps"));
101
USB.println(F(" 2: SF = 10, BW = 125 kHz, BitRate = 980 bps"));
102
USB.println(F(" 3: SF = 9, BW = 125 kHz, BitRate = 1760 bps"));
103
USB.println(F(" 4: SF = 8, BW = 125 kHz, BitRate = 3125 bps"));
104
USB.println(F(" 5: SF = 7, BW = 125 kHz, BitRate = 5470 bps"));
105
USB.println(F("------------------------------------------------------\n"));
106
}
107
else if (LoRaWAN._version == RN2903_MODULE)
108
{
109
USB.println(F("------------------------------------------------------"));
110
USB.println(F(" 0: SF = 10, BW = 125 kHz, BitRate = 980 bps"));
111
USB.println(F(" 1: SF = 9, BW = 125 kHz, BitRate = 1760 bps"));
112
USB.println(F(" 2: SF = 8, BW = 125 kHz, BitRate = 3125 bps"));
113
USB.println(F(" 3: SF = 7, BW = 125 kHz, BitRate = 5470 bps"));
114
USB.println(F("------------------------------------------------------\n"));
115
}
116
else if (LoRaWAN._version == ABZ_MODULE)
117
{
118
// Get band
119
error = LoRaWAN.getBand();
120
121
// Check status
122
if ( error == 0 )
123
{
124
if (LoRaWAN._bandABZ == BAND_JP923)
125
{
126
USB.println(F("------------------------------------------------------"));
127
USB.println(F(" 0: SF = 12, BW = 125 kHz, BitRate = 250 bps"));
128
USB.println(F(" 1: SF = 11, BW = 125 kHz, BitRate = 440 bps"));
129
USB.println(F(" 2: SF = 10, BW = 125 kHz, BitRate = 980 bps"));
130
USB.println(F(" 3: SF = 9, BW = 125 kHz, BitRate = 1760 bps"));
131
USB.println(F(" 4: SF = 8, BW = 125 kHz, BitRate = 3125 bps"));
132
USB.println(F(" 5: SF = 7, BW = 125 kHz, BitRate = 5470 bps"));
133
USB.println(F(" 6: SF = 7, BW = 250 kHz, BitRate = 11000 bps"));
134
USB.println(F("------------------------------------------------------\n"));
135
}
136
else if (LoRaWAN._bandABZ == BAND_KR920)
137
{
138
USB.println(F("------------------------------------------------------"));
139
USB.println(F(" 0: SF = 12, BW = 125 kHz, BitRate = 250 bps"));
140
USB.println(F(" 1: SF = 11, BW = 125 kHz, BitRate = 440 bps"));
141
USB.println(F(" 2: SF = 10, BW = 125 kHz, BitRate = 980 bps"));
142
USB.println(F(" 3: SF = 9, BW = 125 kHz, BitRate = 1760 bps"));
143
USB.println(F(" 4: SF = 8, BW = 125 kHz, BitRate = 3125 bps"));
144
USB.println(F(" 5: SF = 7, BW = 125 kHz, BitRate = 5470 bps"));
145
USB.println(F("------------------------------------------------------\n"));
146
}
147
}
148
else
149
{
150
USB.print(F("1.1. Get band error = "));
151
USB.println(error, DEC);
152
}
153
154
}
155
//////////////////////////////////////////////
156
// 2. Set Data Rate
157
//////////////////////////////////////////////
158
159
error = LoRaWAN.setDataRate(2);
160
161
// Check status
162
if ( error == 0 )
163
{
164
USB.println(F("2. Data rate set OK"));
165
}
166
else
167
{
168
USB.print(F("2. Data rate set error = "));
169
USB.println(error, DEC);
170
}
171
172
173
//////////////////////////////////////////////
174
// 3. Get Data Rate
175
//////////////////////////////////////////////
176
177
error = LoRaWAN.getDataRate();
178
179
// Check status
180
if ( error == 0 )
181
{
182
USB.print(F("3. Data rate get OK. "));
183
USB.print(F("Data rate index:"));
184
USB.println(LoRaWAN._dataRate, DEC);
185
}
186
else
187
{
188
USB.print(F("3. Data rate get error = "));
189
USB.println(error, DEC);
190
}
191
192
193
//////////////////////////////////////////////
194
// 4. Save configuration
195
//////////////////////////////////////////////
196
197
error = LoRaWAN.saveConfig();
198
199
// Check status
200
if ( error == 0 )
201
{
202
USB.println(F("4. Save configuration OK"));
203
}
204
else
205
{
206
USB.print(F("4. Save configuration error = "));
207
USB.println(error, DEC);
208
}
209
210
}
211
212
213
void loop()
214
{
215
216
}
Copied!

Output

1
J#
2
LoRaWAN example - Data Rate configuration
3
4
Data Rate options:
5
1. Switch ON OK
6
------------------------------------------------------
7
0: SF = 12, BW = 125 kHz, BitRate = 250 bps
8
1: SF = 11, BW = 125 kHz, BitRate = 440 bps
9
2: SF = 10, BW = 125 kHz, BitRate = 980 bps
10
3: SF = 9, BW = 125 kHz, BitRate = 1760 bps
11
4: SF = 8, BW = 125 kHz, BitRate = 3125 bps
12
5: SF = 7, BW = 125 kHz, BitRate = 5470 bps
13
------------------------------------------------------
14
15
2. Data rate set OK
16
3. Data rate get OK. Data rate index:2
17
4. Save configuration OK
Copied!
Last modified 1yr ago