A Z-Wave IP implementation for Java. Unofficial library, not supported by Sigma Designs.
This library enables Java applications to communicate with Z-Wave devices via a Z/IP (Z-Wave IP) Gateway.
- Add zwaveip.jar as an "external JAR" to your project.
- Add the two supporting BouncyCastle JARs (as "external JARs") to your project:
- bcprov-jdk15on-159.jar
- bctls-jdk15on-159.jar
import com.zwavepublic.zwaveip.*;
import com.zwavepublic.zwaveip.command.*;
To convert the Z-Wave network's PSK (Pre-Shared Key) password from a hex string to the required binary representation
private static byte[] convertHexStringToBinaryPsk(String hexString) {
byte[] result = new byte[hexString.length() / 2];for (int i = 0; i < hexString.length(); i += 2) {
result[i / 2] = (byte)Integer.parseInt(hexString.substring(i, i + 2), 16);
}return result;
}
// replace this address with your Z/IP device's IPv4 or IPv6 address
InetAddress address = InetAddress.getByName("192.168.0.50");// default pskIdentity and sample password
String pskIdentity = "Client_identity";
byte[] pskPassword = convertHexStringToBinaryPsk("123456789012345678901234567890aa");ZWaveIPClient zwaveIPClient = new ZWaveIPClient(address, pskIdentity, pskPassword);
zwaveIPClient.sendMessage(CommandClass.SWITCH_BINARY, SwitchBinaryCommand.SET, new byte[] {0xFF});
/* NOTE: sendMessage throws both IOException (for network errors) and ZWaveIPException (for Z-Wave timeouts/NAKs) */
try {
byte[] response = zwaveIPClient.sendMessageAndWaitForResponse(CommandClass.SWITCH_BINARY, SwitchBinaryCommand.GET, new byte[] {}, SwitchBinaryCommand.REPORT);
byte powerStateAsByte = response.data[0];
boolean powerStateAsBoolean = (powerStateAsByte != 0);
System.out.println("powerState: " + powerStateAsBoolean + " (" + powerStateAsByte + ")");
} catch (IOException ex) {
System.out.println("IOException (network error): " + ex.toString());
} catch (AckTimeoutException ex) {
System.out.println("Timeout (no ACK)");
} catch (ResponseTimeoutException ex) {
System.out.println("Timeout (no response)");
} catch (NakException ex) {
System.out.println("NAK");
}
zwaveIPClient.close();