360 Secure SkillHub
360 安全技能中心

Dht11 Temp

通过 Python 脚本在树莓派上读取 DHT11 传感器的温度与湿度,默认使用 GPIO 19,可通过命令行参数或 DHT_PIN 环境变量指定引脚,输出温度与湿度两行文本,需安装 RPi.GPIO 并以 sudo 运行。

noahseeger
noahseeger
热度 93.49
最近更新 2026-05-11 17:26:03
分类:自动化依赖:代码执行应用场景:自动化脚本

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add dht11-temp
Metadata
name
dht11-temp
description
Read temperature and humidity from DHT11 sensor. Supports custom GPIO pins via CLI argument or environment variable.
metadata
{"openclaw":{"emoji":"🌡️","requires":{"bins":["python3","sudo","RPi.GPIO"]}}}

DHT11 Temperature & Humidity Sensor

Read temperature and humidity from a DHT11 sensor.

Hardware Setup

Wiring (adjust pin as needed):

DHT11 Pinout:
─────────────
1. VCC     → 5V (Pin 2 oder 4)
2. DATA    → GPIO <PIN> + 10K Pull-Up Widerstand → 5V
3. GND     → GND (Pin 6)

Important: The 10K pull-up resistor must be connected between DATA and VCC (5V)!

Installation

# Install dependencies
pip3 install RPi.GPIO

Usage

Read Sensor (default pin 19)

sudo python3 scripts/dht/main.py

Read Sensor (custom pin)

sudo python3 scripts/dht/main.py 4     # Uses GPIO 4

Using Environment Variable

export DHT_PIN=4
sudo python3 scripts/dht/main.py

Output

  • Line 1: Temperature (°C)
  • Line 2: Humidity (%)

Customization

Variable Default Description
DHT_PIN 19 GPIO pin number

Example crontab entry

# Read every 30 minutes
*/30 * * * * sudo python3 ~/scripts/dht/main.py >> /var/log/dht.log 2>&1