#!/usr/bin/python #https://blog.csdn.net/xujgcn/article/details/90670888 import Adafruit_DHT sensor = Adafruit_DHT.DHT11 pin = 4 #GPIO4 #调用一次返回温度和适度数据 # 输入警报数值 其中湿度为百分比小数 def dh11_data(alram_tem,alram_hum): humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) if humidity is not None and temperature is not None: print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity)) if temperature>alram_tem: print("waring alram_tem") if humidity>alram_hum: print("waring alram_hum ") else: print('Failed to get reading. Try again!') #主函数 def main(): dh11_data(23,5) main()
来源:https://www.cnblogs.com/kekeoutlook/p/12142989.html