Hi,
I've been running Python code on the Pi to post DHT22 data to Cosm. The Python code is part of a work-in-progress program that involves an LCD display and umpteen classes, but here is the part that posts to Cosm (nee Pachube). (NOTE: the leading tabs have been stripped out by the forum software.)
import logging
import urllib2
. . .
# fill in your feed ID here
PACHUBE_FEED_ID = "12345"
# fill in your API key here
PACHUBE_API_KEY = "xxxxxxxx"
def sendToPachube(dataPoint, floatValue):
# Note - the following codes uses the V2 Pachube API and CSV data format
url = 'http://api.pachube.com/v2/feeds/' + PACHUBE_FEED_ID + '/datastreams/' + dataPoint + '.csv?_method=put'
# HACK round to 3 decimal places and drop trailing zeros : technically not needed, but makes Pachube output nicer looking
data = ("%.3f" % floatValue).rstrip('0').rstrip('.')
headers = {'X-PachubeApiKey': PACHUBE_API_KEY}
req = urllib2.Request(url, data, headers)
try:
response = urllib2.urlopen(req)
except urllib2.HTTPError, e:
logging.exception('Error code ' + str(e.code) + ' sending to pachube, datapoint ' + dataPoint)
return False
except urllib2.URLError, e:
logging.exception('Reason code ' + e.reason + ' sending to pachube, datapoint ' + dataPoint)
return False
The 2 parms are the Cosm datapoint ID and the temperature or humidity value. (e.g. sendToPachube("OfficeHum", 38.745)). This code is basically the same as what I used in this project:
http://www.gigamegablog.com/2011/10/29/ ... -hat-trick. The above code needs to have the leading tabs inserted or it won't run, so if you want to see the original code or the full application it is from, you can download the Python code from the link in that article.
The only analog humidity sensor I own is one I bought from Seeedstudio, and they no longer carry it:
http://www.seeedstudio.com/depot/humidi ... ?cPath=190. Like most analog sensors, calibration was a pain. I'd recommend you stick with digital sensors unless you are using a device that doesn't support them (like an Xbee).
Dan.