Lab: Node-RED dashboard for sensor data
In short: Node-RED is a low-code tool that wires inputs, logic and outputs together in the browser. You connect it to your MQTT broker, show sensor readings on a dashboard and lock down the editor, which otherwise lets anyone run code on the host.
Aim and what you need
The aim is a live web dashboard of the temperature and humidity your ESP32 publishes. Node-RED represents logic as flows: boxes called nodes joined by wires. It is popular for IoT prototypes because you can connect MQTT, HTTP, databases and dashboards quickly.
- A Raspberry Pi or Linux machine with Docker.
- The secured broker from the MQTT TLS lab, with a
dashboarduser that can readlab/#, and the lab CA certificate. - A sensor publishing JSON such as
{"t": 21.6, "h": 48}tolab/sensor1/env, ormosquitto_pubto fake it.
Steps
- Start Node-RED with a named volume so flows survive restarts.
- Generate a password hash and add an
adminAuthblock tosettings.jsin the data volume, then restart. - Open
http://<pi-address>:1880, log in, and from Manage palette install the dashboard package (Dashboard 2.0 is published as@flowfuse/node-red-dashboard). - Drag in an mqtt in node. Add a broker: host
broker.lab.example, port 8883, enable TLS with your CA file, and the dashboard username and password. Topiclab/+/env, output: parsed JSON object. - Add a change or function node that sets
msg.payloadto the temperature, then wire it to a gauge and a chart. Repeat for humidity. - Deploy, then open the dashboard URL shown in the sidebar.
docker volume create node_red_data
docker run -d --name nodered --restart unless-stopped -p 1880:1880 -v node_red_data:/data nodered/node-red
npx node-red-admin hash-pw
docker exec -it nodered sh
vi /data/settings.js
# adminAuth: {
# type: "credentials",
# users: [{ username: "admin", password: "<bcrypt-hash>", permissions: "*" }]
# },
exit
docker restart nodered
# function node body
msg.payload = Number(msg.payload.t);
msg.topic = "temperature";
return msg;
# test message
mosquitto_pub -h broker.lab.example -p 8883 --cafile ca.crt -u sensor1 -P '<sensor1-password>' -t lab/sensor1/env -m '{"t":21.6,"h":48}'
How to verify and troubleshoot
The mqtt in node should show a green connected label. Add a debug node to see each message in the sidebar. The gauge should move when you publish a test value, and the chart should build a line over a few minutes. Open the editor in a private browser window: it must ask for a login.
- Node shows disconnected: wrong port, CA file or credentials, or the name does not match the broker certificate.
- Gauge shows nothing: the payload is still an object; check with a debug node and convert to a number.
- Editor still open without login: the
adminAuthblock is commented out or in the wrong file; check the container logs. - Lost flows after update: you forgot the volume; always mount
/data.
Security notes and clean-up
The Node-RED editor can run JavaScript and shell commands, so an exposed editor is a full compromise of the host. Keep it on the LAN or behind a VPN, use HTTPS through a reverse proxy if anyone else uses it, install only well-maintained nodes and export your flows (menu, Export) to Git, leaving credentials out. To remove the lab: docker rm -f nodered and, if you are sure, docker volume rm node_red_data.
Tip: a screenshot of a working dashboard plus a diagram of the data path makes a strong portfolio entry; see the IoT monitoring project.
Practice
Why is an unprotected Node-RED editor so dangerous?
Why mount a volume at /data?
Your gauge does not move but the debug node shows {"t":21.6,"h":48}. What is wrong?
Key takeaways
- Node-RED wires inputs, logic and outputs as visual flows.
- Connect to the broker over TLS with a read-only user.
- Always enable adminAuth before anything else.
- Persist /data and back up flows without secrets.
- Never expose the editor to the internet.
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.