XBEE 802.15.4 

Example

: Getting RSSI

This example shows how to get RSSI after receiving a packet


File:
"WaspXBee802_3_gettingRSSI.pde"


Code



/*
 *  ------Waspmote XBee 802.15.4 Getting RSSI Example------
 *
 *  Explanation: This example shows how to get RSSI after receiving a packet
 *
 *  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
 */

long previous=0;
uint8_t state=0;
uint8_t g=0;

void setup()
{
  // Inits the XBee 802.15.4 library
  xbee802.init(XBEE_802_15_4,FREQ2_4G,NORMAL);

  // Powers XBee
  xbee802.ON();
}

void loop()
{
  // Waiting message
  previous=millis();
  while( (millis()-previous) < 20000 )
  {
    if( XBee.available() )
    {
      xbee802.treatData();
      if( !xbee802.error_RX )
      {
        while(xbee802.pos>0)
        {
          XBee.print("RSSI: ");
          XBee.print(xbee802.packet_finished[xbee802.pos-1]->RSSI,HEX);
          free(xbee802.packet_finished[xbee802.pos-1]);
          xbee802.packet_finished[xbee802.pos-1]=NULL;
          xbee802.pos--;
        }
      }
    }
  }

  // Getting RSSI using the API function
  xbee802.getRSSI();
  if( !xbee802.error_AT ){
    XBee.print("RSSI: ");
    XBee.println(xbee802.valueRSSI[0],HEX);
  }
}
 

Download code

You can download the code of this example.


© Libelium Comunicaciones Distribuidas S.L.

| Terms of use