def get_temp_humid(arg1, stop_event): #function for reading the DHT22, to be put in #thread to continuously run without interference #aio = Client('afe0b443290e43eaa49f6f7b55841bed') #adafruit io key #sensor = Adafruit_DHT.DHT22 print "in thread" GPIO.setup(temp_humid, GPIO.IN) print "past gpio setup in thread" #temperature = 0 #humidity = 0 thresh_up = 26 #degrees celsius above_thresh = 0 #initial temp reading humidity, temperature = Adafruit_DHT.read_retry(sensor, temp_humid) send_data(temperature, humidity, not GPIO.input(pow_on_rise)) #****add threshold logic here**** #loop temp readings and aio sends st_time = time.time() while (not stop_event.is_set()): end_time = time.time() #if ten minutes has passed if (ten_min(st_time, end_time) == True): #print "time elapsed-----------------" humidity, temperature = Adafruit_DHT.read_retry(sensor, temp_humid) send_data(temperature, humidity, not GPIO.input(pow_on_rise)) print temperature if temperature > thresh_up: if above_thresh == 0: send_alert("Temperature Has Raised Above Threshold\n") above_thresh = 1 GPIO.output(led_temp_stat, GPIO.LOW) else: if above_thresh == 1: send_alert("Temperature Has Returned Below Threshold\n") above_thresh = 0 GPIO.output(led_temp_stat, GPIO.HIGH) st_time = end_time #reset time interval if not alert_queue.empty() and ( inet_check.check_connection('www.adafruit.io') == True): aio.send('History', alert_queue.get()) time.sleep(3) #throttle output else: pass #print "alert queue empty" if not data_queue.empty() and ( inet_check.check_connection('www.adafruit.io') == True): aio.send('History', data_queue.get()) time.sleep(3) #throttle output else: pass
def send_alert(string): global alert_queue alert_str = time.strftime("%m/%d/%Y %H:%M:%S ") + string if (inet_check.check_connection('www.adafruit.io') == True): aio.send('Alerts', alert_str) print "Sent Alert" GPIO.output(led_inet, GPIO.HIGH) else: alert_queue.put(alert_str) print "pushed alert onto queue" GPIO.output(led_inet, GPIO.LOW) return
def send_data(temp, humid, bat_on): global data_queue if (inet_check.check_connection('www.adafruit.io') == True): aio.send('Temperature', temp) aio.send('Humidity', humid) print "Sent Data" GPIO.output(led_inet, GPIO.HIGH) else: data_str = time.strftime("%m/%d/%Y %H:%M:%S") + " Temp=" + str( temp) + " Humid=" + str(humid) + " Bat_Active=" + str( bat_on) + '\n' data_queue.put(data_str) print "**BAT_ON =" + str(bat_on) + "**" print "pushed data onto queue" GPIO.output(led_inet, GPIO.LOW) return
def test_adafruitio(self): self.assertTrue(inet_check.check_connection("www.adafruit.io"))
def test_yahoo(self): self.assertTrue(inet_check.check_connection("www.yahoo.com"))
def test_google(self): self.assertTrue(inet_check.check_connection("www.google.com"))