File tree Expand file tree Collapse file tree 1 file changed +12
-17
lines changed Expand file tree Collapse file tree 1 file changed +12
-17
lines changed Original file line number Diff line number Diff line change 6
6
import time
7
7
import datetime
8
8
import gspread
9
+ from DHT_Wrapper import DHT
9
10
10
11
# ===========================================================================
11
12
# Google Account Details
37
38
print "Unable to open the spreadsheet. Check your filename: %s" % spreadsheet
38
39
sys .exit ()
39
40
41
+ # Initialize sensor
42
+ d = DHT ("2302" , 4 )
43
+
40
44
# Continuously append data
41
45
while (True ):
42
46
# 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 ()
51
48
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
+
58
53
59
- print "Temperature: %.1f C" % temp
60
- print "Humidity: %.1f %%" % humidity
54
+ print "Temperature: %.1f C" % r [ " temp" ]
55
+ print "Humidity: %.1f %%" % r [ "hum" ]
61
56
62
57
# Append the data in the spreadsheet, including a timestamp
63
58
try :
64
- values = [datetime .datetime .now (), temp , humidity ]
59
+ values = [datetime .datetime .now (), r [ " temp" ], r [ "hum" ] ]
65
60
worksheet .append_row (values )
66
61
except :
67
62
print "Unable to append data. Check your connection?"
You can’t perform that action at this time.
0 commit comments