Free tech learning for everyone, from basics to pro

IoT ProjectsIoT SecurityIntermediate

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.

ComponentRole
Raspberry Pi 4 or 5 (or a small Linux VM)Host; use an SSD rather than an SD card for database writes
Eclipse MosquittoMQTT broker
TelegrafAgent that subscribes to MQTT and writes to the database
InfluxDB 2.xTime-series database with retention policies
GrafanaDashboards and alert rules
Sensor nodesFor 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

Dashboard data pathSensorspublish JSONMosquittoTLS, ACLsTelegrafsubscribesInfluxDBtime seriesGrafanagraphs, alerts
Figure 1. A common open-source chain turns MQTT messages into stored time series and live dashboards.

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

  1. Install Raspberry Pi OS Lite, update it, create a non-default user with SSH keys and enable the firewall.
  2. Install the broker: sudo apt install mosquitto mosquitto-clients.
  3. Create a small private certificate authority (CA) and a broker certificate whose name matches the Pi's hostname, then configure Mosquitto as below.
  4. Create users with sudo mosquitto_passwd -c /etc/mosquitto/passwd telegraf (drop -c for further users) and write the ACL file.
  5. Install InfluxDB, Telegraf and Grafana from the vendors' official package repositories, create a bucket called sensors and a write-only token for Telegraf.
  6. Configure Telegraf, restart it, and check data arrives in the InfluxDB data explorer.
  7. 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?
Each authenticated user may write only under sensors/ followed by their own username, so one device cannot publish data for another.
Why give Grafana a read-only database token?
Least privilege: if Grafana is compromised, the attacker cannot alter or delete stored data with its token.
Why use an SSD instead of an SD card for this project?
A time-series database writes constantly, which wears out SD cards and can corrupt data. SSDs handle sustained writes far better.

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.
Tracks your learning on this device only. See your progress on the learning paths.

About the author

Mohamed Fayas

Founder of FM TecHub. CCNA certified, with a BTEC HND in Network Engineering, and BEng (Hons) in Computer Networking and Cloud Security. He writes practical, plain-English guides on networking, security and cloud.

More about the author

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.

Stay up to date by email

New notes, tools and security news from FM TecHub, explained simply. Free.

We only use your email to send these updates. See our privacy policy.