本文整理汇总了Python中DHT22.init方法的典型用法代码示例。如果您正苦于以下问题:Python DHT22.init方法的具体用法?Python DHT22.init怎么用?Python DHT22.init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DHT22
的用法示例。
在下文中一共展示了DHT22.init方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main_client
# 需要导入模块: import DHT22 [as 别名]
# 或者: from DHT22 import init [as 别名]
def main_client(addr):
nic = network.WIZNET5K(pyb.SPI(2), pyb.Pin.board.Y5, pyb.Pin.board.Y4)
nic.ifconfig((SENSOR_IP, SENSOR_MASK, SENSOR_GATEWAY, SENSOR_DNS))
# print(nic.ifconfig())
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
count = 0
try:
s.connect(addr)
except:
pass
data = {
'serial_no':'1234567890',
'ip':SENSOR_IP,
'op':gOperator['OP_REGISTER'],
'type':gSensorType['TEMPERATURE']
}
DHT22.init()
while True:
pyb.delay(100)
hum, tem = measure()
print('%d hum:%f, tem:%f' % (count,hum, tem))
data['value'] = {'hum':hum, 'tem':tem}
count += 1
try:
send(s, 'post', '/test_pymagic', data)
print(s.recv(4096))
except:
pass
pyb.delay(1000)
示例2: measure
# 需要导入模块: import DHT22 [as 别名]
# 或者: from DHT22 import init [as 别名]
import DHT22
import pyb
def measure(led, lcd):
try:
(hum, tem) = DHT22.measure()
if ((hum == 0) and (tem == 0)) or (hum > 100):
raise ValueError('Invalid data received from sensor')
lcd.write('\nHumidity: %s%%\n Temp: %sC\n\n' % (hum, tem))
led.off()
except Exception as e:
lcd.write(str(e) + '\n')
led.on()
DHT22.init()
lcd = pyb.LCD('X')
lcd.light(True)
led_red = pyb.LED(1) # 1 = Red
while True:
measure(led_red, lcd)
pyb.delay(3000)