Giter Site home page Giter Site logo

xiaomi-mijia-bluetooth-sensor's Introduction

Xiaomi Mijia bluetooth temperature/humidity sensor

This is an application for collecting sensor measurements from Xiaomi Mijia bluetooth temperature/humidity sensor. It’s based on reading output of hcidump tool and passive scanning of BLE devices with hcitool tool. The description of a protocol used by the sensor is described at the following link: https://github.com/mspider65/Xiaomi-Mijia-Bluetooth-Temperature-and-Humidity-Sensor/blob/master/SensorProtocol.html

Dependencies

  • openjdk-11-jdk

  • bluez

  • bluez-hcidump

Build

./gradlew clean build

Usage

  1. Start scanning for BLE devices in passive mode

    hciconfig hci0 up
    hcitool lescan --passive --duplicates
    Tip

    The hcitool lescan command may fail with various errors, for example: Set scan parameters failed: Input/output error

    You may try to fix it with hciconfig hci0 reset or rfkill unblock bluetooth.

  2. Start the collector specifying MAC address(es) of sensors to monitor

    hcidump -R | ./xiaomi-mijia-bluetooth-sensor 582D3430247C 362D34303089 ...

    The following is example output:

    {"time":"2020-05-21T06:51:24.450Z","humidity":34.3,"temperature":22.1,"mac":"582D3430247C"}
    {"time":"2020-05-21T06:51:26.447Z","temperature":22.1,"mac":"582D3430247C"}
    {"time":"2020-05-21T06:51:28.454Z","humidity":34.2,"temperature":22.1,"mac":"582D3430247C"}
    {"time":"2020-05-21T06:51:34.465Z","humidity":34.1,"temperature":22.0,"mac":"582D3430247C"}
    {"time":"2020-05-21T06:51:36.465Z","humidity":34.0,"mac":"582D3430247C"}
    {"time":"2020-05-21T06:51:38.467Z","batteryLevel":31.0,"mac":"582D3430247C"}
    {"time":"2020-05-21T06:51:40.475Z","humidity":34.2,"temperature":22.0,"mac":"582D3430247C"}
    {"time":"2020-05-21T06:51:42.483Z","humidity":34.1,"temperature":22.0,"mac":"582D3430247C"}
    {"time":"2020-05-21T06:51:44.481Z","humidity":34.1,"temperature":22.1,"mac":"582D3430247C"}

Sensor data visualisation with Grafana

  1. Start collecting data from a sensor dumping measurements into file

    hcidump -R | ./xiaomi-mijia-bluetooth-sensor 582D3430247C 362D34303089 ... | tee -a /tmp/metrics.json
  2. Start several docker containers with docker-compose that will run instances of: Telegraf, InfluxDB and Grafana.

    SENSOR_METRICS_FILE_PATH=/tmp/metrics.json docker-compose up
    Note
    SENSOR_METRICS_FILE_PATH should point to the file where metrics from the application are dumped. This is the file which will be tailed by Telegrag.
  3. In Grafana, add a datasource of type InfluxDB pointing to database created by telegraf

  4. Import the dashboard: grafana-dashbpard.json or just use Explore to monitor temperature measurements:

    Data Source: InfluxDB
    From: defaul xiaomi-mijia-bluetooth-sensor
    Select: field(temperature) mean()
    Group By: time($_interval) fill(null)
    Format as: Time series.
  5. Leave things working for several hours

  6. After several hours you should observe graph(s) full of data

    grafana dashboard screenshot

xiaomi-mijia-bluetooth-sensor's People

Contributors

alexanderzobkov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

xiaomi-mijia-bluetooth-sensor's Issues

Add sensor MAC address information to influxdb/grafana

The application provides mac address information in the json output to allow to understand source of a measurement. However this information is not visible/passed to influxdb/grafana so all measurements seen as came from the same sensor even if these are came from multiple ones.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.