I've had quite a few people getting in contact asking for support with the initial setup and configuration of libxbee. As a result, I felt that it would be worthwhile writing this guide. libxbee is very straight forward, once you understand the principals involved.
It is expected that you have read and understood the samples section before reading this page.
All communications within libxbee are connection-oriented. A connection can be thought of as a queue that is dedicated to a specific type of connection and a specific remote endpoint. The purpose of a connection is so that the data will be collected for you, and so that it is easy to subsequently transmit data - you don't have to keep providing the addressing information.
If you think that you want to deal with connection-less data... you don't.
In fact what you probably want is a
catch all connection that will collect any connection-less packets for a given connection type.
Unless your catch all connection is also a broadcast connection, it makes no sense to try transmitting data using it.
The prototype for
xbee_conNew() is shown below:
|xbee_err xbee_conNew(||struct xbee *xbee,|
|struct xbee_con **retCon,|
|const char *type,|
|struct xbee_conAddress *address);|
address parameters are the intersting ones that will be discussed here.
Other information about
xbee_conNew() can be found in its man page, or the online man page.
The connection types that are available depend from mode to mode. To identify what connection types a given mode supports, you can do one of a few things:
The following sample code will give you a list of the supported connection types for the chosen mode.
Download the source: get_conTypes.c
This is probably more information than the average user wants to know - Show/Hide.
libxbee's source is laid out very nicely.
If you know what mode you are using (which you should), you can use the following path template:
If you're using the
xbee1 mode, this would resolve to
Now that you've found the mode's main file, you need to search for the
struct xbee_mode definition.
It'll look something like this:
Each of these elements will relate to a
struct xbee_modeConType definition, that will in turn contain the name of the connection type.
For example the
xbee_s1_64bitData type is named
Good question! It's fairly straight forward - the struct is shown below.
As you have hopefully picked up from the samples, you must set the
*_enabled flags to make libxbee pay attention to the various sections of the struct.
addr64 values, the Most Significant Byte goes into index zero.
So to connect to an XBee that has a 64-bit address of 0x0013A200 0x40081826, you would write the following:
For some of the more complex modes (such as
xbeeZB) you may have multiple sections of the address struct enabled.
A call to
xbee_conNew() will fail if you have provided invalid information.
Addresses are always left-aligned.
For example, if you're using a WiFi module (and therefore want to enter a 32-bit IP address), you should use the first 4 bytes of
The IP address 192.168.0.15 would be entered like so: