ozw: Rework and add some device specific drivers and examples.

This commit reworks ozw somewhat and adds some device specific drivers
with examples.  All of these drivers are kept in the UPM ozw library.

The OZW class has been reworked to make it a proper singleton, since
the OpenZWave::Manager() it depends on is already a singleton.  This
avoids issues such as opening and initializing OpenZWave multiple
times.

A new, relatively thin base class, ozwInterface is also now present.
This class wraps some basic functionality, and handles initialization
of the OZW base class.  It is intended to be inherited by device
driver classes.  It operates on a node id for a device.  Each OZW
device is referenced by a node id, which does not change unless the
device is removed (and possibly re-added) to a Z-Wave network.

Finally, a series of device specific drivers have been implemented.
These provide basic functionality to monitor and in some cases control
the operation of a Z-Wave device.  They are the following:

ozwdump - This is a fake 'device' driver that initializes an OZW
network and dumps information on all of the nodes (devices) present.
Along with each node, available information on each valueid associated
with that node is also printed.  This fake device and it's examples
replace the original ozw example.

aeotecss6 - Aeotec Smart Switch 6.  This device allows control of the
switch, as well as reporting of information the switch makes
available, such as current consumption, volts, watts, and accumulated
energy use (kWh).

aeotecsdg2 - Aeotec Smart Dimmer Gen 2.  This device is similar to the
Smart Switch 6, but also provides dimming functionality.  It also
provides information on energy use.

aeotecdw2e - Aeotec Door/Window Sensor 2nd Edition.  This device is a
magnetic switch with an embedded tamper switch used to detect the
opening/closing of windows and doors.  This is a battery powered
device.

aeotecdsb09104 - Aeotec Home Energy Monitor.  This device is intended
to be installed at the MAINS or Breaker box.  It reports current and
cumulative energy consumption.

tzemt400 - Trane TZEMT400 Thermostat.  This device is a thermostat
with Z-Wave functionality.  The variant tested was the
TZEMT400BB32MAA.  The driver reports various information on the status
of the thermostat, as well as the current measured temperature.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
Jon Trulson
2016-07-06 13:25:39 -06:00
parent 8da6095c35
commit 9ab9e2c403
47 changed files with 4067 additions and 205 deletions

View File

@ -0,0 +1,103 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var sensorObj = require('jsupm_ozw');
/************** Main code **************/
var defaultDev = "/dev/ttyACM0";
// if an argument was specified, use it as the device instead
if (process.argv.length > 2)
{
defaultDev = process.argv[2];
}
console.log("Using device " + defaultDev);
// Instantiate an Aeotec DSB09104 instance, on device node 12. You
// will almost certainly need to change this to reflect your own
// network. Use the ozwdump example to see what nodes are
// available.
var sensor = new sensorObj.AeotecDSB09104(12);
// The first thing to do is create options, then lock them when done.
sensor.optionsCreate();
sensor.optionsLock();
// Next, initialize it.
console.log("Initializing, this may take awhile depending on your ZWave network");
sensor.init(defaultDev);
console.log("Initialization complete");
console.log("Querying data...");
setInterval(function()
{
sensor.update();
console.log("Watts, Channel 1: "
+ sensor.getWattsC1()
+ " W");
console.log("Watts, Channel 2: "
+ sensor.getWattsC2()
+ " W");
console.log("Watts, Channel 3: "
+ sensor.getWattsC3()
+ " W");
console.log("Energy, Channel 1: "
+ sensor.getEnergyC1()
+ " kWh");
console.log("Energy, Channel 2: "
+ sensor.getEnergyC2()
+ " kWh");
console.log("Energy, Channel 3: "
+ sensor.getEnergyC3()
+ " kWh");
console.log("Battery Level: "
+ sensor.getBatteryLevel()
+ "%");
console.log();
}, 3000);
// exit on ^C
process.on('SIGINT', function()
{
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting.");
process.exit(0);
});

View File

@ -0,0 +1,95 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var sensorObj = require('jsupm_ozw');
/************** Main code **************/
var defaultDev = "/dev/ttyACM0";
// if an argument was specified, use it as the device instead
if (process.argv.length > 2)
{
defaultDev = process.argv[2];
}
console.log("Using device " + defaultDev);
// Instantiate an Aeotec Door/Window 2nd Edition sensor instance, on
// device node 10. You will almost certainly need to change this to
// reflect your own network. Use the ozwdump example to see what
// nodes are available.
var sensor = new sensorObj.AeotecDW2E(10);
// The first thing to do is create options, then lock them when done.
sensor.optionsCreate();
sensor.optionsLock();
// Next, initialize it.
console.log("Initializing, this may take awhile depending on your ZWave network");
sensor.init(defaultDev);
console.log("Initialization complete");
console.log("Querying data...");
setInterval(function()
{
if (sensor.isDeviceAvailable())
{
console.log("Alarm status: "
+ sensor.isAlarmTripped());
console.log("Tamper Switch status: "
+ sensor.isTamperTripped());
console.log("Battery Level: "
+ sensor.getBatteryLevel()
+ "%");
console.log();
}
else
{
console.log("Device has not yet responded to probe.");
console.log("Try waking it, or wait until it wakes itself if "
+ "configured to do so.");
console.log();
}
}, 1000);
// exit on ^C
process.on('SIGINT', function()
{
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting.");
process.exit(0);
});

View File

@ -0,0 +1,119 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var sensorObj = require('jsupm_ozw');
function sleepFor(millis)
{
var now = new Date().getTime();
while(new Date().getTime() < now + millis)
{
/* do nothing */
}
}
/************** Main code **************/
var defaultDev = "/dev/ttyACM0";
// if an argument was specified, use it as the device instead
if (process.argv.length > 2)
{
defaultDev = process.argv[2];
}
console.log("Using device " + defaultDev);
// Instantiate an Aeotec Smart Dimmer Gen2 instance, on device node
// 9. You will almost certainly need to change this to reflect your
// own network. Use the ozwdump example to see what nodes are
// available.
var sensor = new sensorObj.AeotecSDG2(9);
// The first thing to do is create options, then lock them when done.
sensor.optionsCreate();
sensor.optionsLock();
// Next, initialize it.
console.log("Initializing, this may take awhile depending on your ZWave network");
sensor.init(defaultDev);
console.log("Initialization complete");
// turn light on
console.log("Turning switch on, then sleeping for 5 secs");
sensor.on();
sleepFor(5000);
console.log("Querying data...");
var dim = false;
setInterval(function()
{
// put on a light show...
if (dim)
sensor.setLevel(25);
else
sensor.on();
dim = !dim;
sensor.update();
console.log("Current Level: "
+ sensor.getLevel());
console.log("Volts: "
+ sensor.getVolts()
+ " volts");
console.log("Energy Consumption: "
+ sensor.getEnergy()
+ " kWh");
console.log("Watts: "
+ sensor.getWatts());
console.log("Current: "
+ sensor.getCurrent()
+ " amps");
console.log();
}, 5000);
// exit on ^C
process.on('SIGINT', function()
{
console.log("Turning switch off and sleeping for 5 seconds...");
sensor.off();
sleepFor(5000);
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting.");
process.exit(0);
});

View File

@ -0,0 +1,110 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var sensorObj = require('jsupm_ozw');
function sleepFor(millis)
{
var now = new Date().getTime();
while(new Date().getTime() < now + millis)
{
/* do nothing */
}
}
/************** Main code **************/
var defaultDev = "/dev/ttyACM0";
// if an argument was specified, use it as the device instead
if (process.argv.length > 2)
{
defaultDev = process.argv[2];
}
console.log("Using device " + defaultDev);
// Instantiate an Aeotec Smart Switch 6 instance, on device node 11.
// You will almost certainly need to change this to reflect your own
// network. Use the ozwdump example to see what nodes are available.
var sensor = new sensorObj.AeotecSS6(11);
// The first thing to do is create options, then lock them when done.
sensor.optionsCreate();
sensor.optionsLock();
// Next, initialize it.
console.log("Initializing, this may take awhile depending on your ZWave network");
sensor.init(defaultDev);
console.log("Initialization complete");
// turn light on
console.log("Turning switch on, then sleeping for 5 secs");
sensor.on();
sleepFor(5000);
console.log("Querying data...");
setInterval(function()
{
sensor.update();
console.log("Switch status: "
+ sensor.isOn());
console.log("Volts: "
+ sensor.getVolts()
+ " volts");
console.log("Energy Consumption: "
+ sensor.getEnergy()
+ " kWh");
console.log("Watts: "
+ sensor.getWatts());
console.log("Current: "
+ sensor.getCurrent()
+ " amps");
console.log();
}, 3000);
// exit on ^C
process.on('SIGINT', function()
{
console.log("Turning switch off and sleeping for 5 seconds...");
sensor.off();
sleepFor(5000);
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting.");
process.exit(0);
});

View File

@ -3,7 +3,7 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015 Intel Corporation.
* Copyright (c) 2015-2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -31,7 +31,7 @@ var sensorObj = require('jsupm_ozw');
/************** Main code **************/
// Instantiate an OZW instance
var sensor = new sensorObj.OZW();
var sensor = new sensorObj.OZWDUMP();
var defaultDev = "/dev/ttyACM0";
@ -48,42 +48,38 @@ sensor.optionsLock();
// Next, initialize it.
console.log("Initializing, this may take awhile depending on your ZWave network");
if (!sensor.init(defaultDev))
{
console.log("Init failed.");
process.exit(0);
}
sensor.init(defaultDev);
console.log("Initialization complete");
console.log("Dumping nodes...");
sensor.dumpNodes();
sensor.dumpNodes(true);
// The following is example output of dumpNodes:
//
// Dumping nodes...
// Node 1: Z-Stick Gen5
// Node 2: Smart Switch 6
// Index: 0, Type: bool, Label: Switch, Value: False
// Index: 0, Type: bool, Label: Switch, Value: False
// Index: 2, Type: float, Label: Energy, Value: 1.190 kWh
// Index: 3, Type: float, Label: Previous Reading, Value: 1.190 kWh
// Index: 4, Type: int32, Label: Interval, Value: 1521 seconds
// Index: 5, Type: float, Label: Power, Value: 0.000 W
// Index: 6, Type: float, Label: Voltage, Value: 121.256 V
// Index: 7, Type: float, Label: Current, Value: 0.000 A
// Index: 8, Type: bool, Label: Exporting, Value: False
// Index: 45, Type: list, Label: Day, Value: Friday
// Index: 46, Type: byte, Label: Hour, Value: 5
// Index: 47, Type: byte, Label: Minute, Value: 53
// Index: 8, Type: bool, Label: Exporting, Value: False
// Index: 45, Type: list, Label: Day, Value: Friday
// Index: 46, Type: byte, Label: Hour, Value: 5
// Index: 47, Type: byte, Label: Minute, Value: 53
// Node 3: Multi Sensor
// Index: 0, Type: bool, Label: Sensor, Value: True
// Index: 0, Type: bool, Label: Sensor, Value: True
// Index: 1, Type: float, Label: Temperature, Value: 72.8 F
// Index: 2, Type: float, Label: Luminance, Value: 4 lux
// Index: 3, Type: float, Label: Relative Humidity, Value: 22 %
// Index: 17, Type: byte, Label: Battery Level, Value: 98 %
// Node 5: Minimote
// Node 6: Smart Energy Switch
// Index: 0, Type: bool, Label: Switch, Value: False
// Index: 0, Type: bool, Label: Switch, Value: False
// Index: 2, Type: float, Label: Power, Value: 0.000 W
// Index: 3, Type: float, Label: Energy, Value: 1.609 kWh
// Index: 4, Type: float, Label: Previous Reading, Value: 1.609 kWh
@ -91,9 +87,9 @@ sensor.dumpNodes();
// Index: 6, Type: float, Label: Power, Value: 0.000 W
// Index: 7, Type: float, Label: Previous Reading, Value: 1.609 W
// Index: 8, Type: int32, Label: Interval, Value: 1521 seconds
// Index: 9, Type: bool, Label: Exporting, Value: False
// Index: 9, Type: bool, Label: Exporting, Value: False
// Node 7: Smart Energy Switch
// Index: 0, Type: bool, Label: Switch, Value: False
// Index: 0, Type: bool, Label: Switch, Value: False
// Index: 2, Type: float, Label: Power, Value: 0.000 W
// Index: 3, Type: float, Label: Energy, Value: 0.000 kWh
// Index: 4, Type: float, Label: Previous Reading, Value: 0.000 kWh
@ -101,24 +97,7 @@ sensor.dumpNodes();
// Index: 6, Type: float, Label: Power, Value: 0.000 W
// Index: 7, Type: float, Label: Previous Reading, Value: 0.000 W
// Index: 8, Type: int32, Label: Interval, Value: 1521 seconds
// Index: 9, Type: bool, Label: Exporting, Value: False
//
// So, with the above in mind:
//
// 1. Query the temperature on node 3 and print it out (as a
// string), along with the units of measure:
//
// console.log("Temperature: " + sensor.getValueAsString(3, 1) +
// " " + sensor.getValueUnits(3, 1));
//
// 2. query the same temperature as a float:
//
// var temperature = sensor.getValueAsFloat(3, 1);
//
// 3. Turn on the light plugged into the switch on Node 7
//
// console.log("Turning ON node 7");
// sensor.setValueAsBool(7, 0, true);
// Index: 9, Type: bool, Label: Exporting, Value: False
//
sensor = null;

View File

@ -0,0 +1,104 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var sensorObj = require('jsupm_ozw');
/************** Main code **************/
var defaultDev = "/dev/ttyACM0";
// if an argument was specified, use it as the device instead
if (process.argv.length > 2)
{
defaultDev = process.argv[2];
}
console.log("Using device " + defaultDev);
// Instantiate a TZEMT400 instance, on device node 13. You will
// almost certainly need to change this to reflect your own network.
// Use the ozwdump example to see what nodes are available.
var sensor = new sensorObj.TZEMT400(13);
// The first thing to do is create options, then lock them when done.
sensor.optionsCreate();
sensor.optionsLock();
// Next, initialize it.
console.log("Initializing, this may take awhile depending on your ZWave network");
sensor.init(defaultDev);
console.log("Initialization complete");
console.log("Querying data...");
setInterval(function()
{
sensor.update();
console.log("Temperature: "
+ sensor.getTemperature()
+ " C / "
+ sensor.getTemperature(true)
+ " F");
console.log("Mode: "
+ sensor.getMode());
console.log("Operating State: "
+ sensor.getOperatingState());
console.log("Heating Point: "
+ sensor.getHeatingPointTemperature()
+ " C / "
+ sensor.getHeatingPointTemperature(true)
+ " F");
console.log("Cooling Point: "
+ sensor.getCoolingPointTemperature()
+ " C / "
+ sensor.getCoolingPointTemperature(true)
+ " F");
console.log("Fan Mode: "
+ sensor.getFanMode());
console.log("Fan State: "
+ sensor.getFanState());
console.log();
}, 5000);
// exit on ^C
process.on('SIGINT', function()
{
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting.");
process.exit(0);
});