I've used XBee ZNET2.5 modules on a few projects, but only in transparent "AT" mode. This mode is akin to a dial-up modem, where the module is told a destination address and sends ann traffic there until told otherwise. For my next project, I need my XBee modules to function as true network nodes, being able to send and receive packets to any other node at will. The first part of the proejct wil be a simple responder, where a node sends a simple text-based command to another node, which will respond back to the sending node.
Mr. Rapp provides some nice sample sketches for his library, but each sketch only shows a "receive" or a "transmit" configuration. Mr. Rapp's sketches were helpful, but didn't explain how to extract data from a received packet and use the data create a response to the sending node. I spent some time trying to figure out how to receive data packets then respond to the sender, and came up with an Arduino sketch that simply "echoes" received data back to the sending node. It's not very useful, but it does demonstrate the principle and how to get from the library the various pieces of data required to create a response.
I tested the setup using another Series 2 XBeePRO Module (ZNET 2.5) running "Router/End Device AT" firmware (v1247), installed in an Adafruit XBee Adapter kit connected to a terminal emulator, and configured with the API-mode Xbee as its Destination Node (ATDN
The Sketch presumes that "XBee.h" and XBee.cpp" in the same folder with the sketch, rather than in the Arduino Library as Mr. Rapp recommends. This can be changed back to Mr. Rapp recommendation by changing the delimiters in the XBee include line from quotes to the standard "less than" and "greater than".
I have extensively (almost painfully) commented the Sketch heavily to point out what I think is happening in almost every line that has to do with Receive and Transmit Packet handling. I've also tried to point out the "whys" behind the code. I don't promise it's prefect, but I think it's very close. The Sketch is only built to demonstrate Zibgee Receive packets (0x90) and Zigbee Transmit Requests (0x10) and doesn't deal with other packet types.
The sketch is also written to provide addressing and data information about each reeived data packet to a Software Serial port on Arduino Pin D2 at 9600bps. This is leftover code from my investigations but may be useful, so I left it in.
I hope you find this useful.
Thanks to Andrew Rapp for the library and LadyAda for the great parts...
The Arduino Sketch
Click here to obtain the sketch.
Disclaimer. Any and all opinions expressed on this page are solely those of the author. The author accepts no responsibility for the accuracy of data provided on this web site, nor does the author accept any responsibility for the use and /or misuse of information provided on this web site. It is the full and sole responsibility of the user to determine whether and/or how best to use the information provided within their own circumstances, and it is the full and sole responsibility of the user to accept any and all benefits and/or consquences of their actions. Please see my Privacy Policy.