代码拉取完成,页面将自动刷新
# coding: utf-8
import json
import os
import time
import Adafruit_DHT
# Set sensor type : Options are DHT11,DHT22 or AM2302
sensor = Adafruit_DHT.DHT11
# Set GPIO sensor is connected to
gpio = 4
# Use read_retry method. This will retry up to 15 times to
# get a sensor reading (waiting 2 seconds between each retry).
humidity, temperature = Adafruit_DHT.read_retry(sensor, gpio)
result = {'temp': int(temperature), 'humidity': int(
humidity), 'update': int(time.time())}
data_file = os.path.join(os.path.dirname(
os.path.abspath(__file__)), 'home_air.json')
with open(data_file, 'w') as out_file:
json.dump(result, out_file)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。