Last active
December 27, 2016 04:24
-
-
Save electronut/bed9a4159c79b936ada0 to your computer and use it in GitHub Desktop.
Temperature/Humidity monitor using Raspberry Pi and DHT11. Data is displayed at thingspeak.com
This file contains 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
""" | |
dht11_thingspeak.py | |
Temperature/Humidity monitor using Raspberry Pi and DHT11. | |
Data is displayed at thingspeak.com | |
Author: Mahesh Venkitachalam | |
Website: electronut.in | |
""" | |
import sys | |
import RPi.GPIO as GPIO | |
from time import sleep | |
import Adafruit_DHT | |
import urllib2 | |
def getSensorData(): | |
RH, T = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11, 23) | |
# return dict | |
return (str(RH), str(T)) | |
# main() function | |
def main(): | |
# use sys.argv if needed | |
if len(sys.argv) < 2: | |
print('Usage: python tstest.py PRIVATE_KEY') | |
exit(0) | |
print 'starting...' | |
baseURL = 'https://api.thingspeak.com/update?api_key=%s' % sys.argv[1] | |
while True: | |
try: | |
RH, T = getSensorData() | |
f = urllib2.urlopen(baseURL + | |
"&field1=%s&field2=%s" % (RH, T)) | |
print f.read() | |
f.close() | |
sleep(15) | |
except: | |
print 'exiting.' | |
break | |
# call main | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how do you convert to F with this code?