-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdaLog.py
34 lines (25 loc) · 1.03 KB
/
AdaLog.py
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
import time
from Adafruit_IO import Client, Feed
ADAFRUIT_IO_KEY = '##'
# Set to your Adafruit IO username.
# (go to https://accounts.adafruit.com to find your username).
ADAFRUIT_IO_USERNAME = '##'
# Create an instance of the REST client.
aio = Client(ADAFRUIT_IO_KEY, ADAFRUIT_IO_USERNAME)
temperature_feed = aio.feeds('temperature')
def temperatures():
from w1thermsensor import W1ThermSensor
for sensor in W1ThermSensor.get_available_sensors():
data.append(sensor.get_temperature())
return(data)
while True:
temperature = temperatures
if humidity is not None and temperature is not None:
print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature))
# Send humidity and temperature feeds to Adafruit IO
temperature = '%.2f'%(temperature)
aio.send(temperature_feed.key, str(temperature))
else:
print('Failed to get DHT22 Reading, trying again in ', '10', 'seconds')
# Timeout to avoid flooding Adafruit IO
time.sleep(10)