Hi I am having trouble coecting a simple temp,humidity,dew point logger to Thingspeak, this code was working (I thought it was anyway) put this project down for a couple of weeks now having problems.
when I run it I get the following
Traceback (most recent call last):
File "DHH-test5.py", line 14, in <module>
co.request("POST", "/update", params,)
File "/usr/lib/python2.7/httplib.py", line 1001, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python2.7/httplib.py", line 1035, in _send_request
self.endheaders(body)
File "/usr/lib/python2.7/httplib.py", line 997, in endheaders
self._send_output(message_body)
File "/usr/lib/python2.7/httplib.py", line 850, in _send_output
self.send(msg)
File "/usr/lib/python2.7/httplib.py", line 812, in send
self.coect()
File "/usr/lib/python2.7/httplib.py", line 793, in coect
self.timeout, self.source_address)
File "/usr/lib/python2.7/socket.py", line 553, in create_coection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Ero -2] Name or service not known
My code is as follows
import sys
import Adafruit_DHT
import time
import httplib, urllib
for x in range(0,500):
humidity, temperature = Adafruit_DHT.read_retry(11, 4)
if humidity is not None and temperature is not None:
DP= temperature-(100-humidity)/5
print x,'minutes---Temp={0:0.1f} deg C Humidity={1:0.1f}% Dewpoint={2:0.2f} deg c'.format(temperature,humidity,DP)
print ' '
params = urllib.urlencode({'field1':temperature, 'field2': humidity, 'field3':DP,'key': 'app key here'})
co = httplib.HTTPCoection("api.thingspeak.com:80")
co.request("POST", "/update", params,)
response = co.getresponse()
print response.status, response.reason
data = response.read()
co.close()
time.sleep(20)
else:
print 'Failed to get reading. Try again!'
Thanks in advance
Craig
