I am trying to write simple code to read a simulator yabe device in my Java code. I can read the device with yab (a bacnet explorer free app) I am missing something I cant get what
String hostAddress="192.168.1.9";
IpNetwork network = new IpNetworkBuilder().withPort(47808).withSubnet(hostAddress, 24).build();
Transport transport = new DefaultTransport(network);
LocalDevice localDevice = new LocalDevice(3227671, transport);
localDevice.initialize();
localDevice.sendGlobalBroadcast(new WhoIsRequest());
int remoteId=123;
List<RemoteDevice> remoteDevices = localDevice.getRemoteDevices();
the list is always empty. this is the simulato device:
can anyone direct me what am I missing? Thank you.
Forewarning: I'm not a BACnet4J developer nor a Java developer; and I'm using Windows 10.
To start with, you could add 'SLF4J' ('reload4') to get a small sense of what is occurring, e.g. something like so (- having got the libraries online):
E.g. With the 'log4j.properties' configured:
And at the beginning of your 'main()' method - to be sure you've configured the logging properly:
You can also (install &) run Wireshark (as Administrator), and put a 'capture filter' of something like 'udp portrange 47808-47823' to see the BACnet/IP traffic that is flowing.
Now more so to your question.
After the device's 'initialize()', you probably need a 'Listener' class to listen out for the 'I-Am's being received:
With listener class that is something remotely like this:
But I'm guessing that this framework, will not fire the listener's 'iAmReceived()' method, if it's for the same device, so you would either need to define another 'device' (/might be good to try as an alternative/easier? starting-point test), or as you've done try using another device (- unless I'm wrong I'm not sure why this API does not appear to have a 'client'-only class / you seem to have to use a 'device' as being the client).
But I'm guessing the problem with you set-up, might be the (local/'255.255.255.255') 'Who-Is' broadcast, whereby it's only going to broadcast to the local subnet, and to devices that are using the same port #; so in terms of orchestrating that, you'd probably be better off using the IPv4 (only) range of addresses (- IPv6 is cack in this regard in that they've reduced the localhost to being only 1 address rather than like IPv4 a localhost range of addresses or even 5-10 addresses?!), so you can have both the client and server device listening upon the same (Class 'A') network but with the same port #.
Ignoring the fact that I seem to have a newer(?) version of the BACnet4J library, i.e. method-names differences:
E.g. Possibly something close to what could work for two local host addresses: