Sin descripción

ozw.js 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*jslint node:true, vars:true, bitwise:true, unparam:true */
  2. /*jshint unused:true */
  3. /*
  4. * Author: Jon Trulson <jtrulson@ics.com>
  5. * Copyright (c) 2015 Intel Corporation.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining
  8. * a copy of this software and associated documentation files (the
  9. * "Software"), to deal in the Software without restriction, including
  10. * without limitation the rights to use, copy, modify, merge, publish,
  11. * distribute, sublicense, and/or sell copies of the Software, and to
  12. * permit persons to whom the Software is furnished to do so, subject to
  13. * the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  22. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  23. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  24. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. */
  26. var sensorObj = require('jsupm_ozw');
  27. /************** Main code **************/
  28. // Instantiate an OZW instance
  29. var sensor = new sensorObj.OZW();
  30. var defaultDev = "/dev/ttyACM0";
  31. // if an argument was specified, use it as the device instead
  32. if (process.argv.length > 2)
  33. {
  34. defaultDev = process.argv[2];
  35. }
  36. // The first thing to do is create options, then lock them when done.
  37. sensor.optionsCreate();
  38. sensor.optionsLock();
  39. // Next, initialize it.
  40. console.log("Initializing, this may take awhile depending on your ZWave network");
  41. if (!sensor.init(defaultDev))
  42. {
  43. console.log("Init failed.");
  44. process.exit(0);
  45. }
  46. console.log("Initialization complete");
  47. console.log("Dumping nodes...");
  48. sensor.dumpNodes();
  49. // The following is example output of dumpNodes:
  50. //
  51. // Dumping nodes...
  52. // Node 1: Z-Stick Gen5
  53. // Node 2: Smart Switch 6
  54. // Index: 0, Type: bool, Label: Switch, Value: False
  55. // Index: 2, Type: float, Label: Energy, Value: 1.190 kWh
  56. // Index: 3, Type: float, Label: Previous Reading, Value: 1.190 kWh
  57. // Index: 4, Type: int32, Label: Interval, Value: 1521 seconds
  58. // Index: 5, Type: float, Label: Power, Value: 0.000 W
  59. // Index: 6, Type: float, Label: Voltage, Value: 121.256 V
  60. // Index: 7, Type: float, Label: Current, Value: 0.000 A
  61. // Index: 8, Type: bool, Label: Exporting, Value: False
  62. // Index: 45, Type: list, Label: Day, Value: Friday
  63. // Index: 46, Type: byte, Label: Hour, Value: 5
  64. // Index: 47, Type: byte, Label: Minute, Value: 53
  65. // Node 3: Multi Sensor
  66. // Index: 0, Type: bool, Label: Sensor, Value: True
  67. // Index: 1, Type: float, Label: Temperature, Value: 72.8 F
  68. // Index: 2, Type: float, Label: Luminance, Value: 4 lux
  69. // Index: 3, Type: float, Label: Relative Humidity, Value: 22 %
  70. // Index: 17, Type: byte, Label: Battery Level, Value: 98 %
  71. // Node 5: Minimote
  72. // Node 6: Smart Energy Switch
  73. // Index: 0, Type: bool, Label: Switch, Value: False
  74. // Index: 2, Type: float, Label: Power, Value: 0.000 W
  75. // Index: 3, Type: float, Label: Energy, Value: 1.609 kWh
  76. // Index: 4, Type: float, Label: Previous Reading, Value: 1.609 kWh
  77. // Index: 5, Type: int32, Label: Interval, Value: 1521 seconds
  78. // Index: 6, Type: float, Label: Power, Value: 0.000 W
  79. // Index: 7, Type: float, Label: Previous Reading, Value: 1.609 W
  80. // Index: 8, Type: int32, Label: Interval, Value: 1521 seconds
  81. // Index: 9, Type: bool, Label: Exporting, Value: False
  82. // Node 7: Smart Energy Switch
  83. // Index: 0, Type: bool, Label: Switch, Value: False
  84. // Index: 2, Type: float, Label: Power, Value: 0.000 W
  85. // Index: 3, Type: float, Label: Energy, Value: 0.000 kWh
  86. // Index: 4, Type: float, Label: Previous Reading, Value: 0.000 kWh
  87. // Index: 5, Type: int32, Label: Interval, Value: 1521 seconds
  88. // Index: 6, Type: float, Label: Power, Value: 0.000 W
  89. // Index: 7, Type: float, Label: Previous Reading, Value: 0.000 W
  90. // Index: 8, Type: int32, Label: Interval, Value: 1521 seconds
  91. // Index: 9, Type: bool, Label: Exporting, Value: False
  92. //
  93. // So, with the above in mind:
  94. //
  95. // 1. Query the temperature on node 3 and print it out (as a
  96. // string), along with the units of measure:
  97. //
  98. // console.log("Temperature: " + sensor.getValueAsString(3, 1) +
  99. // " " + sensor.getValueUnits(3, 1));
  100. //
  101. // 2. query the same temperature as a float:
  102. //
  103. // var temperature = sensor.getValueAsFloat(3, 1);
  104. //
  105. // 3. Turn on the light plugged into the switch on Node 7
  106. //
  107. // console.log("Turning ON node 7");
  108. // sensor.setValueAsBool(7, 0, true);
  109. //
  110. sensor = null;
  111. sensorObj.cleanUp();
  112. sensorObj = null;
  113. console.log("Exiting...");
  114. process.exit(0);