John Bailey
/
XBeeApiSimpleReceiveExample
Simple example of using XBeeApi to receive data packets via wireless
Revision 2:34b3b5b1f01d, committed 2014-07-08
- Comitter:
- johnb
- Date:
- Tue Jul 08 20:26:40 2014 +0000
- Parent:
- 1:36ac23927246
- Commit message:
- Set the XBee's 16-bit address
Changed in this revision
XBeeApi.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 36ac23927246 -r 34b3b5b1f01d XBeeApi.lib --- a/XBeeApi.lib Wed Apr 02 21:45:08 2014 +0000 +++ b/XBeeApi.lib Tue Jul 08 20:26:40 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/johnb/code/XBeeApi/#291aee9eb900 +http://mbed.org/users/johnb/code/XBeeApi/#37bba77ee73f
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 {