Giter Club home page Giter Club logo

home-monitoring-grafana's Introduction

Home sensor data monitoring with MQTT, InfluxDB and Grafana

Blog post: http://nilhcem.com/iot/home-monitoring-with-mqtt-influxdb-grafana

Projects

  • 01-mosquitto: Mosquitto Docker container configuration files
  • 02-bridge: Python script that receives MQTT data and persists those to InfluxDB
  • 03-bme280_mqtt: Arduino sketch file for the ESP8266 and the BME280 that publishes sensor data to MQTT
  • 04-mijia_ble_mqt: Python script that connects to a BTLE MiJia Temperature & Humidity sensor and publishes data to MQTT
  • 05-dht22_mqtt: Arduino sketch file for the ESP8266 and the DHT22 that publishes sensor data to MQTT

Setup

Mosquitto + InfluxDB + Grafana

Make sure you have docker and docker-compose installed.
For the example, a Raspberry Pi 3 B+ with Raspbian will be used.

Set the DATA_DIR environment variable to the path where will be stored local data (e.g. in /tmp):

export DATA_DIR=/tmp

Create data directories with write access:

mkdir -p ${DATA_DIR}/mosquitto/data ${DATA_DIR}/mosquitto/log ${DATA_DIR}/influxdb ${DATA_DIR}/grafana
sudo chown -R 1883:1883 ${DATA_DIR}/mosquitto
sudo chown -R 472:472 ${DATA_DIR}/grafana

Run docker compose:

$ docker-compose up -d

Mosquitto username and passwords are mqttuser and mqttpassword. To change these, see the Optional: Update mosquitto credentials section.

Sensors

Sensors should send data to the mosquitto broker to the following topic:
home/{peripheralName}/{temperature|humidity|battery|status}.
For example: home/bme280/temperature.

Arduino sketches for the ESP8266 are provided to communicate with a BME280 (03-bme280_mqtt) and a DHT22 (05-dht22_mqtt).
Before flashing, you need to change the WIFI_SSID, WIFI_PASSWORD, and MQTT_SERVER constants to your WiFi information and MQTT server address.

You can also use a Xiaomi MiJia Temperature & Humidity Sensor.
For more information, see 04-mijia_ble_mqtt/README.md.

Grafana setup

  • Access Grafana from http://<host ip>:3000
  • Log in with user/password admin/admin
  • Go to Configuration > Data Sources
  • Add data source (InfluxDB)
    • Name: InfluxDB
    • URL: http://influxdb:8086
    • Database: home_db
    • User: root
    • Password: root
    • Save & Test
  • Create a Dashboard
    • Add Graph Panel
    • Edit Panel
    • Data Source: InfluxDB
    • FROM: [default] [temperature] WHERE [location]=[bme280]
    • SELECT: field(value)
    • FORMAT AS: Time series
    • Draw mode: Lines
    • Stacking & Null value: Null value [connected]
    • Left Y
      • Unit: Temperature > Celcius
    • Panel title: Temperature (°C)

Optional: Update mosquitto credentials

To change default MQTT username and password, run the following, replacing [USER] and [PASSWORD]:

$ cd 01-mosquitto
$ echo -n "" > users
$ docker run --rm -v `pwd`/mosquitto.conf:/mosquitto/config/mosquitto.conf -v `pwd`/users:/mosquitto/config/users eclipse-mosquitto:1.5 mosquitto_passwd -b /mosquitto/config/users [USER] [PASSWORD]
$ cd -

Then, update the MQTT_USER and MQTT_PASSWORD constants in all the subdirectories, and launch docker compose again.

Alternative: Using docker manually instead of docker compose

$ cd 01-mosquitto
$ docker run -d -p 1883:1883 -v $PWD/mosquitto.conf:/mosquitto/config/mosquitto.conf -v $PWD/users:/mosquitto/config/users -v $DATA_DIR/mosquitto/data:/mosquitto/data -v $DATA_DIR/mosquitto/log:/mosquitto/log --name mosquitto eclipse-mosquitto:1.5
$ cd -

$ docker run -d -p 8086:8086 -v $DATA_DIR/influxdb:/var/lib/influxdb --name influxdb influxdb:1.7

$ cd 02-bridge
$ docker build -t nilhcem/mqttbridge .
$ docker run -d --name mqttbridge nilhcem/mqttbridge
$ cd -

$ docker run -d -p 3000:3000 -v $DATA_DIR/grafana:/var/lib/grafana --name=grafana grafana/grafana:5.4.3

home-monitoring-grafana's People

Contributors

nilhcem avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

home-monitoring-grafana's Issues

license

Hi Gautier,

Thanks for the article and the source code provided on this repo.

I would like to include a modified version of your docker-compose and MQTT bridge in on of my projects. Alas, This repo does not have a license, so I'm not sure what is the right way to do it.

Cheers,
Álvaro.

Wemos D1 mini broadcasting SSID

I used the code for a Wemos with BME280, it is working fine, but the Wemos is also broadcasting a default SSID.

I think the Arduino code needs to have a WiFi.mode(WIFI_STA) or something similar added to it to set the ESP chip to station mode, otherwise they seem to come out of the box with an AP mode enabled. This is not really directly effecting function, but for cleanliness should probably be addressed.

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.