From 90a93949675316a597134111805c4a1330abbfc9 Mon Sep 17 00:00:00 2001 From: tatico Date: Sun, 20 Oct 2013 13:21:10 +0200 Subject: [PATCH] added modified version of Adafruit_DHT_googledocs.ex.py to log on local file --- .../Adafruit_DHT_local-log-file.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 Adafruit_DHT_Driver/Adafruit_DHT_local-log-file.py diff --git a/Adafruit_DHT_Driver/Adafruit_DHT_local-log-file.py b/Adafruit_DHT_Driver/Adafruit_DHT_local-log-file.py new file mode 100755 index 00000000..e523df20 --- /dev/null +++ b/Adafruit_DHT_Driver/Adafruit_DHT_local-log-file.py @@ -0,0 +1,45 @@ +#!/usr/bin/python + +## This script is based on the examples provided by Adafruit. +## See README for Copyright information + +import subprocess +import re +import sys +import time + + +try: +# Continuously append data + while(True): + # Run the DHT program to get the humidity and temperature readings! + # open log file to write + logfile=open('temp-hum.log','a') + + output = subprocess.check_output(["./Adafruit_DHT", "22", "4"]); + print output + # search for temperature printout + matches = re.search("Temp =\s+([0-9.]+)", output) + if (not matches): + time.sleep(3) + continue + temp = float(matches.group(1)) + + # search for humidity printout + matches = re.search("Hum =\s+([0-9.]+)", output) + if (not matches): + time.sleep(3) + continue + humidity = float(matches.group(1)) + + now = time.time() + data =("%s %.1f %.1f\n") % (now,temp,humidity) + print(data) + logfile.write(data) + logfile.close() + # Wait half an hour between each measurement + time.sleep(1800) +except KeyboardInterrupt: + print("You pressed ctrl-c, quitting") + logfile.close() + sys.exit(0)