Local Devices, Foreign Registration, Discovery Scenarios
-
I'm a bit confused about when I should be creating a new LocalDevice instance and when I should be re-using the same in the scenario where there are multiple RemoteDevices I'm interesting in communicating with.
I've laid out a scenario here that seems to be working well enough:
But now I'm unsure what the right approach is to add another "set" of devices that are reached through the main device. I'm confused because in order to discover these devices I had to register with the remote device as a Foreign Device. This works well enough and when I use the device discoverer I see all of the devices.
The problem is - when I need to add a 2nd or 3rd set of these, I'm already registered as a FD with the first one, and IpNetwork blows up if you try to register again.
Does that mean I should be using a new LocalDevice instance? Should it be bound to the same network adapter/IP? Bound to the same port?
I've played around with multiple LocalDevices bound to the same IP/port, with different device ids, but kept seeing weird behavior where one or the other didn't seem to receive messages.
-
How are you setting up the multiple local devices? Here is some sample code I've used before but not thoroughly vetted in terms of a device missing a message.
List<InterfaceAddress> usable = BacnetIpUtils.listUsableBACnetInterfaces(); Assume.assumeTrue(usable.size() > 0); InterfaceAddress address = usable.get(0); String bindAddress = address.getAddress().toString().split("/")[1]; String broadcastAddress = address.getBroadcast().toString().split("/")[1]; //Configure the first network, ensure we set reuse address IpNetwork networkOne = new IpNetworkBuilder() .withLocalBindAddress(bindAddress) .withBroadcast(broadcastAddress, address.getNetworkPrefixLength()) .withLocalNetworkNumber(1).withPort(9000).withReuseAddress(true).build(); Transport transportOne = new DefaultTransport(networkOne); LocalDevice localDeviceOne = new LocalDevice(1, transportOne); IpNetwork networkTwo = new IpNetworkBuilder() .withLocalBindAddress(bindAddress) .withBroadcast(broadcastAddress, address.getNetworkPrefixLength()) .withLocalNetworkNumber(1).withPort(9000).withReuseAddress(true).build(); Transport transportTwo = new DefaultTransport(networkTwo); LocalDevice localDeviceTwo = new LocalDevice(2, transportTwo); localDeviceOne.initialize(); localDeviceTwo.initialize();