24 September 2012

Simple XBee ZB (Series 2) P2P Communications

Some folks have difficulty using the XBee Series 2 modules (now called XBee ZB) for simple point-to-point communication in transparent (AT) mode. For this reason, the XBee Series 1 modules (now called XBee 802.15.4) are often recommended for simple P2P applications, with the S2 modules being considered "too complicated".

I disagree with this recommendation because the XBee ZB modules are more capable (and are perfectly capable of simple P2P communication), their radios are a little better than the XBee 802.15.4 modules (both in transmitter power and receiver sensitivity) and they even cost a couple bucks less. With a pair of ZB modules, if you ever want to try mesh networking with three or more nodes, there's nothing else you need to do (except to buy more modules).

The downside is that the XBee ZB modules do require some configuration to establish a P2P link. (I have not experimented with the XBee 802.15.4 modules myself, and I have heard conflicting stories regarding whether a pair can be used as a P2P link "out of the box" without further configuration.)

Getting to the point, I was discussing an XBee ZB issue on the Arduino forum the other day, when I hit on what I think is the minimal amount of configuration required to establish a point-to-point, transparent mode (AT) link with two brand-new XBee ZB modules right out of the box.

First, two assumptions. One, we assume that the modules come from the factory with the Router AT firmware loaded. I think this is a pretty good assumption, all the ZB modules that I have came this way (and BTW, the interface speed is set to 9600 baud). Two, we assume that there are no other XBee networks operating nearby. This is probably a good assumption for folks with their first pair of XBees, but more on that later in case it's not a good assumption for you.

It turns out that there is only one step required to get the new pair of XBee ZBs talking! Using Digi's X-CTU program, load the Coordinator AT firmware on one of the two modules. (Every XBee ZB network needs to have exactly one coordinator, so the first thing when setting up a network is to satisfy this basic requirement anyway.)

This works because the modules' default value of zero for the network ID (PAN ID) causes the coordinator to select a random PAN ID and causes the router to join any PAN ID available. Hence there is a potential issue if there is already another XBee network operating, the router may join it instead of talking to the new coordinator. If this is the case, then there is an additional step: The PAN ID for both units needs to be set to some non-zero value different from that of the other network(s). I like to always set the PAN ID anyway, since what passes for normal around here seems to be a minimum of two separate XBee ZB networks in simultaneous operation, but if you just have that first pair of modules, then more than likely you don't have to worry about it (unless your neighbor hasn't come out of the closet about his XBee addiction).

The other thing that makes this work is that the default destination address (DH and DL parameters) will be zero for the router and 0x000000000000FFFF for the coordinator. Zero is a special address that causes the router to send its traffic to the coordinator. 0x000000000000FFFF is also a special address called the broadcast address. This means that the coordinator will send to every other node on the network.

To broadcast or not to broadcast

As it turns out, using the broadcast address is OK for a simple demonstration with two nodes, but in general, broadcast transmissions should be used sparingly because they cause a lot of network overhead, and this can be significant on larger networks. In the case of two nodes, it's easy enough to avoid and just have the coordinator address its traffic directly to the router. First determine the router's 64-bit (16 hex digit) address. In X-CTU, it's the SH (Serial number High) and SL (Serial number Low) parameters. It's also printed on the label on the bottom of each XBee. SH and SL are each 8 hex digits, and the high part will always be 0x0013A200 for XBees made by Digi International. The low part will be a unique number, for instance 0x406B85A5. Next, connect the coordinator to X-CTU and set its Destination address High (DH) and Destination address Low (DL) to be the router's address. This will cause all transmissions from the coordinator to be unicast transmissions rather than broadcast, and to be directed to the router.

Well this post ended up a bit longer than I thought it would. I hope you stuck in there, and I hope it was useful. I hope to expand on this in another post at a later date, with more details regarding loading firmware, setting parameters, and connecting the XBees, but I wanted to get the thought out there for now. Happy networking!

7 comments:

  1. I found that your post is very impressive. Can you tell me about more the working process of XBee cheat sheet in Linux?

    ReplyDelete
    Replies
    1. Smith, thanks for your comment. I'm afraid I don't know much about Linux (yet). Looking at that XBee cheat sheet, it doesn't seem to be specific to any particular OS. I rely on Digi International's X-CTU utility pretty heavily for configuring and testing XBees. Unfortunately it only runs on Windows. If I didn't have a Windows machine, I might look into a VM, or Wine (www.winehq.org), etc.

      HTH. I frequent the Arduino forum or hit me up on G+ if I can be of further assistance.

      Delete
    2. FYI I have been using the moltosenso Network Manager Iron edition on my linux machine and it has been working great for configuring xBees.

      Delete
  2. Hi Jack, Nice article. I'm surprised that a number of people haven't asked which coordinator software should be loaded. I had that problem on my first set of XBees. I didn't know to read the device first to get the modem type and then load the software accordingly. Drove me nuts for a day or so. When a newbie like me gets hold of XCTU, its lack of documentation can drive him nuts.

    It's almost second nature now, but I still flounder a bit when I try to do something new.

    ReplyDelete
    Replies
    1. Dave, thanks, you make a good point. I'm also in the habit of reading the device back frequently to double-check changes that I've made.

      Delete
  3. Hi,
    I would like to ask, If I have 5 routers and 2 of the routers are in some place where it cannot communicate directly with the coordinator. Do I need to change the SL & SH address to the nearby router?

    thank you

    ReplyDelete
    Replies
    1. SL & SH are read-only, they cannot be changed. The mesh networking should take care of things, though, as long as those 2 routers can communicate with other routers that are within range of the coordinator.

      Delete