Skip to content

Commit b92f0c4

Browse files
committed
Updates google docs example to use DHT python wrapper
1 parent b239f83 commit b92f0c4

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

Adafruit_DHT_Driver/Adafruit_DHT_googledocs.ex.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import time
77
import datetime
88
import gspread
9+
from DHT_Wrapper import DHT
910

1011
# ===========================================================================
1112
# Google Account Details
@@ -37,31 +38,25 @@
3738
print "Unable to open the spreadsheet. Check your filename: %s" % spreadsheet
3839
sys.exit()
3940

41+
# Initialize sensor
42+
d = DHT("2302", 4)
43+
4044
# Continuously append data
4145
while(True):
4246
# Run the DHT program to get the humidity and temperature readings!
43-
44-
output = subprocess.check_output(["./Adafruit_DHT", "2302", "4"]);
45-
print output
46-
matches = re.search("Temp =\s+([0-9.]+)", output)
47-
if (not matches):
48-
time.sleep(3)
49-
continue
50-
temp = float(matches.group(1))
47+
r = d.read()
5148

52-
# search for humidity printout
53-
matches = re.search("Hum =\s+([0-9.]+)", output)
54-
if (not matches):
55-
time.sleep(3)
56-
continue
57-
humidity = float(matches.group(1))
49+
if not r:
50+
time.sleep(3)
51+
continue
52+
5853

59-
print "Temperature: %.1f C" % temp
60-
print "Humidity: %.1f %%" % humidity
54+
print "Temperature: %.1f C" % r["temp"]
55+
print "Humidity: %.1f %%" % r["hum"]
6156

6257
# Append the data in the spreadsheet, including a timestamp
6358
try:
64-
values = [datetime.datetime.now(), temp, humidity]
59+
values = [datetime.datetime.now(), r["temp"], r["hum"]]
6560
worksheet.append_row(values)
6661
except:
6762
print "Unable to append data. Check your connection?"

0 commit comments

Comments
 (0)