Simple example of using XBeeApi to send AT-style commands to the XBee

Dependencies:   XBeeApi mbed

Files at this revision

API Documentation at this revision

Comitter:
johnb
Date:
Mon Mar 31 19:57:48 2014 +0000
Parent:
0:b0f8e1a438e0
Commit message:
Update example to write setting as well as reading

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r b0f8e1a438e0 -r 0ee7020a1b90 main.cpp
--- a/main.cpp	Mon Mar 31 19:42:44 2014 +0000
+++ b/main.cpp	Mon Mar 31 19:57:48 2014 +0000
@@ -30,6 +30,8 @@
 #define XBEE_TX_PIN PTA2
 #define XBEE_RX_PIN PTA1
 
+const uint8_t channelNo = 0xd;
+
 Serial pc(USBTX, USBRX); // tx, rx
 
 XBeeDevice xbeeDevice( XBEE_TX_PIN, XBEE_RX_PIN, NC, NC );
@@ -49,6 +51,7 @@
     {
         uint16_t fwVersion;
         uint8_t  chan;
+        uint8_t  newChan;
         
         /* Ask the XBee for the firmware version it's running.
            
@@ -72,7 +75,13 @@
                in the case that we're using the blocking API */
             if( atIf.getChannel( &chan ) )
             {
-                pc.printf("Firmware version: 0x%04x, channel ID 0x%02x",fwVersion,chan);
+                /* Change the channe ID to something new */
+                atIf.setChannel( channelNo );
+
+                /* Retrieve the channel ID again, after we've changed it */
+                atIf.getChannel( &newChan );
+                
+                pc.printf("Firmware version: 0x%04x\r\nOriginal channel ID 0x%02x, new channel ID 0x%02x",fwVersion,chan,newChan); 
             }
             else
             {