No Description

ozw.py 4.7KB

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