Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: XBeeApiBroadcastExample
main.cpp@0:99422855f301, 2014-03-25 (annotated)
- Committer:
- johnb
- Date:
- Tue Mar 25 18:39:34 2014 +0000
- Revision:
- 0:99422855f301
- Child:
- 1:953e5affd67a
Initial version - simple program to set up an XBee, a P2P network and transmit a frame.
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| johnb | 0:99422855f301 | 1 | /** | 
| johnb | 0:99422855f301 | 2 | @file | 
| johnb | 0:99422855f301 | 3 | @brief Example of using the XBeeApi library to broadcast a message | 
| johnb | 0:99422855f301 | 4 | This example has a minimum of error checking in order | 
| johnb | 0:99422855f301 | 5 | to keep the code compact | 
| johnb | 0:99422855f301 | 6 | |
| johnb | 0:99422855f301 | 7 | @author John Bailey | 
| johnb | 0:99422855f301 | 8 | |
| johnb | 0:99422855f301 | 9 | @copyright Copyright 2014 John Bailey | 
| johnb | 0:99422855f301 | 10 | |
| johnb | 0:99422855f301 | 11 | @section LICENSE | 
| johnb | 0:99422855f301 | 12 | |
| johnb | 0:99422855f301 | 13 | Licensed under the Apache License, Version 2.0 (the "License"); | 
| johnb | 0:99422855f301 | 14 | you may not use this file except in compliance with the License. | 
| johnb | 0:99422855f301 | 15 | You may obtain a copy of the License at | 
| johnb | 0:99422855f301 | 16 | |
| johnb | 0:99422855f301 | 17 | http://www.apache.org/licenses/LICENSE-2.0 | 
| johnb | 0:99422855f301 | 18 | |
| johnb | 0:99422855f301 | 19 | Unless required by applicable law or agreed to in writing, software | 
| johnb | 0:99422855f301 | 20 | distributed under the License is distributed on an "AS IS" BASIS, | 
| johnb | 0:99422855f301 | 21 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
| johnb | 0:99422855f301 | 22 | See the License for the specific language governing permissions and | 
| johnb | 0:99422855f301 | 23 | limitations under the License. | 
| johnb | 0:99422855f301 | 24 | |
| johnb | 0:99422855f301 | 25 | */ | 
| johnb | 0:99422855f301 | 26 | |
| johnb | 0:99422855f301 | 27 | #include "mbed.h" | 
| johnb | 0:99422855f301 | 28 | #include "xbeeapi.hpp" | 
| johnb | 0:99422855f301 | 29 | |
| johnb | 0:99422855f301 | 30 | uint8_t tx_data[] = { 'H', 'E', 'L', 'L', 'O' }; | 
| johnb | 0:99422855f301 | 31 | |
| johnb | 0:99422855f301 | 32 | /* TODO: You may need to change these based on the device/connections that you're using */ | 
| johnb | 0:99422855f301 | 33 | XBeeDevice xbeeDevice( PTA2, PTA1, NC, NC ); | 
| johnb | 0:99422855f301 | 34 | |
| johnb | 0:99422855f301 | 35 | int main() { | 
| johnb | 0:99422855f301 | 36 | /* This example will use the blocking API for simplicity */ | 
| johnb | 0:99422855f301 | 37 | XBeeApiCmdAtBlocking atIf( &xbeeDevice ); | 
| johnb | 0:99422855f301 | 38 | |
| johnb | 0:99422855f301 | 39 | XBeeDevice::XBeeDeviceReturn_t status; | 
| johnb | 0:99422855f301 | 40 | |
| johnb | 0:99422855f301 | 41 | /* This is the frame we're going to transmit */ | 
| johnb | 0:99422855f301 | 42 | XBeeApiTxFrameEx frame( &xbeeDevice ); | 
| johnb | 0:99422855f301 | 43 | |
| johnb | 0:99422855f301 | 44 | /* Get API mode 2 set up - this is a pre-requisit to using other XBeeApi functions. | 
| johnb | 0:99422855f301 | 45 | This step may not be needed in the case that the XBee has already been configured | 
| johnb | 0:99422855f301 | 46 | to use Mode 2 and the setting has been stored in NV */ | 
| johnb | 0:99422855f301 | 47 | status = xbeeDevice.setUpApi(); | 
| johnb | 0:99422855f301 | 48 | |
| johnb | 0:99422855f301 | 49 | if( status != XBeeDevice::XBEEDEVICE_OK ) | 
| johnb | 0:99422855f301 | 50 | { | 
| johnb | 0:99422855f301 | 51 | /* Set the 16-bit source address of this XBee */ | 
| johnb | 0:99422855f301 | 52 | atIf.setSourceAddress( 0x1234 ); | 
| johnb | 0:99422855f301 | 53 | /* Set up a peer-to-peer network using the specified PAN and channel */ | 
| johnb | 0:99422855f301 | 54 | xbeeSetNetworkTypeP2P( &atIf, 1000, 14 ); | 
| johnb | 0:99422855f301 | 55 | |
| johnb | 0:99422855f301 | 56 | /* Set the data pointer & destination address in the transmit frame */ | 
| johnb | 0:99422855f301 | 57 | frame.setDataPtr( tx_data, sizeof( tx_data ) ); | 
| johnb | 0:99422855f301 | 58 | frame.setDestAddr( 0x01 ); | 
| johnb | 0:99422855f301 | 59 | |
| johnb | 0:99422855f301 | 60 | xbeeDevice.SendFrame( &frame ); | 
| johnb | 0:99422855f301 | 61 | } | 
| johnb | 0:99422855f301 | 62 | } |