当前位置: 首页>>代码示例>>Python>>正文


Python dht.DHT11属性代码示例

本文整理汇总了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) 
开发者ID:IBM-Developer-Korea,项目名称:developer-badge-2018-apps,代码行数:18,代码来源:__init__.py

示例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
    ## 
开发者ID:fadushin,项目名称:esp8266,代码行数:20,代码来源:ws.py

示例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) 
开发者ID:fadushin,项目名称:esp8266,代码行数:22,代码来源:util_old.py

示例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) 
开发者ID:fadushin,项目名称:esp8266,代码行数:15,代码来源:ws.py

示例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)) 
开发者ID:fadushin,项目名称:esp8266,代码行数:16,代码来源:ws.py

示例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) 
开发者ID:fadushin,项目名称:esp8266,代码行数:16,代码来源:util_old.py

示例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) 
开发者ID:ulno,项目名称:ulnoiot-upy,代码行数:6,代码来源:dht11.py

示例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 
开发者ID:idimitrakopoulos,项目名称:illuminOS,代码行数:13,代码来源:DHT.py


注:本文中的dht.DHT11属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。