ozw: Initial implementation

This module was developed using the OpenZWave library (v1.3):

http://www.openzwave.com/

It was developed using a collection of devices (switches and a
multi-sensor) connected via an Aeon Z-Stick Gen5 USB dongle.

It can be used to query (and, where appropriate, set) Values on Nodes
connected to the ZWave network.

Checks are made in src/ozw/CMakeLists.txt to ensure that the
libopenzwave library is installed (via pkg-config).  If not present,
then neither the module, nor the example will be built.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Jon Trulson
2015-10-23 18:00:33 -06:00
committed by Mihai Tudor Panu
parent 287250b32d
commit fd509c7d79
12 changed files with 2222 additions and 0 deletions

View File

@ -157,6 +157,10 @@ add_executable (mcp9808-example mcp9808.cxx)
add_executable (groveultrasonic-example groveultrasonic.cxx)
add_executable (sx1276-lora-example sx1276-lora.cxx)
add_executable (sx1276-fsk-example sx1276-fsk.cxx)
# availability of libopenzwave is tested in src/ozw/CMakeLists.txt
if (OPENZWAVE_FOUND)
add_executable (ozw-example ozw.cxx)
endif ()
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
@ -277,6 +281,10 @@ include_directories (${PROJECT_SOURCE_DIR}/src/dfrph)
include_directories (${PROJECT_SOURCE_DIR}/src/mcp9808)
include_directories (${PROJECT_SOURCE_DIR}/src/groveultrasonic)
include_directories (${PROJECT_SOURCE_DIR}/src/sx1276)
if (OPENZWAVE_FOUND)
include_directories(${PROJECT_SOURCE_DIR}/src/ozw)
include_directories(${OPENZWAVE_INCLUDE_DIRS})
endif ()
target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
@ -435,3 +443,6 @@ target_link_libraries (mcp9808-example mcp9808 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (groveultrasonic-example groveultrasonic ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (sx1276-lora-example sx1276 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (sx1276-fsk-example sx1276 ${CMAKE_THREAD_LIBS_INIT})
if (OPENZWAVE_FOUND)
target_link_libraries (ozw-example ozw ${CMAKE_THREAD_LIBS_INIT})
endif ()

141
examples/c++/ozw.cxx Normal file
View File

@ -0,0 +1,141 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015 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.
*/
#include <unistd.h>
#include <iostream>
#include "ozw.h"
using namespace std;
int main(int argc, char **argv)
{
//! [Interesting]
string defaultDev = "/dev/ttyACM0";
// if an argument was specified, use it as the device instead
if (argc > 1)
defaultDev = string(argv[1]);
// Instantiate an OZW instance
upm::OZW *sensor = new upm::OZW();
// The first thing to do is create options, then lock them when done.
sensor->optionsCreate();
sensor->optionsLock();
// Next, initialize it.
cout << "Initializing, this may take awhile depending on your ZWave network"
<< endl;
if (!sensor->init(defaultDev))
{
cerr << "Init failed." << endl;
return 0;
}
cout << "Initialization complete" << endl;
cout << "Dumping nodes..." << endl;
sensor->dumpNodes();
// 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: 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
// Node 3: Multi Sensor
// 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: 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
// Index: 5, Type: int32, Label: Interval, Value: 1521 seconds
// 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
// Node 7: Smart Energy Switch
// 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
// Index: 5, Type: int32, Label: Interval, Value: 1521 seconds
// 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:
//
// cout << "Temperature: " << sensor->getValueAsString(3, 1)
// << " " << sensor->getValueUnits(3, 1) << endl;
//
// 2. query the same temperature as a float:
//
// float temperature = sensor->getValueAsFloat(3, 1);
//
// 3. Turn on the light plugged into the switch on Node 7, wait 5
// seconds, then turn it back off again:
//
// cout << "Turning ON node 7" << endl;
// sensor->setValueAsBool(7, 0, true);
//
// cout << "Sleeping for 5 seconds" << endl;
// sleep(5);
//
// cout << "Turning OFF node 7" << endl;
// sensor->setValueAsBool(7, 0, false);
//! [Interesting]
cout << "Exiting..." << endl;
delete sensor;
return 0;
}

128
examples/javascript/ozw.js Normal file
View File

@ -0,0 +1,128 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015 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 **************/
// Instantiate an OZW instance
var sensor = new sensorObj.OZW();
var defaultDev = "/dev/ttyACM0";
// if an argument was specified, use it as the device instead
if (process.argv.length > 2)
{
defaultDev = process.argv[2];
}
// 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");
if (!sensor.init(defaultDev))
{
console.log("Init failed.");
process.exit(0);
}
console.log("Initialization complete");
console.log("Dumping nodes...");
sensor.dumpNodes();
// 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: 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
// Node 3: Multi Sensor
// 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: 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
// Index: 5, Type: int32, Label: Interval, Value: 1521 seconds
// 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
// Node 7: Smart Energy Switch
// 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
// Index: 5, Type: int32, Label: Interval, Value: 1521 seconds
// 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);
//
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting...");
process.exit(0);

126
examples/python/ozw.py Normal file
View File

@ -0,0 +1,126 @@
#!/usr/bin/python
# Author: Jon Trulson <jtrulson@ics.com>
# Copyright (c) 2015 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.
import time, sys, signal, atexit
import pyupm_ozw as sensorObj
# Instantiate an OZW instance
sensor = sensorObj.OZW()
# This function lets you run code on exit
def exitHandler():
print "Exiting"
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
defaultDev = "/dev/ttyACM0"
if (len(sys.argv) > 1):
defaultDev = sys.argv[1]
# The first thing to do is create options, then lock them when done.
sensor.optionsCreate()
sensor.optionsLock()
# Next, initialize it.
print "Initializing, this may take awhile depending on your ZWave network"
if (not sensor.init(defaultDev)):
print "Init failed."
sys.exit(1)
print "Initialization complete"
print "Dumping nodes..."
sensor.dumpNodes()
# 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: 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
# Node 3: Multi Sensor
# 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: 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
# Index: 5, Type: int32, Label: Interval, Value: 1521 seconds
# 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
# Node 7: Smart Energy Switch
# 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
# Index: 5, Type: int32, Label: Interval, Value: 1521 seconds
# 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:
#
# print "Temperature:", sensor.getValueAsString(3, 1),
# sensor->getValueUnits(3, 1)
#
# 2. query the same temperature as a float:
#
# temperature = sensor.getValueAsFloat(3, 1)
#
# 3. Turn on the light plugged into the switch on Node 7, wait 5
# seconds, then turn it back off again:
#
# print "Turning ON node 7"
# sensor.setValueAsBool(7, 0, true)
#
# print "Sleeping for 5 seconds";
# time.sleep(5)
#
# print "Turning OFF node 7"
# sensor.setValueAsBool(7, 0, false);