LoRaWAN 03: Power level
This example shows how to configure the power level LoRaWAN interface

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 power level
5
LoRaWAN interface:
6
EU 433 MHz US AU IN ASIA-PAC/LATAM JP KR
7
0: N/A 10 dBm N/A N/A 20 dBm 20 dBm 16 dBm 14 dBm
8
1: 14 dBm 7 dBm N/A N/A 18 dBm 18 dBm 14 dBm 12 dBm
9
2: 11 dBm 4 dBm N/A N/A 16 dBm 16 dBm 12 dBm 10 dBm
10
3: 8 dBm 1 dBm N/A N/A 14 dBm 14 dBm 10 dBm 8 dBm
11
4: 5 dBm -2 dBm N/A N/A 12 dBm 12 dBm 8 dBm 6 dBm
12
5: 2 dBm -5 dBm 20 dBm 20 dBm 10 dBm 10 dBm 6 dBm 4 dBm
13
6: N/A N/A 18 dBm 18 dBm N/A N/A 4 dBm 2 dBm
14
7: N/A N/A 16 dBm 16 dBm N/A N/A 2 dBm 0 dBm
15
8: N/A N/A 14 dBm 14 dBm N/A N/A N/A N/A
16
9: N/A N/A 12 dBm 12 dBm N/A N/A N/A N/A
17
10: N/A N/A 10 dBm 10 dBm N/A N/A N/A N/A
18
19
Copyright (C) 2019 Libelium Comunicaciones Distribuidas S.L.
20
http://www.libelium.com
21
22
This program is free software: you can redistribute it and/or modify
23
it under the terms of the GNU General Public License as published by
24
the Free Software Foundation, either version 3 of the License, or
25
(at your option) any later version.
26
27
This program is distributed in the hope that it will be useful,
28
but WITHOUT ANY WARRANTY; without even the implied warranty of
29
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30
GNU General Public License for more details.
31
32
You should have received a copy of the GNU General Public License
33
along with this program. If not, see .
34
35
Version: 3.5
36
Design: David Gascon
37
Implementation: Luismi Marti
38
*/
39
40
#include <WaspLoRaWAN.h>
41
42
//////////////////////////////////////////////
43
uint8_t socket = SOCKET0;
44
//////////////////////////////////////////////
45
46
// variable
47
uint8_t error;
48
49
50
void setup()
51
{
52
USB.ON();
53
USB.println(F("LoRaWAN example - Power configuration"));
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
if (LoRaWAN._version == RN2483_MODULE || LoRaWAN._version == RN2903_IN_MODULE || LoRaWAN._version == RN2903_AS_MODULE)
74
{
75
USB.println(F("------------------------------------------------------"));
76
USB.println(F(" EU 433 MHz IN ASIA-PAC / LATAM"));
77
USB.println(F("0: N/A 10 dBm 20 dBm 20 dBm"));
78
USB.println(F("1: 14 dBm 7 dBm 18 dBm 18 dBm"));
79
USB.println(F("2: 11 dBm 4 dBm 16 dBm 16 dBm"));
80
USB.println(F("3: 8 dBm 1 dBm 14 dBm 14 dBm"));
81
USB.println(F("4: 5 dBm -2 dBm 12 dBm 12 dBm"));
82
USB.println(F("5: 2 dBm -5 dBm 10 dBm 10 dBm"));
83
USB.println(F("------------------------------------------------------\n"));
84
}
85
else if (LoRaWAN._version == RN2903_MODULE)
86
{
87
USB.println(F("------------------------------------------------------"));
88
USB.println(F(" US/AU"));
89
USB.println(F("5: 20 dBm"));
90
USB.println(F("6: 18 dBm"));
91
USB.println(F("7: 16 dBm"));
92
USB.println(F("8: 14 dBm"));
93
USB.println(F("9: 12 dBm"));
94
USB.println(F("10: 10 dBm"));
95
USB.println(F("------------------------------------------------------\n"));
96
}
97
else if (LoRaWAN._version == ABZ_MODULE)
98
{
99
// Get band
100
error = LoRaWAN.getBand();
101
102
// Check status
103
if ( error == 0 )
104
{
105
if (LoRaWAN._bandABZ == BAND_JP923)
106
{
107
USB.println(F("------------------------------------------------------"));
108
USB.println(F(" JP"));
109
USB.println(F("0: 16 dBm"));
110
USB.println(F("1: 14 dBm"));
111
USB.println(F("2: 12 dBm"));
112
USB.println(F("3: 10 dBm"));
113
USB.println(F("4: 8 dBm"));
114
USB.println(F("5: 6 dBm"));
115
USB.println(F("6: 4 dBm"));
116
USB.println(F("7: 2 dBm"));
117
USB.println(F("------------------------------------------------------\n"));
118
}
119
else if (LoRaWAN._bandABZ == BAND_KR920)
120
{
121
USB.println(F("------------------------------------------------------"));
122
USB.println(F(" KR"));
123
USB.println(F("0: 14 dBm"));
124
USB.println(F("1: 12 dBm"));
125
USB.println(F("2: 10 dBm"));
126
USB.println(F("3: 8 dBm"));
127
USB.println(F("4: 6 dBm"));
128
USB.println(F("5: 4 dBm"));
129
USB.println(F("6: 2 dBm"));
130
USB.println(F("7: 0 dBm"));
131
USB.println(F("------------------------------------------------------\n"));
132
}
133
}
134
else
135
{
136
USB.print(F("1.1. Get band error = "));
137
USB.println(error, DEC);
138
}
139
}
140
141
142
//////////////////////////////////////////////
143
// 2. Set Power level
144
//////////////////////////////////////////////
145
146
error = LoRaWAN.setPower(5);
147
148
// Check status
149
if ( error == 0 )
150
{
151
USB.println(F("2. Power level set OK"));
152
}
153
else
154
{
155
USB.print(F("2. Power level set error = "));
156
USB.println(error, DEC);
157
}
158
159
160
//////////////////////////////////////////////
161
// 3. Get Device EUI
162
//////////////////////////////////////////////
163
164
error = LoRaWAN.getPower();
165
166
// Check status
167
if ( error == 0 )
168
{
169
USB.print(F("3. Power level get OK. "));
170
USB.print(F("Power index:"));
171
USB.println(LoRaWAN._powerIndex, DEC);
172
}
173
else
174
{
175
USB.print(F("3. Power level set error = "));
176
USB.println(error, DEC);
177
}
178
179
180
USB.println(F("------------------------------------"));
181
USB.println(F("Keep in mind the power setting cannot"));
182
USB.println(F("be saved in the module's memory. Every"));
183
USB.println(F("time the module is powered on, the user"));
184
USB.println(F("must set the parameter again"));
185
USB.println(F("------------------------------------\n"));
186
187
}
188
189
190
void loop()
191
{
192
193
}
Copied!

Output

1
H#
2
LoRaWAN example - Power configuration
3
1. Switch ON OK
4
------------------------------------------------------
5
EU 433 MHz IN ASIA-PAC / LATAM
6
0: N/A 10 dBm 20 dBm 20 dBm
7
1: 14 dBm 7 dBm 18 dBm 18 dBm
8
2: 11 dBm 4 dBm 16 dBm 16 dBm
9
3: 8 dBm 1 dBm 14 dBm 14 dBm
10
4: 5 dBm -2 dBm 12 dBm 12 dBm
11
5: 2 dBm -5 dBm 10 dBm 10 dBm
12
------------------------------------------------------
13
14
2. Power level set OK
15
3. Power level get OK. Power index:5
16
------------------------------------
17
Keep in mind the power setting cannot
18
be saved in the module's memory. Every
19
time the module is powered on, the user
20
must set the parameter again
21
------------------------------------
Copied!
Last modified 1yr ago