I'm using Xbee java library to discover the network devices but it doesn't work, please any help this the code :

the code :
package com.digi.xbee.example;
import com.digi.xbee.api.XBeeDevice;
import com.digi.xbee.api.XBeeNetwork;
import com.digi.xbee.api.exceptions.XBeeException;
import com.digi.xbee.api.RemoteXBeeDevice;
import java.util.List;
public class discovery {

/* Constants */

// TODO Replace with the serial port where your module is connected to.
private static final String PORT = "COM5";
// TODO Replace with the baud rate of your module.
private static final int BAUD_RATE = 9600;
 public static void main(String[] args) {
	 // Instantiate an XBee device object.
	 XBeeDevice myXBeeDevice = new XBeeDevice(PORT,BAUD_RATE );
	 try{
	 myXBeeDevice.open();
	// Get the XBee Network object from the XBee device.
	 XBeeNetwork network = myXBeeDevice.getNetwork();
	// Set the timeout to 10 seconds.
	 network.setDiscoveryTimeout(10000);
	
	// 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 remotes = network.getDevices();
	 System.out.println("There are " + network.getNumberOfDevices() + " device(s) in the network.");
	

	 }catch (XBeeException e) {
			e.printStackTrace();
			myXBeeDevice.close();
			System.exit(1);
		}
 }

}

What XBee products and related firmware are you using?

Thank for your response , i’am using XBee Serie 2 from Digi
For the router these are the firmware information:
-Product family: XB24-ZB
-Function Set: Zigbee router Api
-Firmware version 23A7
For the coordinator :
-Product family: XB24-ZB
-Function Set: Zigbee coordinator Api
-Firmware version 21A7

Are you sure the modules are associated to each other? If you use the Node Discovery function in XCTU, do you see the other modules in the network?

Yes Mvut they works in XCTU and give me the addresses list of the discovered xbees. and this is the configuration of my Xbees in XCTU :
for the zigbee coordinator api:
-PAN ID: C001BEE
-SC scan channels:FFF
-DH:0
-DL:FFFF
-AP API enable:2
for the zigbee router api:
-PAN ID: C001BEE
-SC scan channels:FFF
-DH:0
-DL:FFFF
-AP API enbale:2
for the zigbee coordinator api:
-PAN ID: C001BEE
-SC scan channels:FFF
-JV channel verification: enabled
-DH:0
-DL:0
-AP API enbale:2

Try API mode 1 on the node that you are using the Java files from. It could very well be that the Java is only using API mode 1.

Thank you Mvut it works :slight_smile: but I want to ask you a question have any idea how I can do the same process of discovering using c sharp with visual studio ??

Try looking through the examples for the XBee Programmables.