diff --git a/airpi.py b/airpi.py index 1145a1d22ed718967b54e12fddf05782fd6fb740..a82aa089a4041a57358d33f269682f8fa243b99e 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 f364cfdbdec3b868ff149599c9179b9b549897d7..61cf7e43fccb392a7e3c04f7c114ce4aee522b05 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 fb1a7b6e3db26e1ced2abc7778709c56860546b9..129375afd8a5cc51710cc62c6a46f14ba16e9966 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