-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththingspeak_dht11.py
More file actions
62 lines (25 loc) · 964 Bytes
/
thingspeak_dht11.py
File metadata and controls
62 lines (25 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import thingspeak
import time
import Adafruit_DHT
channel_id = 337694 # PUT CHANNEL ID HERE
write_key = '1U7S57YRHU7ZMJ2H' # PUT YOUR WRITE KEY HERE
#read_key = 'IE2OR54QVDSC653P' # PUT YOUR READ KEY HERE
pin = 3
#sensor = Adafruit_DHT.DHT11
def measure(channel):
try:
humidity, temperature = Adafruit_DHT.read_retry(11, 3)
# write
response = channel.update({'field1': temperature, 'field2': humidity})
# read
#read = channel.get({})
print ("Humidity = {} %; Temperature = {} C".format(humidity, temperature))
except:
print("connection failed")
if __name__ == "__main__":
channel = thingspeak.Channel(id=channel_id, api_key=write_key)
while True:
measure(channel)
# free account has an api limit of 15sec
time.sleep(15)
##https://tutorials-raspberrypi.com/log-raspberry-pi-sensor-data-with-thingspeak-and-analyze-it/