ZB 05a: Send broadcast
This program shows how to send packets with XBee-ZigBee modules. Broadcast address (0x000000000000FFFF) is specified as destination address

Required Materials

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

Notes

- The coordinator must be turned on - The battery has to be connected. - This example can be executed in Waspmote v12

Code

1
/*
2
* ------ [ZB_05a] - send broadcast packets --------
3
*
4
* Explanation: This program shows how to send packets with
5
* XBee-ZigBee modules. Broadcast address (0x000000000000FFFF)
6
* is specified as destination address
7
*
8
* Copyright (C) 2015 Libelium Comunicaciones Distribuidas S.L.
9
* http://www.libelium.com
10
*
11
* This program is free software: you can redistribute it and/or modify
12
* it under the terms of the GNU General Public License as published by
13
* the Free Software Foundation, either version 3 of the License, or
14
* (at your option) any later version.
15
*
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
20
*
21
* You should have received a copy of the GNU General Public License
22
* along with this program. If not, see .
23
*
24
* Version: 0.2
25
* Design: David Gascón
26
* Implementation: Yuri Carmona
27
*/
28
29
#include <WaspXBeeZB.h>
30
#include <WaspFrame.h>
31
32
// Define BROADCAST MAC address
33
//////////////////////////////////////////
34
char RX_ADDRESS[] = "000000000000FFFF";
35
//////////////////////////////////////////
36
37
// Define the Waspmote ID
38
char WASPMOTE_ID[] = "node_01";
39
40
41
// define variable
42
uint8_t error;
43
44
45
46
void setup()
47
{
48
// init USB port
49
USB.ON();
50
USB.println(F("Sending BROADCAST packets example"));
51
52
// store Waspmote identifier in EEPROM memory
53
frame.setID( WASPMOTE_ID );
54
55
//////////////////////////
56
// 1. init XBee
57
//////////////////////////
58
xbeeZB.ON();
59
60
delay(3000);
61
62
//////////////////////////
63
// 2. check XBee's network parameters
64
//////////////////////////
65
checkNetworkParams();
66
67
}
68
69
70
void loop()
71
{
72
///////////////////////////////////////////
73
// 1. Create ASCII frame
74
///////////////////////////////////////////
75
76
// create new frame
77
frame.createFrame(ASCII);
78
79
// add frame fields
80
frame.addSensor(SENSOR_STR, "new_sensor_frame");
81
frame.addSensor(SENSOR_BAT, PWR.getBatteryLevel());
82
83
84
///////////////////////////////////////////
85
// 2. Send packet
86
///////////////////////////////////////////
87
88
// send XBee packet
89
error = xbeeZB.send( RX_ADDRESS, frame.buffer, frame.length );
90
91
// check TX flag
92
if( error == 0 )
93
{
94
USB.println(F("send ok"));
95
96
// blink green LED
97
Utils.blinkGreenLED();
98
99
}
100
else
101
{
102
USB.println(F("send error"));
103
104
// blink red LED
105
Utils.blinkRedLED();
106
}
107
108
// wait for five seconds
109
delay(5000);
110
}
111
112
113
114
/*******************************************
115
*
116
* checkNetworkParams - Check operating
117
* network parameters in the XBee module
118
*
119
*******************************************/
120
void checkNetworkParams()
121
{
122
// 1. get operating 64-b PAN ID
123
xbeeZB.getOperating64PAN();
124
125
// 2. wait for association indication
126
xbeeZB.getAssociationIndication();
127
128
while( xbeeZB.associationIndication != 0 )
129
{
130
delay(2000);
131
132
// get operating 64-b PAN ID
133
xbeeZB.getOperating64PAN();
134
135
USB.print(F("operating 64-b PAN ID: "));
136
USB.printHex(xbeeZB.operating64PAN[0]);
137
USB.printHex(xbeeZB.operating64PAN[1]);
138
USB.printHex(xbeeZB.operating64PAN[2]);
139
USB.printHex(xbeeZB.operating64PAN[3]);
140
USB.printHex(xbeeZB.operating64PAN[4]);
141
USB.printHex(xbeeZB.operating64PAN[5]);
142
USB.printHex(xbeeZB.operating64PAN[6]);
143
USB.printHex(xbeeZB.operating64PAN[7]);
144
USB.println();
145
146
xbeeZB.getAssociationIndication();
147
}
148
149
USB.println(F("\nJoined a network!"));
150
151
// 3. get network parameters
152
xbeeZB.getOperating16PAN();
153
xbeeZB.getOperating64PAN();
154
xbeeZB.getChannel();
155
156
USB.print(F("operating 16-b PAN ID: "));
157
USB.printHex(xbeeZB.operating16PAN[0]);
158
USB.printHex(xbeeZB.operating16PAN[1]);
159
USB.println();
160
161
USB.print(F("operating 64-b PAN ID: "));
162
USB.printHex(xbeeZB.operating64PAN[0]);
163
USB.printHex(xbeeZB.operating64PAN[1]);
164
USB.printHex(xbeeZB.operating64PAN[2]);
165
USB.printHex(xbeeZB.operating64PAN[3]);
166
USB.printHex(xbeeZB.operating64PAN[4]);
167
USB.printHex(xbeeZB.operating64PAN[5]);
168
USB.printHex(xbeeZB.operating64PAN[6]);
169
USB.printHex(xbeeZB.operating64PAN[7]);
170
USB.println();
171
172
USB.print(F("channel: "));
173
USB.printHex(xbeeZB.channel);
174
USB.println();
175
176
}
Copied!

Output

1
E#
2
Sending BROADCAST packets example
3
4
Joined a network!
5
operating 16-b PAN ID: D27C
6
operating 64-b PAN ID: 84D87D34C4AE4CB1
7
channel: 0B
8
send ok
9
send ok
10
send ok
11
...
Copied!
Last modified 2yr ago