ZB 01a: Coordinator set up
This program shows how to set a new PAN ID to a coordinator.

Required Materials

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

Notes

- To store parameter changes after power cycles, it is needed to execute the "writeValues" function. If not, when the XBee is powered off, values do not remain in the module's memory. - The battery has to be connected. - This example can be executed in Waspmote v12

Code

1
/*
2
------ [ZB_01] - coordinator creates a network --------
3
4
Explanation: This program shows how to set a new PAN ID to a
5
coordinator.
6
7
Copyright (C) 2016 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
/**************************************************
31
IMPORTANT: Beware of the channel selected by the
32
coordinator because routers are not able to scan
33
both 0x19 and 0x1A channels
34
**************************************************/
35
36
37
// coordinator's 64-bit PAN ID to set
38
////////////////////////////////////////////////////////////////////////
39
uint8_t PANID[8] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
40
////////////////////////////////////////////////////////////////////////
41
42
43
void setup()
44
{
45
// init USB
46
USB.ON();
47
USB.println(F("ZB_01 example"));
48
49
50
///////////////////////////////////////////////
51
// Init XBee
52
///////////////////////////////////////////////
53
xbeeZB.ON();
54
delay(1000);
55
56
57
///////////////////////////////////////////////
58
// 1. Set Coordinator Enable
59
///////////////////////////////////////////////
60
61
/*************************************
62
WARNING: Only XBee ZigBee S2C and
63
XBee ZigBee S2D are able to use
64
this function properly
65
************************************/
66
xbeeZB.setCoordinator(ENABLED);
67
68
// check at command flag
69
if (xbeeZB.error_AT == 0)
70
{
71
USB.println(F("1. Coordinator Enabled OK"));
72
}
73
else
74
{
75
USB.println(F("1. Error while enabling Coordinator mode"));
76
}
77
78
79
///////////////////////////////////////////////
80
// 2. Set PANID
81
///////////////////////////////////////////////
82
xbeeZB.setPAN(PANID);
83
84
// check at command flag
85
if (xbeeZB.error_AT == 0)
86
{
87
USB.println(F("2. PANID set OK"));
88
}
89
else
90
{
91
USB.println(F("2. Error while setting PANID"));
92
}
93
94
///////////////////////////////////////////////
95
// 3. Set channels to be scanned before creating network
96
///////////////////////////////////////////////
97
/* Range:[0x0 to 0x3FFF]
98
Channels are scpedified as a bitmap where depending on
99
the bit a channel is selected --> Bit (Channel):
100
0 (0x0B) 4 (0x0F) 8 (0x13) 12 (0x17)
101
1 (0x0C) 5 (0x10) 9 (0x14) 13 (0x18)
102
2 (0x0D) 6 (0x11) 10 (0x15)
103
3 (0x0E) 7 (0x12) 11 (0x16) */
104
xbeeZB.setScanningChannels(0x03, 0xFF);
105
106
// check at command flag
107
if (xbeeZB.error_AT == 0)
108
{
109
USB.println(F("3. Scanning channels set OK"));
110
}
111
else
112
{
113
USB.println(F("3. Error while setting 'Scanning channels'"));
114
}
115
116
///////////////////////////////////////////////
117
// Save values
118
///////////////////////////////////////////////
119
xbeeZB.writeValues();
120
121
// wait for the module to set the parameters
122
delay(10000);
123
USB.println();
124
125
}
126
127
128
void loop()
129
{
130
// get network parameters
131
xbeeZB.getOperating16PAN();
132
xbeeZB.getOperating64PAN();
133
xbeeZB.getChannel();
134
135
USB.print(F("operating 16-bit PAN: "));
136
USB.printHex(xbeeZB.operating16PAN[0]);
137
USB.printHex(xbeeZB.operating16PAN[1]);
138
USB.println();
139
140
USB.print(F("operating 64-bit PAN: "));
141
USB.printHex(xbeeZB.operating64PAN[0]);
142
USB.printHex(xbeeZB.operating64PAN[1]);
143
USB.printHex(xbeeZB.operating64PAN[2]);
144
USB.printHex(xbeeZB.operating64PAN[3]);
145
USB.printHex(xbeeZB.operating64PAN[4]);
146
USB.printHex(xbeeZB.operating64PAN[5]);
147
USB.printHex(xbeeZB.operating64PAN[6]);
148
USB.printHex(xbeeZB.operating64PAN[7]);
149
USB.println();
150
151
USB.print(F("channel: "));
152
USB.printHex(xbeeZB.channel);
153
USB.println();
154
155
delay(3000);
156
}
Copied!

Output

1
E#
2
ZB_01 example
3
PANID set OK
4
operating 16-bit PAN: 7C7A
5
operating 64-bit PAN: 1122334455667788
6
channel: 0D
7
...
Copied!
Last modified 2yr ago