iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 18
0
IoT

制霸IoT 30Day!系列 第 18

Day 18 藍芽溫濕度計使用

藍芽 溫濕度計

今天介紹一下比較生活篇的應用藍芽 溫濕度計的資料收集與呈現。

米家藍牙溫濕度計

今天登場的是小米的米家藍牙溫濕度計

米家藍牙溫濕度計

米家藍牙溫濕度計

  • 產品名稱: 米家藍牙溫濕度計
  • 產品型號: LYWSDCGQ/01ZM
  • 產品重量: 43 g
  • 屏幕尺寸: 1.78 英寸
  • 溫度量程: -9.9℃ ~ 60℃
  • 濕度量程: 0 ~ 99.9%
  • 額定功率: 0.18 mW
  • 電池: 4 號電池(AAA)×1

主要特點即時監測室內溫濕度變化家中溫濕度一目了然溫濕度與人體舒適度、健康情況息息相關。

LCD 螢幕顯示,字體清晰,輕鬆讀取。
但是如果要自行收集資料整合呢?是否可行?

藍牙溫濕度計 偵測

我們這邊使用 bluetoothctl 來做裝置掃描與讀取測試,各位可以看到米家藍牙溫濕度計(MJ_HT_V1)接收讀取到詳盡的資訊。

  • 供應商/製造商 Vendor specific: Xiaomi Inc.
  • 電池服務:0000180f-0000-1000-8000-00805f9b34fb
    Battery Service
  • 傳統的 Bluetooth Device 透過 SDP service 使用 Profile UUID 去讓兩者相連:00000001-0000-1000-8000-00805f9b34fb
    SDP
pi@ras2:~ $ sudo bluetoothctl
[NEW] Controller B8:27:EB:C9:C4:A8 ras2 [default]
[NEW] Device 4C:65:A8:DA:1F:CC MJ_HT_V1
[NEW] Primary Service
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service002d
	0000fe95-0000-1000-8000-00805f9b34fb
	Xiaomi Inc.
[NEW] Characteristic
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service002d/char0039
	00000014-0000-1000-8000-00805f9b34fb
	Hardcopy Data Channel
[NEW] Characteristic
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service002d/char0037
	00000013-0000-1000-8000-00805f9b34fb
	Unknown
[NEW] Characteristic
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service002d/char0035
	00000010-0000-1000-8000-00805f9b34fb
	UPNP
[NEW] Characteristic
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service002d/char0033
	00000004-0000-1000-8000-00805f9b34fb
	Unknown
[NEW] Characteristic
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service002d/char0031
	00000002-0000-1000-8000-00805f9b34fb
	Unknown
[NEW] Characteristic
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service002d/char002e
	00000001-0000-1000-8000-00805f9b34fb
	SDP
[NEW] Descriptor
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service002d/char002e/desc0030
	00002902-0000-1000-8000-00805f9b34fb
	Client Characteristic Configuration
[NEW] Primary Service
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service0025
	00001530-1212-efde-1523-785feabcd123
	Vendor specific
[NEW] Characteristic
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service0025/char002b
	00001534-1212-efde-1523-785feabcd123
	Vendor specific
[NEW] Characteristic
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service0025/char0028
	00001531-1212-efde-1523-785feabcd123
	Vendor specific
[NEW] Descriptor
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service0025/char0028/desc002a
	00002902-0000-1000-8000-00805f9b34fb
	Client Characteristic Configuration
[NEW] Characteristic
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service0025/char0026
	00001532-1212-efde-1523-785feabcd123
	Vendor specific
[NEW] Primary Service
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service001a
	0000180a-0000-1000-8000-00805f9b34fb
	Device Information
[NEW] Characteristic
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service001a/char0023
	00002a26-0000-1000-8000-00805f9b34fb
	Firmware Revision String
[NEW] Characteristic
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service001a/char0021
	00002a27-0000-1000-8000-00805f9b34fb
	Hardware Revision String
[NEW] Characteristic
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service001a/char001f
	00002a25-0000-1000-8000-00805f9b34fb
	Serial Number String
[NEW] Characteristic
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service001a/char001d
	00002a24-0000-1000-8000-00805f9b34fb
	Model Number String
[NEW] Characteristic
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service001a/char001b
	00002a29-0000-1000-8000-00805f9b34fb
	Manufacturer Name String
[NEW] Primary Service
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service0016
	0000180f-0000-1000-8000-00805f9b34fb
	Battery Service
[NEW] Characteristic
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service0016/char0017
	00002a19-0000-1000-8000-00805f9b34fb
	Battery Level
[NEW] Descriptor
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service0016/char0017/desc0019
	00002902-0000-1000-8000-00805f9b34fb
	Client Characteristic Configuration
[NEW] Primary Service
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service000c
	226c0000-6476-4566-7562-66734470666d
	Vendor specific
[NEW] Characteristic
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service000c/char0012
	226cbb55-6476-4566-7562-66734470666d
	Vendor specific
[NEW] Descriptor
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service000c/char0012/desc0015
	00002902-0000-1000-8000-00805f9b34fb
	Client Characteristic Configuration
[NEW] Descriptor
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service000c/char0012/desc0014
	00002901-0000-1000-8000-00805f9b34fb
	Characteristic User Description
[NEW] Characteristic
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service000c/char000d
	226caa55-6476-4566-7562-66734470666d
	Vendor specific
[NEW] Descriptor
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service000c/char000d/desc0011
	00002904-0000-1000-8000-00805f9b34fb
	Characteristic Format
[NEW] Descriptor
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service000c/char000d/desc0010
	00002902-0000-1000-8000-00805f9b34fb
	Client Characteristic Configuration
[NEW] Descriptor
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service000c/char000d/desc000f
	00002901-0000-1000-8000-00805f9b34fb
	Characteristic User Description
[NEW] Primary Service
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service0008
	00001801-0000-1000-8000-00805f9b34fb
	Generic Attribute Profile
[NEW] Characteristic
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service0008/char0009
	00002a05-0000-1000-8000-00805f9b34fb
	Service Changed
[NEW] Descriptor
	/org/bluez/hci0/dev_4C_65_A8_DA_1F_CC/service0008/char0009/desc000b
	00002902-0000-1000-8000-00805f9b34fb
	Client Characteristic Configuration
[CHG] Device 4C:65:A8:DA:1F:CC ServicesResolved: no
[CHG] Device 4C:65:A8:DA:1F:CC Connected: no
[bluetooth]# exit
.......
...
pi@ras2:~ $

藍牙溫濕度計 MQTT

這邊我們介紹如何接收米家藍牙溫濕度計資料送到 MQTT。
依樣我先不介紹寫程式,的方式而是使用套件快速來使用。

這邊使用的是xiaomi-ble-mqtt是 python 開發的程式。
那我們依照說明直接安裝下載:

安裝系統套件:

sudo pip3 install bluepy
sudo pip3 install paho-mqtt

clone 程式:

git clone https://github.com/algirdasc/xiaomi-ble-mqtt.git
cd xiaomi-ble-mqtt

複製 devices.ini.sample 到 devices.ini 做編輯設定

devices.ini

[bedroom] ;;名稱
device_mac = 4C:65:A8:DA:1F:CC ;;裝置藍牙位置
topic = sensors/mi/1 ;;MQTT 消息
availability_topic = sensors/mi/availability ;;MQTT 狀態 消息
average = 5 ;;平均
timeout = 10 ;;遇時間

執行測試,各位可以看到已經抓到完整資料連同電池狀態都有。

pi@ras2:~/xiaomi-ble-mqtt $ /usr/bin/python3.5 /home/pi/xiaomi-ble-mqtt/data-read.py
2019-10-03 22:00:56.451549 bedroom  :  {"battery": 62.0, "humidity": 56.6, "average": 5, "temperature": 27.2}
pi@ras2:~/xiaomi-ble-mqtt $

加入排程定時擷取資料。

pi@ras2:~/xiaomi-ble-mqtt $ crontab -e
* * * * * /usr/bin/python3.5 /home/pi/xiaomi-ble-mqtt/data-read.py >> /home/pi/xiaomi-ble-mqtt/xiaomi-ble.log 2>&1

此時我們使用 MQTT 軟體 連線去訂閱看看資料:

MQTT Client

這裡可以看到資料順利接收!!

藍牙溫濕度計 資料統計到圖表

那我們現在把它啟動送資料到 influsDB 依樣使用 Grafana 來呈現.
建立一個新的設定檔 telegraf-ble.conf

pi@ras2:~ $ cat telegraf-ble.conf
[[inputs.mqtt_consumer]]
  ## MQTT broker URLs to be used. The format should be scheme://host:port,
  ## schema can be tcp, ssl, or ws.
  servers = ["tcp://192.168.0.51:1883"]

  ## Topics that will be subscribed to.
  topics = [
    "sensors/mi/#",
  ]

  ## The message topic will be stored in a tag specified by this value.  If set
  ## to the empty string no topic tag will be created.
  # topic_tag = "topic"

  ## QoS policy for messages
  ##   0 = at most once
  ##   1 = at least once
  ##   2 = exactly once
  ##
  ## When using a QoS of 1 or 2, you should enable persistent_session to allow
  ## resuming unacknowledged messages.
  # qos = 0

  ## Connection timeout for initial connection in seconds
  # connection_timeout = "30s"

  ## Maximum messages to read from the broker that have not been written by an
  ## output.  For best throughput set based on the number of metrics within
  ## each message and the size of the output's metric_batch_size.
  ##
  ## For example, if each message from the queue contains 10 metrics and the
  ## output metric_batch_size is 1000, setting this to 100 will ensure that a
  ## full batch is collected and the write is triggered immediately without
  ## waiting until the next flush_interval.
  # max_undelivered_messages = 1000

  ## Persistent session disables clearing of the client session on connection.
  ## In order for this option to work you must also set client_id to identity
  ## the client.  To receive messages that arrived while the client is offline,
  ## also set the qos option to 1 or 2 and don't forget to also set the QoS when
  ## publishing.
  # persistent_session = false

  ## If unset, a random client ID will be generated.
  client_id = "Telegraf-ble-duhvebwv"

  ## Optional TLS Config
  # tls_ca = "/etc/telegraf/ca.pem"
  # tls_cert = "/etc/telegraf/cert.pem"
  # tls_key = "/etc/telegraf/key.pem"
  ## Use TLS but skip chain & host verification
  # insecure_skip_verify = false

  ## 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 = "json"

[[outputs.influxdb]]
  urls = ["http://192.168.0.51:8086"]

  database = "db0"

  username = "telegraf"
  password = "telegraf"

執行 Docker

$ docker run -d --name=telegraf-ble   -v $PWD/telegraf-ble.conf:/etc/telegraf/telegraf.conf:ro   arm32v7/telegraf

設定圖表!

MQTT Client

這裡我們就可以方便地用複製再修改即可。

MQTT Client

選擇訂閱的資料

MQTT Client

在選擇欄位

MQTT Client

這裡可以看到最後的呈現!

MQTT Client

再做點調整增加

最後分享一下這個儀表板。 只要用匯入即可。

{
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "-- Grafana --",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "editable": true,
  "gnetId": null,
  "graphTooltip": 0,
  "id": 2,
  "links": [],
  "panels": [
    {
      "gridPos": {
        "h": 9,
        "w": 5,
        "x": 0,
        "y": 0
      },
      "id": 2,
      "options": {
        "fieldOptions": {
          "calcs": [
            "mean"
          ],
          "defaults": {
            "mappings": [],
            "max": 50,
            "min": 0,
            "thresholds": [
              {
                "color": "blue",
                "value": null
              },
              {
                "color": "green",
                "value": 18
              },
              {
                "color": "yellow",
                "value": 27
              },
              {
                "color": "red",
                "value": 38
              }
            ],
            "title": "客廳溫度",
            "unit": "celsius"
          },
          "override": {},
          "values": false
        },
        "orientation": "auto",
        "showThresholdLabels": false,
        "showThresholdMarkers": true
      },
      "pluginVersion": "6.3.6",
      "targets": [
        {
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "measurement": "mqtt_consumer",
          "orderByTime": "ASC",
          "policy": "default",
          "refId": "A",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "value"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": [
            {
              "key": "topic",
              "operator": "=",
              "value": "home/temp"
            }
          ]
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "",
      "type": "gauge"
    },
    {
      "gridPos": {
        "h": 9,
        "w": 5,
        "x": 5,
        "y": 0
      },
      "id": 7,
      "options": {
        "fieldOptions": {
          "calcs": [
            "mean"
          ],
          "defaults": {
            "mappings": [],
            "max": 50,
            "min": 0,
            "thresholds": [
              {
                "color": "blue",
                "value": null
              },
              {
                "color": "green",
                "value": 18
              },
              {
                "color": "yellow",
                "value": 27
              },
              {
                "color": "red",
                "value": 38
              }
            ],
            "title": "臥室溫度",
            "unit": "celsius"
          },
          "override": {},
          "values": false
        },
        "orientation": "auto",
        "showThresholdLabels": false,
        "showThresholdMarkers": true
      },
      "pluginVersion": "6.3.6",
      "targets": [
        {
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "measurement": "mqtt_consumer",
          "orderByTime": "ASC",
          "policy": "default",
          "refId": "A",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "temperature"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": [
            {
              "key": "topic",
              "operator": "=",
              "value": "sensors/mi/1"
            }
          ]
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "",
      "type": "gauge"
    },
    {
      "gridPos": {
        "h": 9,
        "w": 4,
        "x": 10,
        "y": 0
      },
      "id": 12,
      "options": {
        "displayMode": "lcd",
        "fieldOptions": {
          "calcs": [
            "mean"
          ],
          "defaults": {
            "mappings": [],
            "max": 100,
            "min": 0,
            "thresholds": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ],
            "title": "臥室裝置電量"
          },
          "override": {},
          "values": false
        },
        "orientation": "vertical"
      },
      "pluginVersion": "6.3.6",
      "targets": [
        {
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "measurement": "mqtt_consumer",
          "orderByTime": "ASC",
          "policy": "default",
          "refId": "A",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "battery"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": [
            {
              "key": "topic",
              "operator": "=",
              "value": "sensors/mi/1"
            }
          ]
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "",
      "type": "bargauge"
    },
    {
      "gridPos": {
        "h": 9,
        "w": 5,
        "x": 14,
        "y": 0
      },
      "id": 3,
      "options": {
        "fieldOptions": {
          "calcs": [
            "mean"
          ],
          "defaults": {
            "mappings": [],
            "max": 100,
            "min": 0,
            "thresholds": [
              {
                "color": "red",
                "value": null
              },
              {
                "color": "green",
                "value": 40
              },
              {
                "color": "dark-blue",
                "value": 70
              }
            ],
            "title": "客廳濕度",
            "unit": "humidity"
          },
          "override": {},
          "values": false
        },
        "orientation": "auto",
        "showThresholdLabels": false,
        "showThresholdMarkers": true
      },
      "pluginVersion": "6.3.6",
      "targets": [
        {
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "measurement": "mqtt_consumer",
          "orderByTime": "ASC",
          "policy": "default",
          "refId": "A",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "value"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": [
            {
              "key": "topic",
              "operator": "=",
              "value": "home/hum"
            }
          ]
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "",
      "type": "gauge"
    },
    {
      "gridPos": {
        "h": 9,
        "w": 5,
        "x": 19,
        "y": 0
      },
      "id": 8,
      "options": {
        "fieldOptions": {
          "calcs": [
            "mean"
          ],
          "defaults": {
            "mappings": [],
            "max": 100,
            "min": 0,
            "thresholds": [
              {
                "color": "red",
                "value": null
              },
              {
                "color": "green",
                "value": 40
              },
              {
                "color": "dark-blue",
                "value": 70
              }
            ],
            "title": "臥室濕度",
            "unit": "humidity"
          },
          "override": {},
          "values": false
        },
        "orientation": "auto",
        "showThresholdLabels": false,
        "showThresholdMarkers": true
      },
      "pluginVersion": "6.3.6",
      "targets": [
        {
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "measurement": "mqtt_consumer",
          "orderByTime": "ASC",
          "policy": "default",
          "refId": "A",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "humidity"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": [
            {
              "key": "topic",
              "operator": "=",
              "value": "sensors/mi/1"
            }
          ]
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "",
      "type": "gauge"
    },
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "fill": 0,
      "fillGradient": 0,
      "gridPos": {
        "h": 7,
        "w": 12,
        "x": 0,
        "y": 9
      },
      "id": 5,
      "legend": {
        "avg": false,
        "current": false,
        "max": false,
        "min": false,
        "rightSide": false,
        "show": true,
        "total": false,
        "values": false
      },
      "lines": true,
      "linewidth": 1,
      "nullPointMode": "connected",
      "options": {
        "dataLinks": []
      },
      "percentage": false,
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "alias": "濕度",
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "measurement": "mqtt_consumer",
          "orderByTime": "ASC",
          "policy": "default",
          "refId": "A",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "value"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": [
            {
              "key": "topic",
              "operator": "=",
              "value": "home/hum"
            }
          ]
        }
      ],
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "客廳濕度歷史",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "decimals": null,
          "format": "humidity",
          "label": "濕度",
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        },
        {
          "format": "celsius",
          "label": "溫度",
          "logBase": 1,
          "max": null,
          "min": null,
          "show": false
        }
      ],
      "yaxis": {
        "align": true,
        "alignLevel": null
      }
    },
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "fill": 0,
      "fillGradient": 0,
      "gridPos": {
        "h": 7,
        "w": 12,
        "x": 12,
        "y": 9
      },
      "id": 9,
      "legend": {
        "avg": false,
        "current": false,
        "max": false,
        "min": false,
        "rightSide": false,
        "show": true,
        "total": false,
        "values": false
      },
      "lines": true,
      "linewidth": 1,
      "nullPointMode": "connected",
      "options": {
        "dataLinks": []
      },
      "percentage": false,
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "alias": "濕度",
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "measurement": "mqtt_consumer",
          "orderByTime": "ASC",
          "policy": "default",
          "refId": "A",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "humidity"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": [
            {
              "key": "topic",
              "operator": "=",
              "value": "sensors/mi/1"
            }
          ]
        }
      ],
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "臥室濕度歷史",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "decimals": null,
          "format": "humidity",
          "label": "濕度",
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        },
        {
          "format": "celsius",
          "label": "溫度",
          "logBase": 1,
          "max": null,
          "min": null,
          "show": false
        }
      ],
      "yaxis": {
        "align": true,
        "alignLevel": null
      }
    },
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "fill": 0,
      "fillGradient": 0,
      "gridPos": {
        "h": 6,
        "w": 12,
        "x": 0,
        "y": 16
      },
      "id": 6,
      "legend": {
        "avg": false,
        "current": false,
        "max": false,
        "min": false,
        "rightSide": false,
        "show": true,
        "total": false,
        "values": false
      },
      "lines": true,
      "linewidth": 1,
      "nullPointMode": "connected",
      "options": {
        "dataLinks": []
      },
      "percentage": false,
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "alias": "溫度",
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "hide": false,
          "measurement": "mqtt_consumer",
          "orderByTime": "ASC",
          "policy": "default",
          "refId": "B",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "value"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": [
            {
              "key": "topic",
              "operator": "=",
              "value": "home/temp"
            }
          ]
        }
      ],
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "客廳溫度歷史",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "decimals": null,
          "format": "celsius",
          "label": "溫度",
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        },
        {
          "format": "celsius",
          "label": "溫度",
          "logBase": 1,
          "max": null,
          "min": null,
          "show": false
        }
      ],
      "yaxis": {
        "align": true,
        "alignLevel": null
      }
    },
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "fill": 0,
      "fillGradient": 0,
      "gridPos": {
        "h": 6,
        "w": 12,
        "x": 12,
        "y": 16
      },
      "id": 10,
      "legend": {
        "avg": false,
        "current": false,
        "max": false,
        "min": false,
        "rightSide": false,
        "show": true,
        "total": false,
        "values": false
      },
      "lines": true,
      "linewidth": 1,
      "nullPointMode": "connected",
      "options": {
        "dataLinks": []
      },
      "percentage": false,
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "alias": "溫度",
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "hide": false,
          "measurement": "mqtt_consumer",
          "orderByTime": "ASC",
          "policy": "default",
          "refId": "B",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "temperature"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": [
            {
              "key": "topic",
              "operator": "=",
              "value": "sensors/mi/1"
            }
          ]
        }
      ],
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "客廳溫度歷史",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "decimals": null,
          "format": "celsius",
          "label": "溫度",
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        },
        {
          "format": "celsius",
          "label": "溫度",
          "logBase": 1,
          "max": null,
          "min": null,
          "show": false
        }
      ],
      "yaxis": {
        "align": true,
        "alignLevel": null
      }
    }
  ],
  "refresh": "5s",
  "schemaVersion": 19,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": []
  },
  "time": {
    "from": "now-6h",
    "to": "now"
  },
  "timepicker": {
    "refresh_intervals": [
      "5s",
      "10s",
      "30s",
      "1m",
      "5m",
      "15m",
      "30m",
      "1h",
      "2h",
      "1d"
    ]
  },
  "timezone": "",
  "title": "家裡溫度",
  "uid": "v3CR7GmRz",
  "version": 7
}

結語

今天介紹 將生活中的藍芽 Bluetooth 裝置直接拿來應用,配合圖表監看很容易分析幾家裡電器(冷氣使用狀況喔)!

Blog 同步刊登


上一篇
Day 17 藍芽偵測使用
下一篇
Day 19 藍芽資料發送接收
系列文
制霸IoT 30Day!30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言