This example shows how to create a Network using Waspmote XBee 900MHz API
File:
"WaspXBee900_1_creatingNetwork.pde"
/*
* ------Waspmote XBee 900MHz Creating a Network Example------
*
* Explanation: This example shows how to create a Network using Waspmote
* XBee 900MHz API
*
* Note: XBee modules must be configured at 38400bps and with API enabled.
*
* Copyright (C) 2009 Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* 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 2 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 .
*
* Version: 0.2
* Design: David Gascón
* Implementation: Alberto Bielsa
*/
uint8_t PANID[2]={0x12,0x34};
char* KEY="WaspmoteKey";
void setup()
{
// Inits the XBee DigiMesh library
xbeeDM.init(XBEE_900,FREQ900M,NORMAL);
// Powers XBee
xbeeDM.ON();
}
void loop()
{
// Chosing a channel : channel 0x0A
xbeeDM.setChannel(0x0A);
if( !xbeeDM.error_AT ) XBee.println("Channel set OK");
else XBee.println("Error while changing channel");
// Chosing a PANID : PANID=0x1234
xbeeDM.setPAN(PANID);
if( !xbeeDM.error_AT ) XBee.println("PANID set OK");
else XBee.println("Error while changing PANID");
// Enabling security : KEY="WaspmoteKey"
xbeeDM.encryptionMode(1);
if( !xbeeDM.error_AT ) XBee.println("Security enabled");
else XBee.println("Error while enabling security");
xbeeDM.setLinkKey(KEY);
if( !xbeeDM.error_AT ) XBee.println("Key set OK");
else XBee.println("Error while setting Key");
// Keep values
xbeeDM.writeValues();
if( !xbeeDM.error_AT ) XBee.println("Changes stored OK");
else XBee.println("Error while storing values");
delay(3000);
}
You can download the code of this example.