A Z-Wave IP implementation for Node.js. Unofficial library, not supported by Sigma Designs.
This library enables node.js application to communicate with Z-Wave devices via a Z/IP (Z-Wave IP) Gateway.
npm install zwaveip
let ZWaveIP = require('zwaveip');
To convert the Z-Wave network's PSK (Pre-Shared Key) password from a hex string to the required binary representation
let convertHexStringToBinaryPsk = function(hexString) {
let result = Buffer.alloc(hexString.length / 2);for (let i = 0; i < hexString.length; i += 2) {
result[i / 2] = parseInt("0x" + hexString.substr(i, 2), 16);
}return result;
}
let deviceConnection = ZWaveIP.connectToZWaveDevice(ipAddress, pskIdentity, pskPassword);
deviceConnection.sendMessage(ZWaveIP.CommandClass.SwitchBinary, ZWaveIP.SwitchBinaryCommand.Set, [0xFF]);
deviceConnection.sendMessage(ZWaveIP.CommandClass.SwitchBinary, ZWaveIP.SwitchBinaryCommand.Set, [0xFF])
.then(
function() {
console.log('Message acknowledged.');
},
function(err) {
console.log('Message failure: ' + JSON.stringify(err));
}
);
deviceConnection.sendMessageAndWaitForResponse(ZWaveIP.CommandClass.SwitchBinary, ZWaveIP.SwitchBinaryCommand.Get, [], ZWaveIP.SwitchBinaryCommand.Report)
.then(
function(response) {
let powerStateAsByte = response.data[0];
let powerStateAsBoolean = (powerStateAsByte != 0);
console.log("powerState: " + powerStateAsBoolean + " (" + powerStateAsByte + ")");
},
function(err) {
console.log('Message failure: ' + JSON.stringify(err));
}
);
deviceConnection.close(callback);
To prevent a Z-Wave device connection from blocking the Node.JS process from exiting (identical to udp socket functionality)
deviceConnection.unref();
ZWaveIP.findGatewayControllerIpv4Address()
.then(
function(ipv4Address) {
console.log(" FOUND: Z/IP Gateway controller IPv4 address is: " + ipv4Address + "\n");
},
function(err) {
console.log('Could not discover the Z-Wave Gateway Controller's virtual IPv4 address: ' + JSON.stringify(err));
}
);
ZWaveIP.requestNodeListFromGatewayController(gatewayIpAddress, pskIdentity, pskPassword)
.then(
function(nodeList) {
for (let index = 0; index < nodeList.length; index++) {
let ipAddress = nodeList[index].ipv4Address === null ? nodeList[index].ipv6Address : nodeList[index].ipv4Address;
console.log('Z-Wave Node # ' + nodeList[index].nodeId + ' (' + ipAddress + ')');
}
},
function(err) {
console.log('Could not request node lsit from the specified Z-Wave Gateway Controller: ' + JSON.stringify(err));
}
);