Unable to find router to network
-
I'm trying to connect to a BACNet device. The code I wrote for this looks somewhat like:
public static void main(String[] args) throws ServiceException { Integer deviceId = 1234; String port = 0xBAC0, localBindAddress = "192.168.0.145"; IpNetworkBuilder builder = new IpNetworkBuilder(); builder.port(Integer.decode(port)); builder.localBindAddress(localBindAddress); IpNetwork network = builder.build(); LocalDevice localDevice = new LocalDevice(deviceId, new DefaultTransport(network)); try { localDevice.initialize(); } catch (Exception e) { throw new ServiceException("Unable to initialize localDevice", e); } localDevice.getEventHandler().addListener(new DeviceEventAdapter() { @Override public void iAmReceived(RemoteDevice remoteDevice) { logger.debug("iAm Received from device: {}, NetworkNumber: {}", remoteDevice.getInstanceNumber(), remoteDevice.getAddress().getNetworkNumber() ); Runnable task = () -> { try { DiscoveryUtils.getExtendedDeviceInformation(localDevice, remoteDevice); SequenceOf<ObjectIdentifier> oids = RequestUtils.getObjectList(localDevice, remoteDevice); for (ObjectIdentifier oid : oids) { String name = ((CharacterString) RequestUtils.getProperty(localDevice, remoteDevice, oid, PropertyIdentifier.objectName)).getValue(); logger.info("Found object oid={}, name={} in device {}", oid, name, remoteDevice.getInstanceNumber() ); } while(true) { for (ObjectIdentifier oid : oids) { Encodable value = RequestUtils.getProperty( localDevice, remoteDevice, oid, PropertyIdentifier.presentValue ); logger.info("{}={}", oid, value); } try { Thread.sleep(5_000L); } catch (InterruptedException e) { } } } catch (BACnetException e) { logger.error("Error getting values from remoteDevice", e); } }; new Thread(task).start(); } }); localDevice.sendGlobalBroadcast(new WhoIsRequest()); }
The logging shows the following devices:
iAm Received from device: 400, NetworkNumber: 0
iAm Received from device: 401, NetworkNumber: 17436
iAm Received from device: 402, NetworkNumber: 17436
iAm Received from device: 404, NetworkNumber: 17436
iAm Received from device: 500, NetworkNumber: 17436
iAm Received from device: 501, NetworkNumber: 17436
iAm Received from device: 502, NetworkNumber: 17436
iAm Received from device: 0, NetworkNumber: 0
iAm Received from device: 141, NetworkNumber: 0
iAm Received from device: 200, NetworkNumber: 0
iAm Received from device: 201, NetworkNumber: 16924
iAm Received from device: 202, NetworkNumber: 16924When connection with an explorer I see that the 17436 network is behind the 400 device and the 16924 network behind the 200 device.
I get the following errors when running this code.
- com.serotonin.bacnet4j.exception.BACnetTimeoutException: Unable to find router to network 17436
- java.lang.RuntimeException: Invalid arguments: router address not provided for remote recipient Address [networkNumber=17436, macAddress=[1c,44,91,1,0,0]]
I bind the localDevice to to the BAC0 port on a specific ip adress on the machine this code is running on. The machine has 2 interfaces and the default gateway points to a machine on the other interface.
I tried using port BAC1, however if I do that, I don't see the IAmReceived messages anymore. So the polling task will not start.
Has anyone an idea what I'm doing wrong and how I can connect to that (foreign?) device?
-
Hi davyv,
Someone referenced this in another thread and so I thought I'd answer, even though it has been a very long time.
My suspicion is that you're not seeing or the devices aren't sending the IAmRouterToNetwork messages. Most likely this has to do with them going to broadcast addresses and your having bound a specific address. So, the operating system may not be delivering those broadcasts to your LocalDevice. You could try binding the address
0.0.0.0
or just zeros in the subnet bits, like192.168.0.0