Discover the network

The XBeeNetwork object discovery process allows you to discover and store all the XBee devices that form the network. The XBeeNetwork object provides a method for executing the discovery process:

Method Description
startDiscoveryProcess() Starts the discovery process, saving the remote XBee devices found inside the XBeeNetwork object.

When a discovery process has started, you can monitor and manage it using the following methods provided by the XBeeNetwork object:

Method Description
isDiscoveryRunning() Returns whether the discovery process is running.
stopDiscoveryProcess() Stops the discovery process that is taking place.

Although you call the stopDiscoveryProcess method, DigiMesh and DigiPoint devices are blocked until the configured discovery time has elapsed. If you try to get or set any parameter during that time, a TimeoutException is thrown.

Discovering the network

Once the process has finished, you can retrieve the list of devices that form the network using the getDevices() method provided by the network object.

import com.digi.xbee.api.XBeeDevice;
import com.digi.xbee.api.XBeeNetwork;

[...]

// Instantiate an XBee device object.
XBeeDevice myXBeeDevice = new XBeeDevice("COM1", 9600);
myXBeeDevice.open();

// Get the XBee Network object from the XBee device.
XBeeNetwork network = myXBeeDevice.getNetwork();

// Start the discovery process.
network.startDiscoveryProcess();

// Wait until the discovery process has finished.
while (network.isDiscoveryRunning()) {
// Sleep.
}

// Retrieve the devices that form the network.
List<RemoteXBeeDevice> remotes = network.getDevices();

[...]

Click one of the following links to view the discovery methods: