Project: an MQTT sensor dashboard
In short: This project builds a small monitoring stack for your sensors. Mosquitto receives MQTT messages over TLS, Telegraf subscribes and writes them into InfluxDB, and Grafana draws graphs and sends alerts. Securing the broker and the web dashboard is as much a part of the build as the graphs.
What you will build and what you need
You will turn the readings from your sensor projects into live graphs with history and alerts, all hosted on your own hardware. The same pattern, broker plus collector plus time-series database plus visualisation, is used in industry, so the skills transfer directly to work.
| Component | Role |
|---|---|
| Raspberry Pi 4 or 5 (or a small Linux VM) | Host; use an SSD rather than an SD card for database writes |
| Eclipse Mosquitto | MQTT broker |
| Telegraf | Agent that subscribes to MQTT and writes to the database |
| InfluxDB 2.x | Time-series database with retention policies |
| Grafana | Dashboards and alert rules |
| Sensor nodes | For example the temperature monitor |
A simpler alternative is Node-RED, which can subscribe to MQTT and draw basic charts with little configuration. The stack below takes longer but scales and keeps history properly.
Design
Sensors publish JSON to sensors/<device-id>/env. Only the broker port (8883) is reachable from the IoT network. InfluxDB listens on the Pi itself, and Grafana is reachable only from your management network or through a VPN.
Build steps
- Install Raspberry Pi OS Lite, update it, create a non-default user with SSH keys and enable the firewall.
- Install the broker:
sudo apt install mosquitto mosquitto-clients. - Create a small private certificate authority (CA) and a broker certificate whose name matches the Pi's hostname, then configure Mosquitto as below.
- Create users with
sudo mosquitto_passwd -c /etc/mosquitto/passwd telegraf(drop-cfor further users) and write the ACL file. - Install InfluxDB, Telegraf and Grafana from the vendors' official package repositories, create a bucket called
sensorsand a write-only token for Telegraf. - Configure Telegraf, restart it, and check data arrives in the InfluxDB data explorer.
- In Grafana, add InfluxDB as a data source with a read-only token, build panels and add an alert rule.
# /etc/mosquitto/conf.d/secure.conf
listener 8883
cafile /etc/mosquitto/certs/ca.crt
certfile /etc/mosquitto/certs/broker.crt
keyfile /etc/mosquitto/certs/broker.key
allow_anonymous false
password_file /etc/mosquitto/passwd
acl_file /etc/mosquitto/acl
# /etc/mosquitto/acl
user telegraf
topic read sensors/#
pattern write sensors/%u/#
# /etc/telegraf/telegraf.d/mqtt.conf
[[inputs.mqtt_consumer]]
servers = ["ssl://pi-broker.lan:8883"]
topics = ["sensors/+/env"]
username = "telegraf"
password = "${MQTT_PASS}"
tls_ca = "/etc/telegraf/ca.crt"
data_format = "json"
topic_tag = "topic"
[[outputs.influxdb_v2]]
urls = ["http://127.0.0.1:8086"]
token = "${INFLUX_TOKEN}"
organization = "home"
bucket = "sensors"
The pattern line uses %u for the username, so a device that logs in as temp01 can write only under sensors/temp01/. Secrets are read from environment variables set in the Telegraf service file rather than typed into the config.
Security checklist and next steps
- Broker: no anonymous access, TLS only, per-device users, ACLs, and no port forwarding from the internet.
- Tokens: separate write-only (Telegraf) and read-only (Grafana) InfluxDB tokens.
- Grafana: change the default admin password at first login, disable sign-up, and reach it over HTTPS or a VPN.
- Host: automatic security updates, SSH keys only, a host firewall allowing just 8883 from the IoT VLAN and 22/3000 from management.
- Data: set a retention period on the bucket and back up the configs and dashboards.
Next, add alerts for missing data (a sensor that goes quiet), and practise reading the broker log at /var/log/mosquitto/mosquitto.log to spot failed logins.
Practice
What does the ACL line 'pattern write sensors/%u/#' achieve?
Why give Grafana a read-only database token?
Why use an SSD instead of an SD card for this project?
Key takeaways
- Broker, collector, time-series database and dashboard is a standard monitoring pattern.
- Secure Mosquitto with TLS, no anonymous access and per-device ACLs.
- Use separate least-privilege tokens for writing and reading data.
- Keep Grafana and InfluxDB off the IoT network and the internet.
- Alert on missing data as well as on bad values.
Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.