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:
- Raspberry Pi with a fresh install of headless Raspbian OS.
- Static IP address for your Raspberry Pi.
- Basic knowledge of using the terminal on Raspberry Pi.
Steps:
-
Update and Install Necessary Packages:
- Run
sudo apt update
andsudo 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.
- Run
-
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.
-
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
.
-
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.
- Open a web browser and enter the IP address of your Raspberry Pi followed by port 9000 (e.g.,
-
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.
- Create an InfluxDB database to store sensor data by running the following command:
-
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).
-
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.
-
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.
-
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.
-
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.