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

Revision:
1:953e5affd67a
Parent:
0:99422855f301
Child:
2:a553ea23194b
--- a/main.cpp	Tue Mar 25 18:39:34 2014 +0000
+++ b/main.cpp	Tue Mar 25 20:23:40 2014 +0000
@@ -27,10 +27,29 @@
 #include "mbed.h"   
 #include "xbeeapi.hpp"
  
-uint8_t tx_data[] = { 'H', 'E', 'L', 'L', 'O' };
+const 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 );
+#define XBEE_TX_PIN PTA2
+#define XBEE_RX_PIN PTA1
+
+/* Network address for our XBee */
+const uint16_t myNetworkAddress = 0x1234;
+
+/* ID for the Personal Area Network we're going to join */
+const XBeeApiCmdAt::panId_t myPANId = 1000;
+
+/* Network channel to use */
+const XBeeApiCmdAt::channel_t myChannelId = 14;
+
+/* This example sends a frame to a specific destination address - we could set
+   the frame to be broadcast by calling the setDestAddrBroadcast() method
+   instead of setDestAddr() in the function below.
+   By default 16-bit addressing mode is used.  setDestAddrType can be used
+   to select between 16-bit and 64-bit addressing modes */
+const uint16_t frameDestinationAddress = 0x01;
+
+XBeeDevice xbeeDevice( XBEE_TX_PIN, XBEE_RX_PIN, NC, NC );
    
 int main() {
     /* This example will use the blocking API for simplicity */   
@@ -49,13 +68,13 @@
     if( status != XBeeDevice::XBEEDEVICE_OK )
     {
         /* Set the 16-bit source address of this XBee */
-        atIf.setSourceAddress( 0x1234 );
+        atIf.setSourceAddress( myNetworkAddress );
         /* Set up a peer-to-peer network using the specified PAN and channel */
-        xbeeSetNetworkTypeP2P( &atIf, 1000, 14 );
+        xbeeSetNetworkTypeP2P( &atIf, myPANId, myChannelId );
 
         /* Set the data pointer & destination address in the transmit frame */
         frame.setDataPtr( tx_data, sizeof( tx_data ) );
-        frame.setDestAddr( 0x01 );
+        frame.setDestAddr( frameDestinationAddress );
         
         xbeeDevice.SendFrame( &frame );    
     }