API for communicating with XBee devices.

Dependencies:   CircularBuffer FixedLengthList

Dependents:   XBeeApiTest XBeeApiSimpleATCmdsExample XBeeApiBroadcastExample XBeeApiBroadcastExampleRTOS ... more

Overview

XBeeApi is intended to be a library for providing a high-level API interface to the XBee - for example getChannel() and setChannel(2) methods rather than needing to send( "ATCH" ) and send( "ATCH 2" ) - and then de-code the responses.

See the notebook page here for a description of how the API works & some details on the various classes.

Features:

  • Support for transmission & reception of data packets
  • Support for reading & changing settings
  • Support for "Remote AT" interface to access settings & I/O channels on remote XBees
  • XBeeApi should work if you're using mbed-rtos, though it is not currently threadsafe. Take a look at the XBeeApiBroadcastExampleRTOS example if you're including mbed-rtos.

Example Programs

There are also example programs available:

Transmit

Import programXBeeApiSimpleBroadcastExample

Simple example of how to use XBeeApi - set up the XBee, configure P2P networking then transmit a frame.

Import programXBeeApiBroadcastExample

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.

Import programXBeeApiBroadcastExampleRTOS

Example of using the XBeeApi library to broadcast a message, based on XBeeApiBroadcastExample. This example shows how to use the library when using mbed-rtos. Before compiling you must open "XbeeApi\Config\XBeeApiCfg.hpp" and change the '#if 0' to '#if 1' on the line above the comment reading "Use RTOS features to make XBeeApi threadsafe"

Settings/Status

Import programXBeeApiSimpleATCmdsExample

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

Import programXBeeApiRemoteATCmdsExample

Example of using the XBeeApi library to send AT commands to remote XBee devices in order to read/write settings

Receive

Import programXBeeApiSimpleReceiveExample

Simple example of using XBeeApi to receive data packets via wireless

Import programXBeeApiReceiveCallbackExample

Example of using the XBeeApi library to receive a message via a callback method

Import programXBeeApiReceiveCallbackExampleRTOS

Example of using the XBeeApi library to receive a message via a callback method. This example shows how to use the library when using mbed-rtos. See the comment at the top of main.cpp

Remote I/O

Import programXBeeApiRemoteIOExample

Example of using the XBeeApi library to read inputs on a remote XBee

If you have 2 mbed connected XBees available then you can use XBeeApiSimpleReceiveExample and XBeeApiSimpleBroadcastExample as a pair.

Note that this is still a work in progress! XBeeApiTodoList tracks some of the functionality still to be added.

Files at this revision

API Documentation at this revision

Comitter:
johnb
Date:
Sat Jul 05 15:33:04 2014 +0000
Parent:
40:b96e8cad93d3
Child:
42:81c789ba4c08
Commit message:
Change from Serial to RawSerial so that the library is RTOS friendly.

Changed in this revision

Base/XBeeDevice.cpp Show annotated file Show diff for this revision Revisions of this file
Base/XBeeDevice.hpp Show annotated file Show diff for this revision Revisions of this file
--- a/Base/XBeeDevice.cpp	Sat Jul 05 14:59:07 2014 +0000
+++ b/Base/XBeeDevice.cpp	Sat Jul 05 15:33:04 2014 +0000
@@ -51,7 +51,7 @@
 {    
     init();
     
-    m_if = new Serial( p_tx, p_rx ); 
+    m_if = new RawSerial( p_tx, p_rx ); 
 
     /* Can only do flow control on devices which support it */
 #if defined ( DEVICE_SERIAL_FC )
@@ -63,7 +63,7 @@
     m_if->attach( this, &XBeeDevice::if_rx, Serial::RxIrq); 
 }
 
-XBeeDevice::XBeeDevice( Serial* p_serialIf ): m_if( p_serialIf ),
+XBeeDevice::XBeeDevice( RawSerial* p_serialIf ): m_if( p_serialIf ),
                                               m_serialNeedsDelete( true )
 {    
     init();
@@ -263,7 +263,6 @@
     /* Checksum is 0xFF - summation of bytes (excluding delimiter and length) */
     xbeeWrite( (uint8_t)0xFFU - sum );
     
-    fflush( *m_if );
 #if defined XBEE_DEBUG_DEVICE_DUMP_MESSAGE_DECODE
     m_if.printf("\r\n");
 #endif
@@ -321,8 +320,6 @@
             m_if->putc(p_dat[i]);
         }
         
-        fflush( *m_if );
-                
         wait_ms( p_wait_ms );
                 
         /* Check the response for the OK indicator */
--- a/Base/XBeeDevice.hpp	Sat Jul 05 14:59:07 2014 +0000
+++ b/Base/XBeeDevice.hpp	Sat Jul 05 15:33:04 2014 +0000
@@ -74,8 +74,9 @@
      next incoming byte needs to be un-escaped) */
      uint16_t m_rxMsgLastWasEsc;
    
-     /** Serial interface for the XBee comms */
-     Serial* m_if;
+     /** Serial interface for the XBee comms
+         Use RawSerial rather than Serial so that we're OK if the RTOS is used */
+     RawSerial* m_if;
      
      /** Flag to indicate if the Serial object m_if was created by this class and
          hence needs deleting in the destructor */
@@ -150,7 +151,7 @@
                            The referenced object must remain valid for as long as the XBeeDevice object is
                            being used.  Must not be NULL.
      */
-     XBeeDevice( Serial* p_serialIf );
+     XBeeDevice( RawSerial* p_serialIf );
 
      /** Destructor */
      virtual ~XBeeDevice( void );