我用一个RuuviTag蓝牙传感器记录数据,它把温度值发送给我的树莓。你知道吗
根据RuuviTag Python库docu,我应该使用函数RuuviTagSensor.get_datas(handle_data)
,它启动函数handle_data()
的无限循环。
就我而言,我的设计是这样的:
def handle_data(found_data):
temperature_measurement = found_data[1]['temperature']
publish_via_mqtt(temperature_measurement)
我把一切都写在:
while True:
try:
RuuviTagSensor.get_datas(handle_data)
except Exception:
logger.exception(f"An error occurred at {datetime.now(timezone.utc)}")
reconnect_mqtt()
然而,一夜之间,我打破了。。。你知道吗
日志上说:
INFO:ruuvitag_sensor.ble_communication:Problem with hciconfig reset. Retry reset.
INFO:ruuvitag_sensor.ble_communication:Problem with hciconfig reset. Retry reset.
INFO:ruuvitag_sensor.ble_communication:Problem with hciconfig reset. Retry reset.
INFO:ruuvitag_sensor.ble_communication:Problem with hciconfig reset. Exit.
所以看起来树莓帽有蓝牙问题,并试图重新连接到鲁维斯。。。当这三次都不起作用时,他就退出了PYTHON?我说的对吗?如果脚本退出,有没有办法重新启动整个脚本或者处理这个退出?你知道吗
在库code中,如果三次尝试后传感器无法启动,则调用
exit(1)
。你知道吗调用exit将引发SystemExit异常。SystemExit不是从
Exception
继承的,因此不会被问题代码中的try/except块捕获。根据项目自述,这种行为似乎是故意的:如果要强制库继续重试,可以在程序中捕获
SystemExit
(except SystemExit:
)。你知道吗相关问题 更多 >
编程相关推荐