libxbee OS X FreeBSD Windows Linux



libxbee started as a small library for myself, but quickly grew. I also noticed that there are seemingly no other XBee interface libraries available for C (there are a handful for other languages and platforms - python-xbee for Python, xbee-arduino for Arduino, etc...).

If you find libxbee useful, then I would really appreciate a donation. Please feel free to use the PayPal button to the right.

Links

Overview

libxbee has been developed with a connection oriented approach. Initially you configure an interface with an XBee module, and then setup connections of varying types to remote nodes. It is then very simple to send and receive data for a given connection. Advanced features such as connection specific callbacks and user-defined data association allow your application to maintain low latencies, without the potentially large overhead of polling a connection. As has been proven recently (with the addition of support for Digi's Series 5 and Series 2 ZigBee modules), the architecture is well thought out and allows for easy extension.

Functionality

An overview of the functionality provided by libxbee3 is given here. If you would like information on previous versions, please visit the history page.

libxbee v3

Development period: Feb 2012 - ongoing
Git repository: GitHub | Bitbucket
Binary releases: Download from Google Drive
Features:
  • Licensed using LGPLv3
  • Full support for XBee Series 1, 2 (ZigBee), 2.5 (ZNet), 3, 5 and 6B (WiFi) modules
  • ZDO support library in development (for use with Series 2 modules)
  • Tx status reporting
  • TCP/IP interface sharing
  • Sample code and applications
  • Man page documentation
  • HTML documentation (http://doc.libxbee.attie.co.uk/)
  • Support site (here!)
  • C++ interface class
  • Linux, Windows, FreeBSD and OS X support

Example

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #include <xbee.h>
  6.  
  7. void myCB(struct xbee *xbee, struct xbee_con *con, struct xbee_pkt **pkt, void **data) {
  8.   if ((*pkt)->dataLen <= 0) return;
  9.  
  10.   /* tell the observer what we received */
  11.   printf("rx: [%s]\n", (*pkt)->data);
  12.  
  13.   /* return the message to the other XBee */
  14.   printf("tx: %d\n", xbee_connTx(con, NULL, (*pkt)->data, (*pkt)->dataLen));
  15. }
  16.  
  17. int main(void) {
  18.   struct xbee *xbee;
  19.   struct xbee_con *con;
  20.   struct xbee_conAddress address;
  21.  
  22.   /* setup libxbee, using a Series 1 XBee, on /dev/ttyUSB0, at 57600 baud */
  23.   xbee_setup(&xbee, "xbee1", "/dev/ttyUSB0", 57600);
  24.  
  25.   /* setup a 64-bit address */
  26.   memset(&address, 0, sizeof(address));
  27.   address.addr64_enabled = 1;
  28.   address.addr64[0] = 0x00;
  29.   address.addr64[1] = 0x13;
  30.   address.addr64[2] = 0xA2;
  31.   address.addr64[3] = 0x00;
  32.   address.addr64[4] = 0x40;
  33.   address.addr64[5] = 0x08;
  34.   address.addr64[6] = 0x18;
  35.   address.addr64[7] = 0x26;
  36.  
  37.   /* create a 64-bit data connection with the address */
  38.   xbee_conNew(xbee, &con, "64-bit Data", &address);
  39.  
  40.   /* setup a callback to keep both the system load and response time low */
  41.   xbee_conCallbackSet(con, myCB, NULL);
  42.  
  43.   /* sleep for a minute! */
  44.   sleep(60);
  45.  
  46.   /* close the connection */
  47.   xbee_conEnd(con);
  48.  
  49.   /* shutdown libxbee */
  50.   xbee_shutdown(xbee);
  51.  
  52.   return 0;
  53. }