Last active
March 18, 2018 11:13
-
-
Save joelthchao/d7b18f06c624ebc7a0c8bd816bd030fa to your computer and use it in GitHub Desktop.
DHT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/home/pi/miniconda3/bin/python | |
from datetime import datetime | |
import sys | |
import Adafruit_DHT | |
def main(): | |
sensor = Adafruit_DHT.AM2302 | |
pin = 4 | |
record_file = '/home/pi/joel/dht_monitor/record/dht.csv' # TODO: change to your own path | |
timestr = datetime.now().strftime('%Y-%m-%d-%H:%M:%S') | |
humidity = None | |
temperature = None | |
try: | |
humidity, temperature = Adafruit_DHT.read_retry( | |
sensor, pin, retries=5, delay_seconds=1) | |
except ValueError as e: | |
print('Encounter sensor problem') | |
with open(record_file, 'a') as f: | |
print('{},{},{}'.format(timestr, humidity, temperature), file=f) | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment