Building a Weather Monitoring Station and IoT Dashboard with EMQX, InfluxDB v3, and Grafana on a VPS
Introduction to Enterprise-Grade IoT Telemetry
In the era of smart infrastructure and data-driven decision-making, real-time environmental monitoring has become crucial for sectors ranging from agriculture to logistics and smart city management. Building a scalable, reliable, and high-performance Internet of Things (IoT) architecture requires selecting the right stack to handle continuous data ingestion, efficient storage, and real-time visualization.
This technical guide provides a comprehensive walkthrough for establishing a professional weather monitoring station and IoT dashboard. By leveraging EMQX as the enterprise MQTT broker, InfluxDB v3 as the high-performance time-series database, and Grafana for visual analytics—all hosted on a single Virtual Private Server (VPS)—you can build a self-hosted, secure pipeline capable of handling thousands of telemetry data points per second with minimal latency.
The Architectural Blueprint
Before diving into configuration, it is essential to understand how data flows through this IoT ecosystem. The architecture is designed around the decoupled publish-subscribe pattern to ensure maximum uptime and scalability:
- Data Generation (Edge Layer): Microcontrollers (such as ESP32 or Raspberry Pi Pico W) connected to sensors (e.g., BME280 for temperature, humidity, and pressure) collect environmental metrics. They format this data into lightweight JSON payloads.
- Data Ingestion (Message Broker): The edge devices act as MQTT clients, publishing payloads to specific topics on the EMQX MQTT broker hosted on your VPS.
- Data Processing & Storage (Time-Series Database): EMQX processes incoming messages. Through its powerful internal rule engine, it extracts the JSON payloads and writes them directly into InfluxDB v3.
- Data Visualization (Dashboard Layer): Grafana queries InfluxDB v3 using SQL or InfluxQL to render responsive, real-time dashboards accessible from any web browser.
Step 1: Preparing Your VPS and Network Environment
To ensure smooth deployment and operation, we recommend a VPS running Ubuntu 22.04 LTS or later with at least 2 vCPUs, 4GB of RAM, and SSD storage. For seamless orchestration and isolation of services, we will use Docker and Docker Compose.
First, update your system packages and install Docker by executing the following commands via SSH:
sudo apt update && sudo apt upgrade -y
sudo apt install docker.io docker-compose -y
sudo systemctl enable --now docker
Next, configure your VPS firewall (UFW) to open the necessary communication ports. This is critical for both security and functionality:
1883: MQTT standard port (for sensor connections).8883: MQTT over SSL/TLS (for secure production connections).18083: EMQX Dashboard management UI.8086: InfluxDB v3 API and interface access.3000: Grafana dashboard interface.
Step 2: Deploying the Core Infrastructure via Docker Compose
To deploy EMQX, InfluxDB v3, and Grafana simultaneously with interconnected networks, create a docker-compose.yml file in your working directory. This approach guarantees that services can securely communicate with each other using internal Docker DNS aliases.
Construct your configuration file with the following service definitions, ensuring you substitute placeholder values with strong passwords and secure tokens:
version: '3.8'
services:
emqx:
image: emqx/emqx:latest
container_name: emqx_broker
ports:
- "1883:1883"
- "8883:8883"
- "18083:18083"
volumes:
- emqx_data:/opt/emqx/data
- emqx_log:/opt/emqx/log
networks:
- iot_network
influxdb:
image: influxdb:3.0
container_name: influxdb_v3
ports:
- "8086:8086"
environment:
- INFLUXD_TLS_CERT_CONFIG=
volumes:
- influxdb_data:/var/lib/influxdb2
networks:
- iot_network
grafana:
image: grafana/grafana:latest
container_name: grafana_dashboard
ports:
- "3000:3000"
volumes:
- grafana_data:/var/lib/grafana
networks:
- iot_network
networks:
iot_network:
driver: bridge
volumes:
emqx_data:
emqx_log:
influxdb_data:
grafana_data:
Launch the stack in detached mode by running: docker-compose up -d. Verify that all three containers are actively running by executing docker ps.
Step 3: Configuring EMQX and Database Integration
EMQX stands out due to its ultra-low latency and built-in Rule Engine, which removes the need for intermediary backend code to parse MQTT topics into database records.
- Access the EMQX Dashboard by navigating to
http://your_vps_ip:18083. Log in using the default credentials (admin/public) and immediately update your password. - Navigate to the Integration -> Rules section to create a rule for parsing incoming data. Assume your weather stations publish JSON data to the topic
weather/+/telemetry. - Write the SQL rule to extract the fields:
SELECT payload.temperature AS temp, payload.humidity AS hum, payload.pressure AS press, clientid FROM "weather/+/telemetry". - Add an Action to send this filtered data to an external data source. Choose InfluxDB as the target action. Fill in your InfluxDB container endpoint (
http://influxdb:8086), your organization name, bucket name (e.g.,weather_data), and your secure API token generated from the InfluxDB UI.
Pro Tip: Always use specific MQTT topics like "weather/station_id/telemetry" rather than broad wildcards. This allows the Rule Engine to automatically extract metadata such as the location or ID of the specific station reporting the metrics.
Step 4: Crafting the Real-Time Grafana Dashboard
With data flowing automatically from your sensors into InfluxDB v3 via EMQX, the final phase is visualization. Navigate to your Grafana instance at http://your_vps_ip:3000 (default login: admin/admin).
First, add InfluxDB v3 as a Data Source. InfluxDB v3 native support enables seamless SQL querying. Input the connection URL, specify your authentication headers containing your API token, and set the default database bucket to weather_data. Test the connection to ensure Grafana can successfully reach the time-series database.
Next, create a new Dashboard and add your visualization panels:
- Time Series Graph: Use an SQL query to track historical fluctuations in temperature and atmospheric pressure over rolling windows (e.g., past 24 hours, last 7 days).
- Gauge Chart: Display immediate, current relative humidity levels using color-coded thresholds (e.g., Green for comfortable, Red for extreme dryness or saturation).
- Stat Panels: Show calculation matrices like peak maximum temperature or minimum overnight temperature recorded during the current cycle.
Conclusion and Next Steps
You have successfully constructed a scalable, self-hosted IoT weather monitoring platform on a single VPS. By utilizing EMQX to handle telemetry streams, InfluxDB v3 for compressed and optimized time-series storage, and Grafana for visual delivery, your architecture is resilient, responsive, and ready for expansion.
As you scale this project further, consider implementing enterprise security protocols. Transitioning your edge devices to communicate exclusively over port 8883 utilizing SSL/TLS certificates, setting up MQTT client authentication rules within EMQX, and adding an Nginx reverse proxy with Let's Encrypt certificates in front of your Grafana dashboard will ensure your infrastructure remains completely secure against unauthorized access.
