Figure 5. Wireless sensor network
concept of operation.
command and associated
command parameters to a 16-
bit remote sensor address. Data
length is the size of the
command parameters which is
fixed at four bytes. Both the
base and remote unit must be
in API mode. The remote unit
will send a command response
back to the base.
cmdparameters, char* cmd,
byte datalength) — Sends a
local command and associated
command parameters to the
local unit. Data length is the
size of the command
parameters which is fixed at
four bytes. The base must be
in API mode. The local unit will send a command
response based on receiving this command.
Int recv_packets (void) — This function is called to
determine if a network packet has been received at the
base unit. The type of packet and associated data is
shown on the graphics display. It is also stored in a global
memory location designated “mypacket” for any
additional processing you may want to do. Responses to
command response packets are processed, as well as data
packets from remote data sensors. If a data packet is
received, the data will exist in a global memory array
sample [ 9]. The function returns an int indicating that a
packet is available.
Besides the data itself, the only new field is RSSI which
represents the received signal strength of the base signal
as measured by the remote.
A block diagram example of network operations using
the API mode is shown in Figure 5. In an outgoing
command packet (base to remote), ID represents the
packet type as command(RAT, LAT) or data; length is the
byte size of the entire packet; destination is the 16-bit
remote address for where the packet needs to go. The
source is the 16-bit address for the packet originator; in
this case, the base. There are packet fields for CMD
(command type) and CMD parameters associated with
the command, and then finally checksum. Checksum is
used for error detection of transmitted packet data. It is a
unique byte signature that is the sum of all the data
content within the transmitted packet.
The command response packet is similar, and includes
the remote source address, the CMD the remote has
received, and the status of the CMD execution (OK,
Unknown CMD, or error). The I/O data packet is used to
transmit sensor data from the remote back to the base.
Initial XBee Setup and
Here’s where the dongle and X-CTU come in handy.
You need to pre-configure your remote sensor address
and set up API mode to allow the Experimenter to
communicate with the remote. For the demos, we use
two remote addresses (MY = 1 and MY = 2). It is very
Plug the remote XBee module into the dongle, and
then hook up the dongle to the PC USB. Open up X-C TU.
The X-CTU will come into a setup mode showing the
COM port that is now available to use. Select the COM
port, then test it to insure the dongle communication is
working. If all is okay, select the modem configuration,
and read the XBee module using the GUI tool “Read.”
Scroll to MY setting under configuration and set the
address required in the text edit box. Scroll to the API
setting and select API as active. Finally, using the GUI tool
“Write,” program this new configuration to the XBee.
Work both remote modules in a similar way. You are
The demos are built with MPLAB 8. 80 and the PIC32
free C compiler. Make sure you have properly configured
the remote XBee using X-CTU and the dongle with their
required addresses and API mode. In our first demo, the
Experimenter will configure its local D7 as a digital output,
and then configure remote (MY = 1) D0 as a digital
December 2012 49