When a data collector node needs to communicate with the rest of nodes in the network and not just receive data from them, problems arise. The data collector, and even other nodes, would need enough routing table entries for every node in the network. Or, each node has to discover the route before sending data to the destination.
The maximum number of routing table entries in an XBee module is 40. This means networks containing more than 40 XBee modules could easily become inundated with broadcast route discovery messages.
Source routing allows the collector to store and specify routes for many remotes. The collector remembers the route taken by a message to the data collector so it can be retrieved later to indicate the route of a message from the collector to a certain remote:
- The data collector must send periodic many-to-one route request broadcasts, so many-to-one routes to the central collector are created on all remotes.
- Every time a remote XBee module transmits data using a many-to-one route, it first sends a route record transmission.
- The route record transmission is unicast along the many-to-one route until it reaches the data collector.
- As the route record traverses the many-to-one route, each node in the route appends its own 16-bit address into the payload of the route record.
- When the route record reaches the data collector, it contains the address of the sender and the 16-bit address of each hop in the route.
- The data collector can store the routing information and retrieve it later to send a source routed packet to the remote module.
Note Source routing allows a data collector to route responses back to each device, supplying a many-to-one data request without additional route table entries.
Using source routing
To use source routing:
- The data collector must work in API mode.
- The collector must send periodic many-to-one route request (AR parameter value must be different from 0xFF).
- You need a microcontroller or a PC connected to the data collector to automatically capture and store the routes to the rest of network nodes.
These routes are used when transmitting a message to a remote node.
Acquiring source routes requires the remote nodes to send a unicast to the data collector (device that sends many-to-one route request broadcasts). There are several ways to force remotes to send route record transmissions:
- The data collector can issue a network discovery command (ND) to force all XBees to send a network discovery response. Each network discovery response will be prefaced by a route record.
- Periodic IO sampling can be enabled on remotes to force them to send data at a regular rate. Each IO sample would be prefaced by a route record.
- If the node identifier (NI) of the remote XBee is known, the DN command can be issued with the NI of the remote in the payload. The remote node with a matching NI would send a route record and a DN response.
- If the application on remote nodes periodically sends data to the data collector, each transmission forces a route record to occur.
To store source routes for remote nodes:
- Remote nodes must first send a unicast transmission to the central collector.
- Upon receipt of a unicast, the XBee emits a Route Record Indicator (0xA1) frame through the serial interface.
- The information from the route record frame must be interpreted and stored by the application on the microcontroller for later use.
To transmit data using source routing:
- The microcontroller application must force the XBee to create a source route in its internal source route table by sending a Create Source Route (0x21) frame through the serial interface.
- After setting up the source route, the application can send data to be wirelessly transmitted (Transmit Request (0x10), Explicit Addressing Command Frame (0x11), or Remote Command Request (0x17) frames) as needed, to the same destination, or any destination in the established source route.
- If new data must be sent to a destination not included in the last source route, the application must first send a new Create Source Route API frame.
Note If a Create Source Route API frame (0x21) does not precede data frames, data loss may occur.
XBee modules can buffer one source route that includes up to 11 hops (excluding source and destination).
When source routing is used, the 16-bit addresses in the source route are inserted into the RF payload space. This means the payload will be reduced by two bytes per intermediate hop. The user must account for the payload size reduction when using source routing.