-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDeviceDiscovery.java
More file actions
23 lines (20 loc) · 864 Bytes
/
DeviceDiscovery.java
File metadata and controls
23 lines (20 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import io.github.joblo2213.sma.speedwire.Speedwire;
import io.github.joblo2213.sma.speedwire.protocol.telegrams.DiscoveryResponse;
import java.io.IOException;
/**
* This sample demonstrates a simple way to detect all speedwire devices in the local network.
*/
public class DeviceDiscovery {
public static void main(String[] args) throws IOException, InterruptedException {
Speedwire speedwire = new Speedwire();
speedwire.onError(Exception::printStackTrace);
speedwire.onTimeout(() -> System.err.println("speedwire timeout"));
speedwire.onData(DiscoveryResponse.class, data ->
System.out.println("Device detected with ip " + data.getOrigin().getHostAddress())
);
speedwire.start();
speedwire.sendDiscoveryRequest();
Thread.sleep(5_000);
speedwire.shutdown();
}
}