From 19095b0ef2c87d0cdb5f52b364d7f23fc87a7c8b Mon Sep 17 00:00:00 2001 From: Tom Hartley Date: Wed, 18 Dec 2013 21:15:06 +0000 Subject: [PATCH] Added light-blinking on success & failure --- airpi.py | 15 ++++++++++++--- sensors/dht22.py | 4 ++-- settings.cfg | 2 ++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/airpi.py b/airpi.py index 1145a1d..a82aa08 100644 --- a/airpi.py +++ b/airpi.py @@ -2,6 +2,7 @@ import sys sys.dont_write_bytecode = True +import RPi.GPIO as GPIO import ConfigParser import time import inspect @@ -25,6 +26,8 @@ sensorConfig.read('sensors.cfg') sensorNames = sensorConfig.sections() +GPIO.setwarnings(False) +GPIO.setmode(GPIO.BCM) #Use BCM GPIO numbers. sensorPlugins = [] for i in sensorNames: @@ -165,7 +168,10 @@ mainConfig.read("settings.cfg") lastUpdated = 0 delayTime = mainConfig.getfloat("Main","uploadDelay") - +redPin = mainConfig.getint("Main","redPin") +greenPin = mainConfig.getint("Main","greenPin") +GPIO.setup(redPin,GPIO.OUT,initial=GPIO.LOW) +GPIO.setup(greenPin,GPIO.OUT,initial=GPIO.LOW) while True: curTime = time.time() if (curTime-lastUpdated)>delayTime: @@ -188,7 +194,10 @@ while True: working = working and i.outputData(data) if working: print "Uploaded successfully" - #Blink Green + GPIO.output(greenPin,GPIO.HIGH) else: print "Failed to upload" - #Blink Red + GPIO.output(redPin,GPIO.HIGH) + time.sleep(1) + GPIO.output(greenPin,GPIO.LOW) + GPIO.output(redPin,GPIO.LOW) diff --git a/sensors/dht22.py b/sensors/dht22.py index f364cfd..61cf7e4 100644 --- a/sensors/dht22.py +++ b/sensors/dht22.py @@ -30,13 +30,13 @@ class DHT22(sensor.Sensor): if (time.time()-tm)<2: t, h = dhtreader.lastData else: - t = time.time() + tim = time.time() try: t, h = dhtreader.read(22,self.pinNum) except Exception: t, h = dhtreader.lastData dhtreader.lastData = (t,h) - dhtreader.lastDataTime=t + dhtreader.lastDataTime=tim if self.valName == "Temperature": temp = t if self.valUnit == "Fahrenheit": diff --git a/settings.cfg b/settings.cfg index fb1a7b6..129375a 100644 --- a/settings.cfg +++ b/settings.cfg @@ -1,2 +1,4 @@ [Main] uploadDelay = 5 ;how long to wait before uploading again +redPin=10 +greenPin=22 -- GitLab