ZB 01b: Coordinator reset
This program shows how to set reset a network from the coordinator. After reseting the network a new PAN ID is set.

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_01b] - coordinator resets network --------
3
4
Explanation: This program shows how to set reset a network
5
from the coordinator. After reseting the network a new PAN ID
6
is set.
7
8
Copyright (C) 2016 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
31
/**************************************************
32
IMPORTANT: Beware of the channel selected by the
33
coordinator because routers are not able to scan
34
both 0x19 and 0x1A channels
35
**************************************************/
36
37
38
// coordinator's 64-bit PAN ID to set
39
//////////////////////////////////////////////////////////////////
40
uint8_t PANID[8] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
41
//////////////////////////////////////////////////////////////////
42
43
44
void setup()
45
{
46
// init USB
47
USB.ON();
48
USB.println(F("ZB_01b example"));
49
50
51
///////////////////////////////////////////////
52
// Init XBee
53
///////////////////////////////////////////////
54
xbeeZB.ON();
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. Reset network before setting the new PAN ID
81
//////////////////////////////////////////////////
82
83
// 2.1. reset network
84
xbeeZB.resetNetwork(0x01);
85
86
// 2.2. check AT command flag
87
if (xbeeZB.error_AT == 0)
88
{
89
USB.println(F("2. Reset network before setting the new PAN ID --> OK"));
90
}
91
else
92
{
93
USB.println(F("2. Error while resetting network"));
94
}
95
96
// 2.3. wait for the reset
97
delay(5000);
98
99
100
//////////////////////////////////////////////////
101
// 3. set the new PAN ID
102
//////////////////////////////////////////////////
103
104
// 3.1. set PANID
105
xbeeZB.setPAN(PANID);
106
107
// 3.2. check AT command flag
108
if (xbeeZB.error_AT == 0)
109
{
110
USB.println(F("3. PANID set OK"));
111
}
112
else
113
{
114
USB.println(F("3. Error while setting PANID"));
115
}
116
117
// 3.3. save values
118
xbeeZB.writeValues();
119
120
// 3.4. wait for the module to set the parameters
121
delay(10000);
122
USB.println();
123
124
}
125
126
127
void loop()
128
{
129
//////////////////////////////////////////////////
130
// 3. get network parameters
131
//////////////////////////////////////////////////
132
133
xbeeZB.getOperating16PAN();
134
xbeeZB.getOperating64PAN();
135
xbeeZB.getChannel();
136
137
USB.print(F("operating 16-bit PAN: "));
138
USB.printHex(xbeeZB.operating16PAN[0]);
139
USB.printHex(xbeeZB.operating16PAN[1]);
140
USB.println();
141
142
USB.print(F("operating 64-bit PAN: "));
143
USB.printHex(xbeeZB.operating64PAN[0]);
144
USB.printHex(xbeeZB.operating64PAN[1]);
145
USB.printHex(xbeeZB.operating64PAN[2]);
146
USB.printHex(xbeeZB.operating64PAN[3]);
147
USB.printHex(xbeeZB.operating64PAN[4]);
148
USB.printHex(xbeeZB.operating64PAN[5]);
149
USB.printHex(xbeeZB.operating64PAN[6]);
150
USB.printHex(xbeeZB.operating64PAN[7]);
151
USB.println();
152
153
USB.print(F("channel: "));
154
USB.printHex(xbeeZB.channel);
155
USB.println();
156
157
delay(3000);
158
}
Copied!

Output

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