ZB 06: Get RSSI
This program shows how to get the RSSI value from the last received packet. For this protocol, there is an API function which shows this information. Before running this example, make sure there is another emitter sending packets to this XBee module in order to receive information.

Required Materials

1 x Waspmote 1 x Battery 1 x MiniUSB wire 1 x XBee-ZigBee module

Notes

- The coordinator must be turned on - Before running this example, make sure there is another emitter sending packets to this XBee module in order to receive information. - The battery has to be connected. - This example can be executed in Waspmote v12

Code

1
/*
2
* ------ [ZB_06] - get RSSI from last received packet --------
3
*
4
* Explanation: This program shows how to get RSSI value from the
5
* last received packet. For this protocol, there is an API function which
6
* shows this information. Before running this example, make sure there
7
* is another emitter sending packets to this XBee module in order to
8
* receive information.
9
*
10
* Copyright (C) 2015 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: 0.2
27
* Design: David Gascón
28
* Implementation: Yuri Carmona
29
*/
30
31
#include <WaspXBeeZB.h>
32
33
// define variable
34
uint8_t error;
35
36
// variable to store RSSI
37
int rssi;
38
39
40
void setup()
41
{
42
// init USB port
43
USB.ON();
44
USB.println(F("Get RSSI example"));
45
46
//////////////////////////
47
// 1. init XBee
48
//////////////////////////
49
xbeeZB.ON();
50
51
delay(3000);
52
53
//////////////////////////
54
// 2. check XBee's network parameters
55
//////////////////////////
56
checkNetworkParams();
57
58
}
59
60
61
62
void loop()
63
{
64
// receive XBee packet (wait for 10 seconds)
65
error = xbeeZB.receivePacketTimeout( 10000 );
66
67
// check answer
68
if( error == 0 )
69
{
70
// Show data stored in '_payload' buffer indicated by '_length'
71
USB.print(F("Data: "));
72
USB.println( xbeeZB._payload, xbeeZB._length);
73
74
// Show data stored in '_payload' buffer indicated by '_length'
75
USB.print(F("Length: "));
76
USB.println( xbeeZB._length,DEC);
77
78
// Getting RSSI using the API function
79
// This function returns the last received packet's RSSI
80
xbeeZB.getRSSI();
81
82
// check AT flag
83
if( xbeeZB.error_AT == 0 )
84
{
85
USB.print(F("getRSSI(dBm): "));
86
87
//get rssi from getRSSI function and make conversion
88
rssi = xbeeZB.valueRSSI[0];
89
rssi *= -1;
90
USB.println(rssi,DEC);
91
}
92
USB.println();
93
}
94
else
95
{
96
// Print error message:
97
/*
98
* '7' : Buffer full. Not enough memory space
99
* '6' : Error escaping character within payload bytes
100
* '5' : Error escaping character in checksum byte
101
* '4' : Checksum is not correct
102
* '3' : Checksum byte is not available
103
* '2' : Frame Type is not valid
104
* '1' : Timeout when receiving answer
105
*/
106
USB.print(F("Error receiving a packet:"));
107
USB.println(error,DEC);
108
}
109
}
110
111
112
/*******************************************
113
*
114
* checkNetworkParams - Check operating
115
* network parameters in the XBee module
116
*
117
*******************************************/
118
void checkNetworkParams()
119
{
120
// 1. get operating 64-b PAN ID
121
xbeeZB.getOperating64PAN();
122
123
// 2. wait for association indication
124
xbeeZB.getAssociationIndication();
125
126
while( xbeeZB.associationIndication != 0 )
127
{
128
delay(2000);
129
130
// get operating 64-b PAN ID
131
xbeeZB.getOperating64PAN();
132
133
USB.print(F("operating 64-b PAN ID: "));
134
USB.printHex(xbeeZB.operating64PAN[0]);
135
USB.printHex(xbeeZB.operating64PAN[1]);
136
USB.printHex(xbeeZB.operating64PAN[2]);
137
USB.printHex(xbeeZB.operating64PAN[3]);
138
USB.printHex(xbeeZB.operating64PAN[4]);
139
USB.printHex(xbeeZB.operating64PAN[5]);
140
USB.printHex(xbeeZB.operating64PAN[6]);
141
USB.printHex(xbeeZB.operating64PAN[7]);
142
USB.println();
143
144
xbeeZB.getAssociationIndication();
145
}
146
147
USB.println(F("\nJoined a network!"));
148
149
// 3. get network parameters
150
xbeeZB.getOperating16PAN();
151
xbeeZB.getOperating64PAN();
152
xbeeZB.getChannel();
153
154
USB.print(F("operating 16-b PAN ID: "));
155
USB.printHex(xbeeZB.operating16PAN[0]);
156
USB.printHex(xbeeZB.operating16PAN[1]);
157
USB.println();
158
159
USB.print(F("operating 64-b PAN ID: "));
160
USB.printHex(xbeeZB.operating64PAN[0]);
161
USB.printHex(xbeeZB.operating64PAN[1]);
162
USB.printHex(xbeeZB.operating64PAN[2]);
163
USB.printHex(xbeeZB.operating64PAN[3]);
164
USB.printHex(xbeeZB.operating64PAN[4]);
165
USB.printHex(xbeeZB.operating64PAN[5]);
166
USB.printHex(xbeeZB.operating64PAN[6]);
167
USB.printHex(xbeeZB.operating64PAN[7]);
168
USB.println();
169
170
USB.print(F("channel: "));
171
USB.printHex(xbeeZB.channel);
172
USB.println();
173
174
}
Copied!

Output

1
E#
2
Get RSSI example
3
4
Joined a network!
5
operating 16-b PAN ID: D27C
6
operating 64-b PAN ID: 84D87D34C4AE4CB1
7
channel: 0B
8
Data: <=>€#387245265#node_01#21#STR:new_sensor_frame#BAT:1#
9
Length: 54
10
getRSSI(dBm): -55
11
12
Data: <=>€#387245265#node_01#22#STR:new_sensor_frame#BAT:1#
13
Length: 54
14
getRSSI(dBm): -56
15
16
Data: <=>€#387245265#node_01#23#STR:new_sensor_frame#BAT:1#
17
Length: 54
18
getRSSI(dBm): -62
19
...
Copied!
Last modified 2yr ago