-
Notifications
You must be signed in to change notification settings - Fork 6
Discover LAN enabled devices
LAN-enabled VBus devices like controllers, adapters and dataloggers have a network discovery mechanism that allows to find such a device on a local network without having to know its IP address.
The "discovery" example application combines the steps described here to continously discover LAN-enabled devices and print their name and IP address. The example application can be found here: https://github.com/danielwippermann/resol-vbus-java/blob/master/vbus-example/src/main/java/de/resol/vbus/example/discovery/Main.java
The heavy lifting of the discovery process is performed by TcpDataSourceProvider.discoverDataSources. This function takes:
- a broadcast IP address to limit the search,
- a number of tries,
- a timeout in milliseconds between the tries and
- a flag specifying whether the function should fetch additional information about the device after discovering it (like its name, serial, version, ...)
In code it looks like this:
InetAddress broadcastAddress = InetAddress.getByName("255.255.255.255");
int rounds = 3;
int timeout = 500; // in milliseconds
boolean fetchInformation = true;
TcpDataSource[] dataSources = TcpDataSourceProvider.discoverDataSources(broadcastAddress, tries, timeout, fetchInformation);
Once the function returns the dataSources array holds instances of the TcpDataSource class filled with the information gathered from the devices.
If you already know the IP address of a LAN-enabled device you can create a TcpDataSource instance directly:
InetAddress address = InetAddress.getByName("192.168.13.1");
int timeout = 500;
TcpDataSource dataSource = TcpDataSourceProvider.fetchInformation(address, timeout);
Those instances can then be used to Create and establish a connection.