LoRaWAN 05: Adaptive data rate
This example shows how to enable / disable the adaptive data rate.

Required Materials

1 x Waspmote 1 x Battery 1 x LoRaWAN EU or US or AU or IN or ASIA-PAC / LATAM 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 enable / disable the
5
* adaptive data rate.
6
*
7
* Copyright (C) 2017 Libelium Comunicaciones Distribuidas S.L.
8
* http://www.libelium.com
9
*
10
* This program is free software: you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation, either version 3 of the License, or
13
* (at your option) any later version.
14
*
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
19
*
20
* You should have received a copy of the GNU General Public License
21
* along with this program. If not, see .
22
*
23
* Version: 3.1
24
* Design: David Gascon
25
* Implementation: Luismi Marti
26
*/
27
28
#include <WaspLoRaWAN.h>
29
30
//////////////////////////////////////////////
31
uint8_t socket = SOCKET0;
32
//////////////////////////////////////////////
33
34
// variable
35
uint8_t error;
36
37
38
void setup()
39
{
40
USB.ON();
41
USB.println(F("LoRaWAN example - Data Rate configuration"));
42
43
//////////////////////////////////////////////
44
// 1. switch on
45
//////////////////////////////////////////////
46
47
error = LoRaWAN.ON(socket);
48
49
// Check status
50
if( error == 0 )
51
{
52
USB.println(F("1. Switch ON OK"));
53
}
54
else
55
{
56
USB.print(F("1. Switch ON error = "));
57
USB.println(error, DEC);
58
}
59
60
61
//////////////////////////////////////////////
62
// 2. Enable Adaptive Data Rate (ADR)
63
//////////////////////////////////////////////
64
65
error = LoRaWAN.setADR("on");
66
67
// Check status
68
if( error == 0 )
69
{
70
USB.print(F("2. Adaptive Data Rate enabled OK. "));
71
USB.print(F("ADR:"));
72
USB.println(LoRaWAN._adr, DEC);
73
}
74
else
75
{
76
USB.print(F("2. Enable data rate error = "));
77
USB.println(error, DEC);
78
}
79
80
81
//////////////////////////////////////////////
82
// 3. Disable Adaptive Data Rate (ADR)
83
//////////////////////////////////////////////
84
85
error = LoRaWAN.setADR("off");
86
87
// Check status
88
if( error == 0 )
89
{
90
USB.print(F("3. Adaptive Data Rate disabled OK. "));
91
USB.print(F("ADR:"));
92
USB.println(LoRaWAN._adr, DEC);
93
}
94
else
95
{
96
USB.print(F("3. Data rate set error = "));
97
USB.println(error, DEC);
98
}
99
100
101
//////////////////////////////////////////////
102
// 4. Save configuration
103
//////////////////////////////////////////////
104
105
error = LoRaWAN.saveConfig();
106
107
// Check status
108
if( error == 0 )
109
{
110
USB.println(F("4. Save configuration OK"));
111
}
112
else
113
{
114
USB.print(F("4. Save configuration error = "));
115
USB.println(error, DEC);
116
}
117
118
}
119
120
121
void loop()
122
{
123
124
}
Copied!

Output

1
H#
2
LoRaWAN example - Data Rate configuration
3
1. Switch ON OK
4
2. Adaptive Data Rate enabled OK. ADR:1
5
3. Adaptive Data Rate disabled OK. ADR:0
6
4. Save configuration OK
Copied!
Last modified 1yr ago