Skip to main content

Xiaomi Mijia Temperature and Humidity Sensor

硬體規格

  • 名稱:小米藍芽溫溼度計
  • 型號:LYWSD03MMC

Raspberry Pi OS

安裝 Python module

# 以下指令必須用 user 帳號下執行 (non-root)
mkdir mitemp2
cd mitemp2
python -m venv env
source env/bin/activate
which python
# 記得先升級 pip 至最新版
pip install --upgrade pip
# 開始安裝套件
sudo apt install libbluetooth-dev libglib2.0-dev
pip install bluepy
pip install lywsd03mmc
pip install paho-mqtt
錯誤:ERROR: Could not build wheels for bluepy, which is required to install pyproject.toml-based projects

解決:

sudo apt install libbluetooth-dev libglib2.0-dev

Telegraf

Option 1: Python script

建立設定檔

mv /etc/telegraf/telegraf.conf /etc/telegraf/telegraf.conf.orig
telegraf --input-filter exec --output-filter influxdb_v2 config > /etc/telegraf/telegraf.conf

telegraf.conf

[[outputs.influxdb_v2]]
  urls = ["http://127.0.0.1:8086"]

  ## Token for authentication.
  token = "YOUR-TOKEN"
  ## Organization is the name of the organization you wish to write to.
  organization = "YOUR-ORAG"
  ## Destination bucket to write into.
  bucket = "YOUR-BUCKET"

  ## Timeout for HTTP messages.
  timeout = "5s"


[[inputs.exec]]
    interval = "180s"
    commands = [["sudo -u pi sh -c '/home/pi/mitemp/go-mitemp.py'"]

    ## Timeout for each command to complete.
    timeout = "30s"

    ## Data format to consume.
    ## Each data format has its own unique set of configuration options, read
    ## more about them here:
    ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
    data_format = "influx"

Option 2: MQTT Consumer