Development v12

Warning - Product Update

All the resources present on this section belong to Waspmote v12, Waspmote Plug & Sense! v12 and Meshlium v3.8.

If you have a Waspmote v15, Waspmote Plug & Sense! v15 or Meshlium v4.0 please go to the new Development Section.

Check what is your version and what are the differences between the old and the new one in this document.

» 868 01: Configure XBee

This program shows how to set the basic networking parameters to a XBee module.

Required Materials

1 x Waspmote
1 x Battery
1 x MiniUSB wire
1 x XBee-868

Notes

- The XBee module must be configured to the default baud rate (BD=7) and AP parameter (AP=2).
- 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.
- This example can be executed in Waspmote v12 and Waspmote v15

Code

/*  
 *  ------ [868_01] - configure basic XBee parameters -------- 
 *  
 *  Explanation: This program shows how to set the basic networking
 *  parameters to a XBee module.
 *  
 *  Copyright (C) 2015 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 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 <http://www.gnu.org/licenses/>. 
 *  
 *  Version:           0.2
 *  Design:            David Gascón 
 *  Implementation:    Yuri Carmona
 */

#include <WaspXBee868.h>

// PAN (Personal Area Network) Identifier
uint8_t  panID[2] = {0x12,0x34}; 

// Define the Encryption mode: 1 (enabled) or 0 (disabled)
uint8_t encryptionMode = 0;

// Define the AES 16-byte Encryption Key
char  encryptionKey[] = "WaspmoteLinkKey!"; 


void setup()
{
  // open USB port
  USB.ON();

  USB.println(F("-------------------------------"));
  USB.println(F("Configure XBee 868"));
  USB.println(F("-------------------------------"));

  // init XBee 
  xbee868.ON();


  /////////////////////////////////////
  // 1. set PANID
  /////////////////////////////////////
  xbee868.setPAN( panID );

  // check the AT commmand execution flag
  if( xbee868.error_AT == 0 ) 
  {
    USB.print(F("1. PAN ID set OK to: 0x"));
    USB.printHex( xbee868.PAN_ID[0] ); 
    USB.printHex( xbee868.PAN_ID[1] ); 
    USB.println();
  }
  else 
  {
    USB.println(F("1. Error calling 'setPAN()'"));  
  }

  /////////////////////////////////////
  // 2. set encryption mode (1:enable; 0:disable)
  /////////////////////////////////////
  xbee868.setEncryptionMode( encryptionMode );

  // check the AT commmand execution flag
  if( xbee868.error_AT == 0 ) 
  {
    USB.print(F("2. AES encryption configured (1:enabled; 0:disabled):"));
    USB.println( xbee868.encryptMode, DEC );
  }
  else 
  {
    USB.println(F("2. Error calling 'setEncryptionMode()'"));
  }

  /////////////////////////////////////
  // 3. set encryption key
  /////////////////////////////////////
  xbee868.setLinkKey( encryptionKey );

  // check the AT commmand execution flag
  if( xbee868.error_AT == 0 ) 
  {
    USB.println(F("3. AES encryption key set OK"));
  }
  else 
  {
    USB.println(F("3. Error calling 'setLinkKey()'")); 
  }

  /////////////////////////////////////
  // 4. write values to XBee module memory
  /////////////////////////////////////
  xbee868.writeValues();

  // check the AT commmand execution flag
  if( xbee868.error_AT == 0 ) 
  {
    USB.println(F("4. Changes stored OK"));
  }
  else 
  {
    USB.println(F("4. Error calling 'writeValues()'"));   
  }

  USB.println(F("-------------------------------")); 
}



void loop()
{

  /////////////////////////////////////
  // 1. get PANID
  /////////////////////////////////////
  xbee868.getPAN();
  USB.print(F("panid: "));
  USB.printHex(xbee868.PAN_ID[0]); 
  USB.printHex(xbee868.PAN_ID[1]); 
  USB.println(); 

  /////////////////////////////////////
  // 2. get encryption mode (1:enable; 0:disable)
  /////////////////////////////////////
  xbee868.getEncryptionMode();
  USB.print(F("encryption mode: "));
  USB.printHex(xbee868.encryptMode);
  USB.println(); 

  USB.println(F("-------------------------------")); 

  delay(3000);
}

Output

H#
-------------------------------
Configure XBee 868
-------------------------------
1. PAN ID set OK to: 0x1234
2. AES encryption configured (1:enabled; 0:disabled):0
3. AES encryption key set OK
4. Changes stored OK
-------------------------------
panid: 1234
encryption mode: 00
-------------------------------
panid: 1234
encryption mode: 00
-------------------------------

Quick Publish: