如何解决PIGPIOD运行时无法使用adafruit DHT22库
我当前在运行Pigpio守护程序时读取adafruit DHT22温湿度传感器时遇到问题。当守护程序未运行时,代码将产生预期的结果,但是当守护程序运行时,代码将在尝试读取传感器时卡住。
humidity,temperature = Adafruit_DHT.read_retry(DHT_SENSOR,TEMP) #attempt to read temp and humidity sensor
print("Temp: %f\n" % temperature) #print temperature to console
print("Humidity: %f\n" % humidity) #print humidity to console
print("Temp and humidity tests have succeeded\n")
logging.debug("Temp and humidity tests have succeeded") #log results
except Exception as e:
print("An error occured while reading the temperature or humidity\n")
logging.error("Error,Temp and humidity sensor failed to read: %s" % e)
print("All temperature and humidity tests have been completed\n")
在这里,如果守护程序未运行,则代码将打印当前的温度和湿度,而仅在守护程序运行时移至异常。生成的日志文件具有以下例外情况:
ERROR:root:Error,Temp and humidity sensor failed to read: must be real number,not NoneType
经过一些实验,当传感器无法读取任何值时,似乎会抛出此错误,而不会在温度和湿度变量中存储任何内容。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。