Simple example of using XBeeApi to receive data packets via wireless

Dependencies:   XBeeApi mbed

Revision:
2:34b3b5b1f01d
Parent:
1:36ac23927246
diff -r 36ac23927246 -r 34b3b5b1f01d main.cpp
--- a/main.cpp	Wed Apr 02 21:45:08 2014 +0000
+++ b/main.cpp	Tue Jul 08 20:26:40 2014 +0000
@@ -33,6 +33,9 @@
 #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;
 
@@ -74,32 +77,35 @@
 
     if( status == XBeeDevice::XBEEDEVICE_OK )
     {
+        /* Set the 16-bit source address of this XBee */
+        atIf.setSourceAddress( myNetworkAddress );
+
         /* Set up a peer-to-peer network using the specified PAN and channel */
         if( xbeeSetNetworkTypeP2P( &atIf, myPANId, myChannelId ) )
-    {
-        const XBeeApiRxFrame* frameP;
-        while( 1 )
         {
-            /* Wait for a while, report how many frames are in the buffer then clear
-               clear the buffer out for the next loop around */
-            wait(10);
-
-            pc.printf("Received frames: %d\r\n",rxBuffer.getFrameCount() );
-
-            /* Work through all of the frames in the buffer */
-            while( NULL != ( frameP = rxBuffer.getTailPtr()))
+            const XBeeApiRxFrame* frameP;
+            while( 1 )
             {
-                /* Dump out some information from the frame */
-                dumpFrame( frameP );
-                /* Remove the frame from the buffer */
-                rxBuffer.pop();
-            }   
+                /* Wait for a while, report how many frames are in the buffer then clear
+                   clear the buffer out for the next loop around */
+                wait(10);
+    
+                pc.printf("Received frames: %d\r\n",rxBuffer.getFrameCount() );
+    
+                /* Work through all of the frames in the buffer */
+                while( NULL != ( frameP = rxBuffer.getTailPtr()))
+                {
+                    /* Dump out some information from the frame */
+                    dumpFrame( frameP );
+                    /* Remove the frame from the buffer */
+                    rxBuffer.pop();
+                }   
+            }
         }
-    }
-    else
-    {
-            pc.printf("xbeeSetNetworkTypeP2P failed\r\n");
-    }
+        else
+        {
+                pc.printf("xbeeSetNetworkTypeP2P failed\r\n");
+        }
     }
     else
     {