我无法将简单的温度,湿度,露点记录器连接到Thingspeak,这段代码正在运行(我认为无论如何)将这个项目放下了几个星期,现在遇到了问题。
当我运行它时,我得到以下
Traceback (most recent call last):
File "DHH-test5.py", line 14, in <module>
conn.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.connect()
File "/usr/lib/python2.7/httplib.py", line 793, in connect
self.timeout, self.source_address)
File "/usr/lib/python2.7/socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -2] Name or service not known
我的代码如下
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'})
conn = httplib.HTTPConnection("api.thingspeak.com:80")
conn.request("POST", "/update", params,)
response = conn.getresponse()
print response.status, response.reason
data = response.read()
conn.close()
time.sleep(20)
else:
print 'Failed to get reading. Try again!'
答案 0 :(得分:0)
解决了,由于某种原因,我的wifi连接已连接,但无法上网,重新安装raspbian并再次尝试和工作