这段代码是通过 output = subprocess.check_output(["./readTemp", "25"]);
读取树莓派DHT11的温度然后上传到yeelink 代码可以正常运行,无限循环上传,但是上传一段时间后就会卡住不动了,然后用try捕捉然后想用continue继续运行程序,但是捕捉不会执行except:这块代码,但是ctrl+C后就继续执行了,很疑惑求指教。。。。。
求大神赐教为什么会卡住不执行?
代码如下:
#!/home/pi/cc
'''
#=============================================================================
# FileName: doRead.py
# Desc:
# Author: wangheng
# Email: wujiwh@gmail.com
# HomePage: http://wangheng.org
# Version: 0.0.1
# LastChange: 2015-01-27 22:40:37
# History:
#=============================================================================
'''
import subprocess
import re
import json
import sys
import time
import datetime
import requests
API_Headers = {'U-ApiKey': '8aa382fead8acc965d4536fdfda6478c', 'content-type': 'application/json'}
hum_url ="http://api.yeelink.net/v1.0/device/223765/sensor/242406/datapoints"
temp_url ="http://api.yeelink.net/v1.0/device/223765/sensor/242363/datapoints"
# Continuously append data
while(True):
try:
#to get the humidity and temperature readings!
output = subprocess.check_output(["./readTemp", "25"]);
#print output
matches = re.search("Temp=([0-9.]+)C", output)
if (not matches):
time.sleep(3)
continue
temp = float(matches.group(1))
# search for humidity printout
matches = re.search("Hum=([0-9.]+)\%", output)
if (not matches):
time.sleep(3)
continue
humidity = float(matches.group(1))
print "Temperature: %.1f C" % temp
print "Humidity: %.1f %%" % humidity
except:
print "ERR 1234567890"
#sys.exit()
continue
try:
#Post temp data
post_data = {'value': temp}
r = requests.post(temp_url, headers=API_Headers, data=json.dumps(post_data))
#Post Humidity data
post_data = {'value': humidity}
r = requests.post(hum_url, headers=API_Headers, data=json.dumps(post_data))
print "Post to yeelink success!"
except:
print "Unable to post data. Check your connection?"
sys.exit()
# Wait seconds before continuing
#time.sleep(1)
读取树莓派DHT11的温度然后上传到yeelink 代码可以正常运行,无限循环上传,但是上传一段时间后就会卡住不动了,然后用try捕捉然后想用continue继续运行程序,但是捕捉不会执行except:这块代码,但是ctrl+C后就继续执行了,很疑惑求指教。。。。。
求大神赐教为什么会卡住不执行?
代码如下:
#!/home/pi/cc
'''
#=============================================================================
# FileName: doRead.py
# Desc:
# Author: wangheng
# Email: wujiwh@gmail.com
# HomePage: http://wangheng.org
# Version: 0.0.1
# LastChange: 2015-01-27 22:40:37
# History:
#=============================================================================
'''
import subprocess
import re
import json
import sys
import time
import datetime
import requests
API_Headers = {'U-ApiKey': '8aa382fead8acc965d4536fdfda6478c', 'content-type': 'application/json'}
hum_url ="http://api.yeelink.net/v1.0/device/223765/sensor/242406/datapoints"
temp_url ="http://api.yeelink.net/v1.0/device/223765/sensor/242363/datapoints"
# Continuously append data
while(True):
try:
#to get the humidity and temperature readings!
output = subprocess.check_output(["./readTemp", "25"]);
#print output
matches = re.search("Temp=([0-9.]+)C", output)
if (not matches):
time.sleep(3)
continue
temp = float(matches.group(1))
# search for humidity printout
matches = re.search("Hum=([0-9.]+)\%", output)
if (not matches):
time.sleep(3)
continue
humidity = float(matches.group(1))
print "Temperature: %.1f C" % temp
print "Humidity: %.1f %%" % humidity
except:
print "ERR 1234567890"
#sys.exit()
continue
try:
#Post temp data
post_data = {'value': temp}
r = requests.post(temp_url, headers=API_Headers, data=json.dumps(post_data))
#Post Humidity data
post_data = {'value': humidity}
r = requests.post(hum_url, headers=API_Headers, data=json.dumps(post_data))
print "Post to yeelink success!"
except:
print "Unable to post data. Check your connection?"
sys.exit()
# Wait seconds before continuing
#time.sleep(1)
