ZB 07b: Expansion board RX
This example shows how to receive packet via the Expansion board (SOCKET1).

Required Materials

1 x Waspmote 1 x Battery 1 x MiniUSB wire 1 x XBee-ZigBee module 1 x Expansion Radio Board

Notes

- The coordinator must be turned on - This example belongs to a two-code example. This is the sending part. - The battery has to be connected. - This example can be executed in Waspmote v12

Code

1
/*
2
* ------ [ZB_07b] - Use of Expansion board --------
3
*
4
* Explanation: This example shows how to receive packet via
5
* the Expansion board (SOCKET1).
6
*
7
* Copyright (C) 2015 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: 0.2
24
* Design: David Gascón
25
* Implementation: Yuri Carmona
26
*/
27
28
#include <WaspXBeeZB.h>
29
30
// define variable
31
uint8_t error;
32
33
34
void setup()
35
{
36
// init USB port
37
USB.ON();
38
USB.println(F("Receiving example via Expansion Board"));
39
40
//////////////////////////
41
// 1. init XBees
42
//////////////////////////
43
44
// 1.2. initiliaze object in SOCKET1
45
xbeeZB.ON( SOCKET1 );
46
47
delay(3000);
48
49
50
//////////////////////////
51
// 2. check both XBee's network parameters
52
//////////////////////////
53
checkNetworkParams();
54
}
55
56
57
void loop()
58
{
59
// receive XBee packet
60
error = xbeeZB.receivePacketTimeout( 10000 );
61
62
// check answer
63
if( error == 0 )
64
{
65
// Show data stored in '_payload' buffer indicated by '_length'
66
USB.print(F("\nData: "));
67
USB.println( xbeeZB._payload, xbeeZB._length);
68
69
// Show data stored in '_payload' buffer indicated by '_length'
70
USB.print(F("Length: "));
71
USB.println( xbeeZB._length,DEC);
72
}
73
else
74
{
75
// Print error message:
76
/*
77
* '7' : Buffer full. Not enough memory space
78
* '6' : Error escaping character within payload bytes
79
* '5' : Error escaping character in checksum byte
80
* '4' : Checksum is not correct
81
* '3' : Checksum byte is not available
82
* '2' : Frame Type is not valid
83
* '1' : Timeout when receiving answer
84
*/
85
USB.print(F("Error receiving a packet:"));
86
USB.println(error,DEC);
87
}
88
89
}
90
91
92
93
94
/*******************************************
95
*
96
* checkNetworkParams - Check operating
97
* network parameters in the XBee module
98
*
99
*******************************************/
100
void checkNetworkParams()
101
{
102
// 1. get operating 64-b PAN ID
103
xbeeZB.getOperating64PAN();
104
105
// 2. wait for association indication
106
xbeeZB.getAssociationIndication();
107
108
USB.println(F("Wait for association"));
109
while( xbeeZB.associationIndication != 0 )
110
{
111
delay(2000);
112
113
USB.print(F("."));
114
115
xbeeZB.getAssociationIndication();
116
}
117
118
USB.println(F("\nmodule joined a network!"));
119
120
}
121
122
Copied!

Output

1
E#
2
Receiving example via Expansion Board
3
Wait for association
4
5
module joined a network!
6
7
Data: this_is_a_message
8
Length: 17
9
10
Data: this_is_a_message
11
Length: 17
12
13
Data: this_is_a_message
14
Length: 17
15
...
Copied!
Last modified 2yr ago