Example for XBeeAPI; a little more involved than XBeeApiSimpleBroadcastExample with report on failure to set up the XBee and on the transmit status of the message.

Dependencies:   XBeeApi XBeeApiSimpleBroadcastExample mbed

Fork of XBeeApiSimpleBroadcastExample by John Bailey

main.cpp

Committer:
johnb
Date:
2014-03-25
Revision:
0:99422855f301
Child:
1:953e5affd67a

File content as of revision 0:99422855f301:

/**
   @file
   @brief Example of using the XBeeApi library to broadcast a message
          This example has a minimum of error checking in order
          to keep the code compact

   @author John Bailey 

   @copyright Copyright 2014 John Bailey

   @section LICENSE
   
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*/

#include "mbed.h"   
#include "xbeeapi.hpp"
 
uint8_t tx_data[] = { 'H', 'E', 'L', 'L', 'O' };

/* TODO: You may need to change these based on the device/connections that you're using */ 
XBeeDevice xbeeDevice( PTA2, PTA1, NC, NC );
   
int main() {
    /* This example will use the blocking API for simplicity */   
    XBeeApiCmdAtBlocking atIf( &xbeeDevice );

    XBeeDevice::XBeeDeviceReturn_t status;

    /* This is the frame we're going to transmit */
    XBeeApiTxFrameEx frame( &xbeeDevice );
        
    /* Get API mode 2 set up - this is a pre-requisit to using other XBeeApi functions.
       This step may not be needed in the case that the XBee has already been configured
       to use Mode 2 and the setting has been stored in NV */
    status = xbeeDevice.setUpApi();

    if( status != XBeeDevice::XBEEDEVICE_OK )
    {
        /* Set the 16-bit source address of this XBee */
        atIf.setSourceAddress( 0x1234 );
        /* Set up a peer-to-peer network using the specified PAN and channel */
        xbeeSetNetworkTypeP2P( &atIf, 1000, 14 );

        /* Set the data pointer & destination address in the transmit frame */
        frame.setDataPtr( tx_data, sizeof( tx_data ) );
        frame.setDestAddr( 0x01 );
        
        xbeeDevice.SendFrame( &frame );    
    }
}