LoRaWAN 02b: Channels US or AU
This example shows how to configure the channels settings for LoRaWAN US and LoRaWAN AU

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

Output

1
H#
2
LoRaWAN example - LoRaWAN 900 Channel configuration
3
1. Switch ON OK
4
2. Frequency get OK. Frequency:902900000
5
3. Data Rate range set OK. Data Rate min:0. Data Rate max:2
6
4. Channel status set OK: 1
7
5. Save configuration OK
8
9
----------------------------
10
Channel: 0
11
Freq: 902300000
12
DR min: 0
13
DR max: 3
14
Status: on
15
----------------------------
16
Channel: 1
17
Freq: 902500000
18
DR min: 0
19
DR max: 3
20
Status: on
21
----------------------------
22
Channel: 2
23
Freq: 902700000
24
DR min: 0
25
DR max: 3
26
Status: on
27
----------------------------
28
Channel: 3
29
Freq: 902900000
30
DR min: 0
31
DR max: 2
32
Status: off
33
----------------------------
34
.........
35
----------------------------
36
Channel: 62
37
Freq: 914700000
38
DR min: 0
39
DR max: 3
40
Status: on
41
----------------------------
42
Channel: 63
43
Freq: 914900000
44
DR min: 0
45
DR max: 3
46
Status: on
47
----------------------------
Copied!
Last modified 1yr ago