[英]DHT11 Temp/Humidity Sensor Web Service Error
大家好,我想通過php.wsdl Web服務發送溫度和濕度傳感器,我需要將數據解析到Web服務,以便可以將其從Web服務插入mysql數據庫。
我遇到一些有關的問題,請告知
這是我的腳本:
#!/usr/bin/python
import time
from suds.client import Client
url = "http://172.20.xxx.xx``/SCS/WebService/webS.php?wsdl"
client = Client(url)
while(True):
# Run the DHT program to get the humidity and temperature readings!
output = subprocess.check_output(["./Adafruit_DHT", "2302", "4"]);
print output
matches = re.search("Temp =\s+([0-9.]+)", output)
if (not matches):
time.sleep(3)
continue
temp = float(matches.group(1))
# search for humidity printout
matches = re.search("Hum =\s+([0-9.]+)", output)
if (not matches):
time.sleep(3)
continue
humidity = float(matches.group(1))
print "Temperature: %.1f C" % temp
print "Humidity: %.1f %%" % humidity
# Append the data , including a timestamp
try:
values = [datetime.datetime.now(), temp, humidity]
except:
print "Unable to append data. Check your connection?"
sys.exit()
這是遇到的錯誤
追溯(最近一次通話):
File "./websvc.py", line 13, in <module>
output = subprocess.check_output(["./Adafruit_DHT", "2302", "4"]);
NameError: name 'subprocess' is not defined
我正在嘗試使用本站點的本教程/腳本中的python suds。 請指教。 http://bradsrpi.blogspot.sg/2013/03/raspberry-pi-soap-web-service-client.html
@ user1449266是正確的。
你需要把
import subprocess
在文件的開頭:
#...
import time
import subprocess
from suds.client import Client
#...
然后將子模塊的名稱子下已知的,並且當subprocess.check_output
寫入則屬性check_output
子過程中找到。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.