XBee Device Shared Methods
These methods are shared among XBee Devices. They will run on any XBee Device in the system, whether it's wired or wirelessly connected. For most systems, one won't need to use these methods, as the default configuration set up by the Virtual Wiring system works well. These methods are good for doing lower level device configuration, control and monitoring, and they are useful if you want to learn more about how XBees work. You can run these methods within your Scripts or from the Console.
AT Command Set Methods
AT commands are for probing and configuring the XBee network, checking signal strength and integrity, reading and writing the digital I/O pins, configuring the digital and analog input pins, setting up sampling, resetting individual devices and the network, and configuring the serial interfaces. See the XBee module reference manual for details on the command set.
The do_AT method runs an XBee "AT" command and returns the result. It takes the AT command to run as its first parameter. Any following parameters are the parameters that the AT command uses. The result value is an array, where the first byte is the AT command status (0 means OK), and the following bytes are the value returned by the command. For more information on the AT command status bytes, see the XBee module reference manual.
As an example, the AT "NI" command returns the "node identifier" of an XBee device or, if a string is provided, sets the node identifier of the device. To read the node identifier of a device with the ID "coordinator" from the Console:
If the node identfier were "XSTICK", the return value would be:
The return array starts with 0, the command was OK, and six bytes of ASCII characters meaning: 'X', 'S', 'T', 'I', 'C', 'K'. To change the name of the "coordinator" from "XSTICK" to "COORDINATOR":
The console returns:
The write_AT method is similar to the do_AT method, except that it returns immediately without waiting for the result of its AT command. The method is useful if the result will be slow, as in a node discover(ND) command, or if you want to see a result pretty printed by the system's packet parser. If the write_AT command succeeds, its return value will be something other than
Here, instead of running the do_AT command to learn a node's identifier, we'll run the write_AT command:
We can see that the result of the write_AT command (16) is not
When the result of the NI command does come back from the XBee, it will be sent to the Log. If we go to the Log page, the last line will look something like:
Here, we see the NI return packet pretty printed. In the RESP (response) part of the packet, you can see the return value is "COORDINATOR". There are other packet fields as well. The packet start byte (always 0x7E), the length (0x10), API (0x88), packet ID (0x13), AT command (NI), return status (OK - a zero), and a check byte (0x89).