coldnut
Posts: 8
Joined: Sun Mar 31, 2013 6:01 pm

Upload DHT22 Sensor Data to Xively Feed: C & Python

Thu Aug 22, 2013 10:15 pm

I am trying to modify some of the predefined code that exists for the DHT22 [1] sensor. I would like to modify Adafruit's DHT_Driver [2] so that it returns an array corresponding to the Temperature value and Humidity value that the sensor outputs. I would like to make this change so that I can utilize the output array in a Python snippet. Namely, I want to use the output array values to upload data to a Xively feed.

I am looking for something similar to this...

Code: Select all

    #!/usr/bin/env python
    import time
    import os
    import eeml
    
    # Xively variables specific to my account.
    API_KEY = 'API Key Here'
    FEED = 'FEED # Here'
    API_URL = '/v2/feeds/{feednum}.xml' .format(feednum = FEED)
    
    # Continuously read data from the DHT22 sensor and upload
    # the results to the Xively feed. 
    while True:
    	# Read the data from the sensor.
    	sensorData = .... // Call on the main method within the DHT_Driver.c file
    	temp_C = sensorData[0]
    	humidity = sensorData[1]
    	
    	if DEBUG:
    		print("sensorData:\t", sensorData)
    		print("\n")
     
    	if LOGGER:
    		# Initialize the users Xively account.
    		pac = eeml.Pachube(API_URL, API_KEY)
     
    		# Prepare the data to be uploaded to the Xively
    		# account.
    		# temp_C & humidity are extracted from their indices
    		# above.
    		pac.update([eeml.Data(0, temp_C, unit=eeml.Celsius())])
    		pac.update([eeml.Data(1, humidity, unit=eeml.%())])
     
    		# Upload the data to the Xively account.
    		pac.put()
     
    		# Wait 30 seconds to avoid flooding the Xively feed.
    		time.sleep(30)
I need some feedback on getting the Temperature and Humidity vaules from the sensor. It must utilize `C` because Python isn't fast enough to process the data from the sensor. Ideally I could just return an array containing the two values and access the values like this:

Code: Select all

    temp_C = sensorData[0]
    humidity = sensorData[1]
Also, if, within this Python snippet, I were to call on the main method within the DHT_Driver.c file would this be limited by the Python interpreter (i.e. will the C based program run with similar performance to a Python based program)?

I am very unfamiliar with Python and I am just beginning C so if there are any suggestions and or positive criticism, please feel free to chime in.


[1]: http://www.adafruit.com/datasheets/DHT22.pdf
[2]: https://github.com/adafruit/Adafruit-Ra ... ruit_DHT.c

Return to “C/C++”