本文整理汇总了Python中dht.DHT11属性的典型用法代码示例。如果您正苦于以下问题:Python dht.DHT11属性的具体用法?Python dht.DHT11怎么用?Python dht.DHT11使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类dht
的用法示例。
在下文中一共展示了dht.DHT11属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import dht [as 别名]
# 或者: from dht import DHT11 [as 别名]
def main():
#h = DHT11(machine.Pin(33)) # J8
h = DHT11(machine.Pin(26)) # J7
ugfx.set_default_font('IBMPlexMono_Bold24')
ugfx.clear()
ugfx.Label(40, 0, 240, 60, text='DHT11/22 Demo')
ugfx.set_default_font('IBMPlexMono_Regular24')
l = ugfx.Label(40, 60, 240, 120, text='')
while True:
h.measure()
h.temperature()
l.text('temperature:{},humidity:{}'.format(h.temperature(), h.humidity()))
time.sleep(1)
示例2: tick
# 需要导入模块: import dht [as 别名]
# 或者: from dht import DHT11 [as 别名]
def tick(self, pin=2) :
import dht
import machine
try :
d = dht.DHT11(machine.Pin(pin))
d.measure()
tempf = 32.0 + 1.8 * d.temperature()
humidity = d.humidity()
logging.debug("Read measurements off DHT11: temp(f): %s humidity: %s" % (tempf, humidity))
self._upload(tempf, humidity)
util.clear_led_error()
except Exception as E :
logging.error("An error occurred taking measurements: %s", E)
util.set_led_error()
##
## Internal operations
##
示例3: upload
# 需要导入模块: import dht [as 别名]
# 或者: from dht import DHT11 [as 别名]
def upload(stationid, password, tempf, humidity) :
import socket
try :
#addr_info = socket.getaddrinfo(address, port)
addr_info = socket.getaddrinfo("weatherstation.wunderground.com", 80)
url = "/weatherstation/updateweatherstation.php?ID=%s&PASSWORD=%s&dateutc=now&tempf=%s&humidity=%s&softwaretype=ESP8266+DHT11&action=updateraw" % (stationid, password, tempf, humidity)
addr = addr_info[0][-1]
s = socket.socket()
s.connect(addr)
val = s.send(b"GET %s HTTP/1.0\r\nHost: weatherstation.wunderground.com\r\nUser-Agent: curl/7.43.0\r\nAccept: */*\r\n\r\n" % url)
print("send val: %s" % val)
print(s.read())
s.close()
send_status("uploaded data")
except Exception as E :
print("An error occurred: %s" % E)
#set_led_error(5)
import webrepl
webrepl.start()
raise Exception("Failed to upload data to wunderground.com: %s" % E)
示例4: run
# 需要导入模块: import dht [as 别名]
# 或者: from dht import DHT11 [as 别名]
def run(self, pin=2, sleep_s=30) :
'''Run the weather station
Take a DHT measurement from the specified pin and upload the results every
sleep_s seconds. This function runs indefinitely.
pin -- the GPIO pin from which to read DHT11 sensor data (default: 2)
sleep_s -- the number of seconds to sleep between measurements (default: 30)
'''
while True :
self.tick(pin)
logging.debug("Sleeping %s secs ..." % sleep_s)
time.sleep(sleep_s)
示例5: _upload
# 需要导入模块: import dht [as 别名]
# 或者: from dht import DHT11 [as 别名]
def _upload(self, tempf, humidity) :
import socket
addr_info = socket.getaddrinfo("weatherstation.wunderground.com", 80)
url = "/weatherstation/updateweatherstation.php?ID=%s&PASSWORD=%s&dateutc=now&tempf=%s&humidity=%s&softwaretype=ESP8266+DHT11&action=updateraw" % (self._stationid, self._password, tempf, humidity)
addr = addr_info[0][-1]
s = socket.socket()
s.connect(addr)
request = b"GET %s HTTP/1.0\r\nHost: weatherstation.wunderground.com\r\nUser-Agent: curl/7.43.0\r\nAccept: */*\r\n\r\n" % url
logging.debug("Request: %s" % request)
val = s.send(request)
logging.debug("val: %s" % val)
logging.debug("Response: %s" % s.read())
s.close()
logging.info("Uploaded tempf: %s humidity: %s to wunderground.com stationid %s", (tempf, humidity, self._stationid))
示例6: dht_test
# 需要导入模块: import dht [as 别名]
# 或者: from dht import DHT11 [as 别名]
def dht_test(pin=2, n=1, sleep_s=5) :
import dht
import machine
d = dht.DHT11(machine.Pin(pin))
for i in range(n):
d.measure()
line = "temp(f): %s humidity: %s" % (32.0 + 1.8*d.temperature(), d.humidity())
print(line)
#upload("192.168.1.154", 44404, line)
upload("KMABOXBO9", "7rwzw8bh", 32.0 + 1.8*d.temperature(), d.humidity())
#print("Going into deep sleep for %s secs ..." % sleep_secs)
#deep_sleep(sleep_secs)
print("Sleeping %s secs ..." % sleep_s)
time.sleep(sleep_s)
示例7: __init__
# 需要导入模块: import dht [as 别名]
# 或者: from dht import DHT11 [as 别名]
def __init__(self, name, pin, on_change=None, filter=None):
import dht
_HTDHT.__init__(self, name, pin, dht.DHT11(pin), 2000,
on_change=on_change, filter=filter)
示例8: __init__
# 需要导入模块: import dht [as 别名]
# 或者: from dht import DHT11 [as 别名]
def __init__(self, type, pin):
self.type = type
if self.type == 0:
self.sensor = dht.DHT11(Pin(pin))
elif self.type == 1:
self.sensor = dht.DHT22(Pin(pin))
else:
log.error("Unknown sensor type '{}'. Cannot instantiate it.".format(self.type))
# @timed_function