------ [ZB_02b] - router joins an unknown coordinator --------
Explanation: This program shows how to search for a new coordinator
when network parameters are unknown. It is necessary to scan a new
coordinator setting different channels to be scanned
Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Implementation: Yuri Carmona
// PAN ID to set in order to search a new coordinator
uint8_t PANID[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
USB.println(F("ZB_02b example"));
///////////////////////////////////////////////
///////////////////////////////////////////////
///////////////////////////////////////////////
// 1. Disable Coordinator mode
///////////////////////////////////////////////
/*************************************
WARNING: Only XBee ZigBee S2C and
XBee ZigBee S2D are able to use
************************************/
xbeeZB.setCoordinator(DISABLED);
if (xbeeZB.error_AT == 0)
USB.println(F("1. Coordinator mode disabled"));
USB.println(F("1. Error while disabling Coordinator mode"));
///////////////////////////////////////////////
// 2. Dissociation process
///////////////////////////////////////////////
/////////////////////////////////////
// 2.1. Set PANID: 0x0000000000000000
/////////////////////////////////////
if (xbeeZB.error_AT == 0)
USB.println(F("2.1. PANID set OK"));
USB.println(F("2.1. Error while setting PANID"));
/////////////////////////////////////
// 2.2. set all possible channels to scan
/////////////////////////////////////
// channels from 0x0B to 0x18 (0x19 and 0x1A are excluded)
Channels are scpedified as a bitmap where depending on
the bit a channel is selected --> Bit (Channel):
0 (0x0B) 4 (0x0F) 8 (0x13) 12 (0x17)
1 (0x0C) 5 (0x10) 9 (0x14) 13 (0x18)
2 (0x0D) 6 (0x11) 10 (0x15)
3 (0x0E) 7 (0x12) 11 (0x16) */
xbeeZB.setScanningChannels(0x3F, 0xFF);
if ( xbeeZB.error_AT == 0 )
USB.println(F("2.2. Scanning channels set OK"));
USB.println(F("2.2. Error while setting 'Scanning channels'"));
/////////////////////////////////////
// 2.3. Set channel verification JV=1
// in order to make the module to scan
/////////////////////////////////////
xbeeZB.setChannelVerification(1);
if ( xbeeZB.error_AT == 0 )
USB.println(F("2.3. Verification channel set OK"));
USB.println(F("2.3. Error while setting verification channel"));
///////////////////////////////////////////////
///////////////////////////////////////////////
///////////////////////////////////////////////
///////////////////////////////////////////////
/////////////////////////////////////
// 3. Wait for Association
/////////////////////////////////////
// Wait for association indication
xbeeZB.getAssociationIndication();
while ( xbeeZB.associationIndication != 0 )
// get operating 64-b PAN ID
xbeeZB.getOperating64PAN();
USB.print(F("Operating 64-b PAN ID: "));
USB.printHex(xbeeZB.operating64PAN[0]);
USB.printHex(xbeeZB.operating64PAN[1]);
USB.printHex(xbeeZB.operating64PAN[2]);
USB.printHex(xbeeZB.operating64PAN[3]);
USB.printHex(xbeeZB.operating64PAN[4]);
USB.printHex(xbeeZB.operating64PAN[5]);
USB.printHex(xbeeZB.operating64PAN[6]);
USB.printHex(xbeeZB.operating64PAN[7]);
xbeeZB.getAssociationIndication();
USB.println(F("\n\nJoined a coordinator!"));
// 2.2. When XBee is associated print all network
// parameters unset channel verification JV=0
xbeeZB.setChannelVerification(0);
// 2.3. get network parameters
xbeeZB.getOperating16PAN();
xbeeZB.getOperating64PAN();
USB.print(F("Operating 16-b PAN ID: "));
USB.printHex(xbeeZB.operating16PAN[0]);
USB.printHex(xbeeZB.operating16PAN[1]);
USB.print(F("Operating 64-b PAN ID: "));
USB.printHex(xbeeZB.operating64PAN[0]);
USB.printHex(xbeeZB.operating64PAN[1]);
USB.printHex(xbeeZB.operating64PAN[2]);
USB.printHex(xbeeZB.operating64PAN[3]);
USB.printHex(xbeeZB.operating64PAN[4]);
USB.printHex(xbeeZB.operating64PAN[5]);
USB.printHex(xbeeZB.operating64PAN[6]);
USB.printHex(xbeeZB.operating64PAN[7]);
USB.print(F("Channel: "));
USB.printHex(xbeeZB.channel);