d的重试请求

2024-05-15 19:00:04 发布

您现在位置:Python中文网/ 问答频道 /正文

(这里充其量是新手Python程序员……)

我使用一个模块来访问名为BAC0的楼宇自动化系统。当运行该脚本以通过本地Wifi局域网将BACnet与楼宇自动化系统通信以检索数据时,该脚本将从我的Windows笔记本电脑中创建一个楼宇自动化设备。你知道吗

具体地说,下面的脚本是每120秒轮询一个热水设备控制器一个离开温度传感器,然后在while True循环中每600次更新一次。你知道吗

import BAC0
import time

#alarm setpoint
setPoint = 140

#connect to device
bacnet = BAC0.lite()
hws = BAC0.device('100:99', 30099, bacnet, poll=120, history_size=10000)



while True:

    data = hws['SHWS-T']

    time.sleep(600)


    if data > setPoint:
        good = f'[INFO] - Looks good, the temp of the {data} on {time.ctime()}'
        print(good)

    else:
        bad = f'[INFO] - Looks bad, the temp of the {data} on {time.ctime()}'
        print(bad)
        print("Here's the coldest last 10 recorded boiler supply temp readings")
        print(data.history.nsmallest(n=10, keep='last'))
        print("I better get some help!")

不管怎样,每隔一段时间就会发生的是控制器没有响应,然后脚本就会停止,因为如果这。。。如果我知道如何像retry那样重试3次,然后再pass再等600秒重试,那就太好了。。。你知道吗

我知道这是不正确的下面,但像这样的东西???你知道吗

try:
     if isinstance(Exception: Problem reading : SHWS-T) 
     # retry function?
     retry()

     else:
     # This is our sensor value
     pass

完全回溯:

benbartling@benbartling-HP-ProDesk-600-G1-SFF ~/Desktop/bac0 $ python interpreter.py
2019-04-12 13:39:49,484 - INFO    | Starting BAC0 version 0.99.944 (Lite)
2019-04-12 13:39:49,513 - INFO    | Using ip : 10.30.4.200
2019-04-12 13:39:49,514 - INFO    | Starting app...
2019-04-12 13:39:49,514 - INFO    | BAC0 started
2019-04-12 13:39:49,514 - INFO    | Registered as Simple BACnet/IP App
2019-04-12 13:39:51,517 - INFO    | Changing device state to DeviceDisconnected'>
2019-04-12 13:39:57,867 - INFO    | Changing device state to RPMDeviceConnected'>
2019-04-12 13:39:58,306 - INFO    | Device 30099:[Boiler] found... building points list
2019-04-12 13:39:59,683 - INFO    | Ready!
2019-04-12 13:39:59,688 - INFO    | Polling started, values read every 120 seconds
[INFO] - Looks good, the temp of the Boiler/SHWS-T : 141.62 degreesFahrenheit on Fri Apr 12 13:50:05 2019
[INFO] - Looks good, the temp of the Boiler/SHWS-T : 141.78 degreesFahrenheit on Fri Apr 12 14:00:06 2019
[INFO] - Looks good, the temp of the Boiler/SHWS-T : 143.18 degreesFahrenheit on Fri Apr 12 14:10:06 2019
[INFO] - Looks good, the temp of the Boiler/SHWS-T : 141.33 degreesFahrenheit on Fri Apr 12 14:20:06 2019
[INFO] - Looks good, the temp of the Boiler/SHWS-T : 143.15 degreesFahrenheit on Fri Apr 12 14:30:07 2019
[INFO] - Looks good, the temp of the Boiler/SHWS-T : 141.97 degreesFahrenheit on Fri Apr 12 14:40:07 2019
[INFO] - Looks good, the temp of the Boiler/SHWS-T : 141.42 degreesFahrenheit on Fri Apr 12 14:50:07 2019
[INFO] - Looks good, the temp of the Boiler/SHWS-T : 141.96 degreesFahrenheit on Fri Apr 12 15:00:08 2019
[INFO] - Looks good, the temp of the Boiler/SHWS-T : 141.19 degreesFahrenheit on Fri Apr 12 15:10:08 2019
[INFO] - Looks good, the temp of the Boiler/SHWS-T : 141.51 degreesFahrenheit on Fri Apr 12 15:20:09 2019
[INFO] - Looks good, the temp of the Boiler/SHWS-T : 142.76 degreesFahrenheit on Fri Apr 12 15:30:15 2019
[INFO] - Looks good, the temp of the Boiler/SHWS-T : 142.10 degreesFahrenheit on Fri Apr 12 15:40:15 2019
[INFO] - Looks good, the temp of the Boiler/SHWS-T : 142.66 degreesFahrenheit on Fri Apr 12 15:50:16 2019
[INFO] - Looks good, the temp of the Boiler/SHWS-T : 142.86 degreesFahrenheit on Fri Apr 12 16:00:16 2019
[INFO] - Looks good, the temp of the Boiler/SHWS-T : 141.98 degreesFahrenheit on Fri Apr 12 16:10:16 2019
[INFO] - Looks good, the temp of the Boiler/SHWS-T : 141.67 degreesFahrenheit on Fri Apr 12 16:20:16 2019
[INFO] - Looks good, the temp of the Boiler/SHWS-T : 142.45 degreesFahrenheit on Fri Apr 12 16:30:17 2019
[INFO] - Looks good, the temp of the Boiler/SHWS-T : 143.06 degreesFahrenheit on Fri Apr 12 16:40:17 2019
Traceback (most recent call last):
  File "/home/benbartling/anaconda3/lib/python3.6/site-packages/BAC0/core/devices/Points.py", line 112, in value
    self.properties.device.properties.address, self.properties.type, str(self.properties.address)))
  File "/home/benbartling/anaconda3/lib/python3.6/site-packages/BAC0/core/io/Read.py", line 163, in read
    "APDU Abort Reason : {}".format(reason))
BAC0.core.io.IOExceptions.NoResponseFromController: APDU Abort Reason : noResponse

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "interpreter.py", line 20, in <module>
    if data > setPoint:
  File "/home/benbartling/anaconda3/lib/python3.6/site-packages/BAC0/core/devices/Points.py", line 524, in __gt__
    return self.value > other
  File "/home/benbartling/anaconda3/lib/python3.6/site-packages/BAC0/core/devices/Points.py", line 116, in value
    'Problem reading : {}'.format(self.properties.name))
Exception: Problem reading : SHWS-T

Tags: oftheinfoboilerdataontempapr
2条回答

正如您定义的轮询一样,您不需要读取逻辑中的点。尝试使用“hws[SHWS-T].lastValue”

使用对该点的调用将强制在网络上进行读取,而不是提高效率。LastValue将使用点的历史记录。你知道吗

您可以尝试使用retryingpypi包并根据需要修改您的程序。 检查https://pypi.org/project/retrying/

沿着这条线。你知道吗

@retry(stop_max_attempt_number=3)
def read_from_sensor():
   #your code here
    pass

@retry(wait_fixed=6000)
def get_sensor_reading():
    read_from_sensor()

相关问题 更多 >