![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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
Diff: main.cpp
- Revision:
- 5:481ec3d3737f
- Parent:
- 4:4c6644fd040b
diff -r 4c6644fd040b -r 481ec3d3737f main.cpp --- a/main.cpp Fri Jun 27 19:18:39 2014 +0000 +++ b/main.cpp Sat Jul 05 16:57:36 2014 +0000 @@ -76,42 +76,48 @@ /* 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 */ - xbeeSetNetworkTypeP2P( &atIf, myPANId, myChannelId ); - - /* Set the data pointer & destination address in the transmit frame */ - frame.setDataPtr( tx_data, sizeof( tx_data ) ); - frame.setDestAddr( frameDestinationAddress ); - - xbeeDevice.SendFrame( &frame ); - - /* Arbitary wait for the TX to occurr. We could poll getMostRecentStatus() - instead of just waiting */ - wait_ms( WAIT_FOR_TX_TIME ); - - pc.printf( "\r\nTX Status: "); - switch( frame.getMostRecentStatus() ) + if( xbeeSetNetworkTypeP2P( &atIf, myPANId, myChannelId ) ) { - case XBeeApiTxFrame::XBEE_API_TX_STATUS_LAST: - /* Didn't receive a response from the XBee indicating - the transmit status */ - pc.printf("No TX confirmation received from XBee"); - break; - case XBeeApiTxFrame::XBEE_API_TX_STATUS_OK: - /* Frame was transmitted OK and at least one other network - node acknowledged it */ - pc.printf("OK"); - break; - case XBeeApiTxFrame::XBEE_API_TX_STATUS_NO_ACK: - /* This means that the message was transmitted by - the XBee but no other nodes on the network acknowledged it. - Could be other nodes are not on the same PAN, channel, etc) */ - pc.printf("No acknowledgement received"); - break; - default: - /* In this example we don't expect a response other than - those explicitly handled above */ - pc.printf("Unexpected response received"); - break; + + /* Set the data pointer & destination address in the transmit frame */ + frame.setDataPtr( tx_data, sizeof( tx_data ) ); + frame.setDestAddr( frameDestinationAddress ); + + xbeeDevice.SendFrame( &frame ); + + /* Arbitary wait for the TX to occurr. We could poll getMostRecentStatus() + instead of just waiting */ + wait_ms( WAIT_FOR_TX_TIME ); + + pc.printf( "\r\nTX Status: "); + switch( frame.getMostRecentStatus() ) + { + case XBeeApiTxFrame::XBEE_API_TX_STATUS_LAST: + /* Didn't receive a response from the XBee indicating + the transmit status */ + pc.printf("No TX confirmation received from XBee"); + break; + case XBeeApiTxFrame::XBEE_API_TX_STATUS_OK: + /* Frame was transmitted OK and at least one other network + node acknowledged it */ + pc.printf("OK"); + break; + case XBeeApiTxFrame::XBEE_API_TX_STATUS_NO_ACK: + /* This means that the message was transmitted by + the XBee but no other nodes on the network acknowledged it. + Could be other nodes are not on the same PAN, channel, etc) */ + pc.printf("No acknowledgement received"); + break; + default: + /* In this example we don't expect a response other than + those explicitly handled above */ + pc.printf("Unexpected response received"); + break; + } + } + else + { + pc.printf("xbeeSetNetworkTypeP2P reported failure\r\n"); } } else