aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgcohen2014-12-29 21:35:06 -0800
committergcohen2014-12-29 21:35:06 -0800
commit4d17f5d927cb4f887103f0c4155413c851d37675 (patch)
treeb67f15e4ec59ff7f6257757091d0d496b9b8b03f
parentd75f4c9511bf40a5c07f7931ac3718288d908622 (diff)
downloadpubnub-python-4d17f5d927cb4f887103f0c4155413c851d37675.tar.bz2
adding PN control
-rw-r--r--python/examples/futureHouse/futureHouse.py33
-rwxr-xr-xpython/examples/getTemp_11_4.py22
2 files changed, 42 insertions, 13 deletions
diff --git a/python/examples/futureHouse/futureHouse.py b/python/examples/futureHouse/futureHouse.py
index 638b165..54d5118 100644
--- a/python/examples/futureHouse/futureHouse.py
+++ b/python/examples/futureHouse/futureHouse.py
@@ -3,6 +3,10 @@ from Pubnub import Pubnub
from Adafruit_PWM_Servo_Driver import PWM
import time
import random
+import Adafruit_BMP.BMP085 as BMP085
+import Adafruit_DHT
+
+sensor = BMP085.BMP085()
publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo-36'
subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo-36'
@@ -15,16 +19,21 @@ pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key,
channel = 'futureHouse'
+# pulse lengths have a max of 4096
+
leds = [
{'name': 'iceCaveLamp', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005},
{'name': 'iceCaveCrystal', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005},
+ {'name': 'fireplaceOrange', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005},
{'name': 'campfire', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005},
{'name': 'porchLight', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005},
- {'name': 'stove', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005},
{'name': 'fireplaceRed', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005},
- {'name': 'fireplaceOrange', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005}
+ {'name': 'stove', 'minPulseLength': 150, 'maxPulseLength': 2600, 'waitFloor': 0.0001, 'waitCeiling': 0.005}
]
+
+
+
def callback(message, channel):
# LED Setters
@@ -42,6 +51,26 @@ def callback(message, channel):
print "Setting waitFloor to: " + str(message['waitFloor'])
leds[message['ledID']]['waitFloor'] = message['waitFloor']
+ if 'getEnviro' in message:
+ enviro = {}
+ enviro['temp1'] = '{0:0.2f} *C'.format(sensor.read_temperature())
+ enviro['pres1'] = '{0:0.2f} Pa'.format(sensor.read_pressure())
+ enviro['alt1'] = '{0:0.2f} m'.format(sensor.read_altitude())
+ enviro['pres2'] = '{0:0.2f} Pa'.format(sensor.read_sealevel_pressure())
+ enviro['humidity1'], enviro['temp2'] = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11, 4)
+
+ def pubMessage(message):
+ print(message)
+
+ pubnub.publish(channel, enviro, callback=pubMessage, error=pubMessage)
+
+
+ # print "Sending Environmental Stats"
+ # print 'Temp = {0:0.2f} *C'.format(sensor.read_temperature())
+ # print 'Pressure = {0:0.2f} Pa'.format(sensor.read_pressure())
+ # print 'Altitude = {0:0.2f} m'.format(sensor.read_altitude())
+ # print 'Sealevel Pressure = {0:0.2f} Pa'.format(sensor.read_sealevel_pressure())
+ #
def error(message):
diff --git a/python/examples/getTemp_11_4.py b/python/examples/getTemp_11_4.py
index daa9770..10d6490 100755
--- a/python/examples/getTemp_11_4.py
+++ b/python/examples/getTemp_11_4.py
@@ -25,20 +25,20 @@ import Adafruit_DHT
# Parse command line parameters.
-sensor_args = { '11': Adafruit_DHT.DHT11,
- '22': Adafruit_DHT.DHT22,
- '2302': Adafruit_DHT.AM2302 }
-if len(sys.argv) == 3 and sys.argv[1] in sensor_args:
- sensor = sensor_args[sys.argv[1]]
- pin = sys.argv[2]
-else:
- print 'usage: sudo ./Adafruit_DHT.py [11|22|2302] GPIOpin#'
- print 'example: sudo ./Adafruit_DHT.py 2302 4 - Read from an AM2302 connected to GPIO #4'
- sys.exit(1)
+# sensor_args = { '11': Adafruit_DHT.DHT11,
+# '22': Adafruit_DHT.DHT22,
+# '2302': Adafruit_DHT.AM2302 }
+# if len(sys.argv) == 3 and sys.argv[1] in sensor_args:
+# sensor = sensor_args[sys.argv[1]]
+# pin = sys.argv[2]
+# else:
+# print 'usage: sudo ./Adafruit_DHT.py [11|22|2302] GPIOpin#'
+# print 'example: sudo ./Adafruit_DHT.py 2302 4 - Read from an AM2302 connected to GPIO #4'
+# sys.exit(1)
# Try to grab a sensor reading. Use the read_retry method which will retry up
# to 15 times to get a sensor reading (waiting 2 seconds between each retry).
-humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
+humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11, 4)
# Note that sometimes you won't get a reading and
# the results will be null (because Linux can't