Raspberry Pi IoT Server Tutorial: InfluxDB, MQTT, Grafana, Node-RED & Docker

3 min read 4 months ago
Published on May 08, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Step-by-Step Tutorial: Setting Up a Raspberry Pi IoT Server with InfluxDB, MQTT, Grafana, Node-RED & Docker

Prerequisites:

  1. Raspberry Pi with a fresh install of headless Raspbian OS.
  2. Static IP address for your Raspberry Pi.
  3. Basic knowledge of using the terminal on Raspberry Pi.

Steps:

  1. Update and Install Necessary Packages:

    • Run sudo apt update and sudo apt upgrade to update the system.
    • Use the following curl command to install Docker, Docker Compose, and other necessary packages:
      curl -sSL https://get.docker.com | sh
      
    • Follow the prompts to install the required packages. This process may take some time.
  2. Setting Up Docker Containers:

    • Access the IoT stack folder on your Raspberry Pi.
    • Run the menu script with ./menu.sh.
    • Select "Build Stack" to choose the applications you want to install (Grafana, InfluxDB, Mosquito, Node-RED, and Portainer).
    • Navigate using the arrow keys and spacebar to select the applications.
    • Once selected, return to the menu and confirm your choices.
  3. Start Docker Containers:

    • In the menu, navigate to the Docker commands section and select "Start Stack" to launch all the containers.
    • Wait for the images to be downloaded and for the applications to start running.
    • Verify the containers are running by using docker-compose ps.
  4. Accessing Portainer:

    • Open a web browser and enter the IP address of your Raspberry Pi followed by port 9000 (e.g., http://<ip_address>:9000).
    • Explore Portainer to manage and interact with the Docker containers.
  5. Creating InfluxDB Database:

    • Create an InfluxDB database to store sensor data by running the following command:
      docker exec -it influxdb influx
      
    • Inside the InfluxDB container, create a database using:
      create database <database_name>
      
    • Exit the container.
  6. Configuring Node-RED:

    • Access Node-RED via a web browser by entering the IP address of your Pi and port 1880.
    • Build a workflow by configuring inputs (MQTT), processing data, and configuring outputs (InfluxDB).
  7. Setting Up Grafana Dashboard:

    • Open Grafana in a web browser by entering the IP address of your Pi.
    • Add a data source by selecting InfluxDB and entering the necessary details.
    • Create a dashboard to visualize the sensor data by adding panels and configuring data sources.
  8. Visualizing Data:

    • Customize the dashboard by selecting measurement sources, variables to plot, and adjusting plot settings.
    • Save the dashboard configuration and explore different visualization options in Grafana.
  9. Finalizing and Testing:

    • Save all configurations and settings in Grafana and Node-RED.
    • Test the setup by checking for data entries in the InfluxDB database and verifying data visualization in Grafana.
  10. Wrap Up:

    • Save your progress, close any open windows, and ensure all configurations are saved.
    • You now have a fully functional Raspberry Pi IoT server for collecting, storing, and visualizing sensor data.

Congratulations! You have successfully set up a Raspberry Pi IoT server with InfluxDB, MQTT, Grafana, Node-RED, and Docker to monitor and visualize sensor data.