📊

Setting Up Raspberry Pi IoT Server

Feb 22, 2025

Raspberry Pi IoT Server Setup

Objective

  • Create a Raspberry Pi IoT server to collect sensor data.
  • Visualize data using Grafana dashboard.

Project Overview

  • Sensor Node: Arduino Uno with BME 680 sensor.
    • Collects: Temperature, pressure, humidity, air quality.
    • Sends data every 2 seconds in JSON format.
    • Uses MQTT protocol to send data to Raspberry Pi server.

MQTT Protocol

  • Client/Server Communication:
    • Client publishes data to a broker/server (Mosquitto).
    • Broker forwards messages to subscribed clients.
  • Topics: Categorize data sent via MQTT (e.g., home/office).

Applications Required on Raspberry Pi

  1. Mosquitto: MQTT broker
  2. Node-RED: For data flow management
  3. InfluxDB: Database to store sensor data
  4. Grafana: Frontend for data visualization
  5. Portainer: Manage Docker containers graphically

Docker and Containers

  • Applications run in containers for easy setup and management.
  • Containers are lighter than virtual machines; run above the OS.
  • Use IoTStack to simplify Docker setup.

Getting Started

  • Raspbian OS: Fresh install (64-bit Lite version).
  • Enable SSH and set a static IP address.

Initial Setup Steps

  1. Update System:
    • sudo apt update
    • sudo apt upgrade
  2. Download IoT Stack:
    • Use curl command to install Docker and necessary packages.
  3. Restart the Pi for environment variables.

Configuring IoTStack

  • Go to IoT stack folder:
    • Run ./.menu.sh to build stack.
    • Select applications (Grafana, InfluxDB, Mosquitto, Node-RED, and Portainer).
  • Start all containers:
    • Use Docker commands to verify (docker-compose ps).
  • Access Portainer via web browser at IP:9000.

InfluxDB Configuration

  1. Enter InfluxDB container:
    • docker exec -it influxdb influx
    • Create database: create database sensor_data
  2. Exit container using quit.

Node-RED Configuration

  1. Access Node-RED via web browser at IP:1880.
  2. Create a flow with:
    • MQTT Input: Subscribe to the topic (e.g., /home/sensors).
    • Change Node: Modify JSON data keys.
    • InfluxDB Output: Configure database connection (IP, port, and measurement name).
  3. Deploy the configuration.

Testing Data Flow

  • Check InfluxDB for entries:
    • Enter InfluxDB container and run:
      • use sensor_data
      • show measurements
      • select * from sensor_data

Grafana Dashboard Setup

  1. Access Grafana dashboard at IP:3000.
    • Login: Default credentials (admin/admin).
    • Change password.
  2. Add InfluxDB as a data source:
    • Enter IP, port (8086), and database name.
    • Save and test connection.
  3. Create a new dashboard:
    • Add panels for each measurement.
    • Adjust settings and save dashboard.

Conclusion

  • Successfully created an IoT server.
  • Data from sensors visualized effectively on a Grafana dashboard.
  • Refer to the website for all commands and additional resources.