Skip to content

aktnk/mqtt-node_red-influxdb-grafana

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MQTT - Node-RED - InfluxDB - Grafana

Temperature and humidity sensor values installed in the room are received via MQTT, stored in InfluxDB using Node-RED, and monitored by Grafana.

Prerequisites

From the MQTT Broker, which receives sensor values, to Grafana for monitoring, we use Docker containers to build the system. Therefore, a docker environment must be installed and the docker compose command must be available.

This system has been tested in the following environments.

  • Ubuntu 20.04LTS environment built on WSL2 of Windows 11 Pro
  • Docker version 24.0.7
  • Docker Compose version v2.21.0
  • mosquitto-clients already installed in Ubuntu environment by sudo apt install mosquitto-clients

Usage

  1. Clone this repository

    $ git clone [email protected]:aktnk/mqtt-node_red-influxdb-grafana.git mqtt
    $ cd mqtt
    
  2. Edit ".env" file

    Edit the .env file and fill in the InfluxDB and Grafana admin username, password, and InfluxDB database name.

  3. Start each containers

    Start the container with the following command and check the message displayed.

    $ docker compose up
    
  4. Stop and Restart each containers

    After confirming that each container is running without any errors, stop the container by CTRL+C and start it up again by docker compose start.

    Aborting on container exit...
    [+] Stopping 4/4
    ✔ Container node-red  Stopped                                                                                1.0s
    ✔ Container influxdb  Stopped                                                                                0.7s
    ✔ Container mqtt      Stopped                                                                                0.8s
    ✔ Container grafana   Stopped                                                                                1.1s
    canceled
    
    $ docker compose start
    [+] Running 4/4
    ✔ Container node-red  Started                                                                                1.0s
    ✔ Container influxdb  Started                                                                                0.7s
    ✔ Container mqtt      Started                                                                                1.0s
    ✔ Container grafana   Started                                                                                0.5s
    $
    
  5. Create a password file on mqtt container

    Use the mosquitto_passwd command in the mqtt container to register a username and password that allows access to the MQTT server.

    $ docker exec -it mqtt /bin/sh
    / # cd mosquitto/config/
    /mosquitto/config # ls -la
    total 12
    drwxr-xr-x    2 mosquitt mosquitt      4096 Jan  7 08:32 .
    drwxr-xr-x    1 mosquitt mosquitt      4096 Dec  1 07:00 ..
    -rw-r--r--    1 mosquitt mosquitt       150 Jan  7 07:19 mosquitto.conf
    /mosquitto/config # mosquitto_passwd -c passwd mqtt_user
    Password:
    Reenter password:
    /mosquitto/config # ls -la
    total 16
    drwxr-xr-x    2 mosquitt mosquitt      4096 Jan  7 08:32 .
    drwxr-xr-x    1 mosquitt mosquitt      4096 Dec  1 07:00 ..
    -rw-r--r--    1 mosquitt mosquitt       150 Jan  7 07:19 mosquitto.conf
    -rw-------    1 root     root           123 Jan  7 08:32 passwd
    /mosquitto/config # exit
    
  6. Create a database on InfluxDB

    Start the influx shell on the influxdb container and use the CREATE DATABASE command to create a database with the name specified in the environment variable "INFLUXDB_DATABASE" specified in the ".env" file.

    $ docker compose exec influxdb influx
    Connected to http://localhost:8086 version 1.8.10
    InfluxDB shell version: 1.8.10
    > CREATE DATABASE db0
    > exit
    $
    
  7. Configurering Node-RED

    • Open Node-RED by accessing localhost:1880 in your browser. [Open the "Add Node" tab under "Palette Management" and add "node-red-contrib-influxdb".

    • Set up a flow in Node-RED to receive information from sensors via MQTT Broker and store it in InfluxDB.

  8. Send test datas

    Use the mosquitto_pub command to manually send test data from the sensor.

    $ mosquitto_pub -t test/sensors -m '{"p":"room1","t":22.0,"h":54}'
    $ mosquitto_pub -t test/sensors -m '{"p":"room2","t":21.0,"h":50}'
    
    
  9. Grafana Sttings

    • Open Grafana by accessing localhost:3000 in your browser. Enter the administrator user name and password specified in the .env file, you will be prompted to change the password appropriately.
    • Add InfluxDB to Datasource.
    • Set up a Time series panel on the Dashboard.

References

In constructing this environment, I referred to the following articles.

About

Receive sensors value via MQTT and monitor them with Grafana

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published