Monday, 26 June 2017

DHT22 sensor data send to thingspeak cloud using Raspberry Pi

DHT22 sensor data send to thingspeak cloud using Raspberry Pi:


import sys
import RPi.GPIO as GPIO
from time import sleep
import Adafruit_DHT
import urllib2
myAPI = "Your key Generated on thingspeak"
def getSensorData():
   RH, T = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, 2)
   return (str(RH), str(T))
def main():
   print 'starting...'
   baseURL = 'https://api.thingspeak.com/update?api_key=%s' % myAPI
   while True:
       try:
           RH, T = getSensorData()
           f = urllib2.urlopen(baseURL +
                               "&field1=%s&field2=%s" % (RH, T))
           print f.read()
           f.close()
           sleep(5)
       except:
           print 'exiting.'
           break
# call main
if __name__ == '__main__':
   main()


Circuit Diagram:



0 comments:

Post a Comment

if you have any doubt please let me know