How-to
Route MQTT sensor data into Grafana on an edge PC
Short answer
An MQTT broker forwards each message once and keeps no history, so Grafana cannot trend from it directly. Subscribe with Node-RED, write each payload into InfluxDB, set a 365-day retention policy, and point a Grafana data source at that database. For the example below — 720 signals sampling every 5 s — that is about 0.9 TB for a year; provision roughly 2 TB.
On this page
- Why does Grafana show nothing from my MQTT broker?
- What path do the messages take from sensor to dashboard?
- Which nodes write an MQTT payload into InfluxDB in Node-RED?
- How much storage does one year from 18 lines need?
- How do I connect Grafana to the InfluxDB database?
- What makes this pipeline fail silently?
- What hardware should host the whole stack?
- Questions asked
Your sensor messages already reach the broker, so the publish side works — what the dashboard is missing is storage. An MQTT broker delivers each message to whoever is subscribed at that instant and remembers nothing, and Grafana cannot subscribe: it queries databases only. The fix is one subscriber in between that writes a time-series database, then a Grafana data source pointed at that database: sensor → broker → Node-RED → InfluxDB → Grafana → tablet browser. This article proves each hop with its own test, sizes a year of retention for 18 lines with the arithmetic shown, names the four failures that hide behind a healthy-looking dashboard, and finishes with what to host the stack on.
Why does Grafana show nothing from my MQTT broker? #
Grafana shows nothing because a broker is a courier, not a filing cabinet: it forwards each published message to the subscribers connected at that moment and then forgets it, while Grafana can only query a database that stores rows on disk.
Retained messages do not change this — a new subscriber receives the last retained value, which is one data point, not a trend. Grafana's data-source model issues queries against stores that answer them, and an MQTT broker, whether Mosquitto, HiveMQ or another MQTT server, is not one of them. That is why the broker log fills with traffic while every panel stays empty.
Two consequences follow. No broker setting — more topics, a different QoS, a second listener — will put history behind Grafana; the missing piece is a writer, not a configuration change. And broker access comes first: if the broker still needs accounts, TLS and per-topic rules, work through the secure Mosquitto MQTT lab broker with Node-RED guide, because every later hop reuses its credentials and port decisions.
What path do the messages take from sensor to dashboard? #
Use five hops — sensor or PLC to broker, broker to Node-RED, Node-RED to InfluxDB, InfluxDB to Grafana, Grafana to the tablet's browser — and prove each hop with its own test before moving to the next.
| Hop | Configure | Proof before moving on |
|---|---|---|
| Sensor to broker | Broker host, listener port, credentials, publish topic | An independent subscriber prints a message on each sensor change |
| Broker to Node-RED | Same endpoint, matching topic filter | The debug node shows topic and raw payload |
| Node-RED to InfluxDB | Database endpoint, credentials, target database and retention policy | A direct query returns the inserted timestamp and value |
| InfluxDB to Grafana | Data source URL, database, credentials | The data source test passes and a panel returns rows |
| Grafana to tablet | Grafana address and view-only login reachable from the tablet's network | The dashboard loads in the tablet browser |
Work the table top to bottom, because a successful publication proves only the hop you tested. The Node-RED host must resolve the broker's name and reach its port from its own segment; InfluxDB must accept the Node-RED host on its port; the tablet's segment must route to Grafana's. Test each service port from the actual client host instead of assuming a default, confirm firewalls allow return traffic — a TCP connection needs packets in both directions — and where TLS is on, check the certificate name and system time on the connecting host, because clock skew breaks otherwise-valid sessions.
The database-and-dashboard half of this design survives even if acquisition changes later: if a line ends up polled straight from a PLC instead of arriving by MQTT, selecting pymodbus, InfluxDB and Grafana for SCADA compares that variant of the same stack.
Which nodes write an MQTT payload into InfluxDB in Node-RED? #
Three nodes do the whole job: an MQTT input node that subscribes to the broker, a function node that parses the payload and maps the fields, and an InfluxDB output node that writes each value with its timestamp.
- Add an MQTT input node, set the broker endpoint and credentials you verified in the table above, and subscribe to a topic filter that covers exactly the wanted sensors —
plant/line1/#in this example. - Wire it to a debug node set to show the complete message, deploy, and check that topic and raw payload match your independent capture.
- Add a function node that parses and validates the payload: for JSON, check that every field the database contract needs is present and numeric, and route any parse or validation failure to a dead-letter output instead of writing a zero.
- Fix the timestamp policy: use the source timestamp when the device sends one, stamp on arrival when it does not, and never mix the two inside one measurement.
- Map the record so identity stays separate from the reading — line and sensor as tags, the numeric value as the field, quality as a field when the source carries one.
- Add the InfluxDB output node from the InfluxDB palette, set the server, database and the 365-day retention policy from the sizing section, and deploy again.
- Trigger one known sensor change, then query the database directly — not through Grafana — and match the stored value and timestamp to the message that produced it.
The record this flow writes is a contract between the publisher and the database; the field names below are illustrative:
{
"line": "line-7",
"sensor": "temp-3",
"ts": "2025-01-15T08:00:05Z",
"value": 42.7,
"quality": "good"
}
If the debug node stays silent while the broker logs publications, the subscription itself is the fault, and the fixes for missing MQTT sensor data in Node-RED start with the topic filter and session settings.
How much storage does one year from 18 lines need? #
For the example plant — 720 signals storing one record every 5 seconds at 200 measured bytes per record — a year needs 908 GB of primary storage, so set the retention policy to 365 days and provision a 2 TB volume.
Primary storage is N × R × B × D, where N is the number of stored signals, R the stored records per signal per day, B the measured database bytes per record including index overhead, and D the retention in days.
Worked example, with illustrative inputs and the arithmetic shown:
- N = 18 lines × 40 signals = 720
- R = 86,400 s ÷ 5 s = 17,280 records per signal per day
- B = 200 bytes (placeholder until measured — see below)
- D = 365
720 × 17,280 = 12,441,600 records per day.
12,441,600 × 200 B = 2,488,320,000 B per day, about 2.5 GB.
2,488,320,000 × 365 = 908,236,800,000 B, about 908 GB or 0.91 TB.
Add 50% headroom for compaction, index growth and backup staging: 908 × 1.5 = 1,362 GB, so the 2 TB volume above is the decision.
Measure B rather than trusting any figure: run one full day of real ingest, take the database's on-disk growth for that day, and divide by the records it reports written. Every input moves the total linearly — halving the sample period to 2.5 s doubles the year to about 1.8 TB, and the same holds for signal count. The example load also fixes the write rate: 12,441,600 ÷ 86,400 s = 144 writes per second on average, which is what sizes the host later.
For deeper trade-offs around hosting this same stack yourself, the self-hosted Node-RED, InfluxDB and Grafana historian sizing guide goes further.
How do I connect Grafana to the InfluxDB database? #
In Grafana, open Connections in the left-side menu, choose Add new connection, search for InfluxDB, select the InfluxDB data source, click Add new data source, then fill in the URL, database name and credentials and run the test.
Point the URL at the address InfluxDB actually listens on — 8086 is its documented default — and match the remaining fields to the version: database and retention policy under InfluxQL on 1.x, organization, bucket and token on 2.x.
Then prove it with rows, not the test button alone: build one panel over the measurement written earlier, set the time range to the last hour, and confirm the value you matched in the direct query appears at the same timestamp. Only then is the dashboard connected.
If the source test passes but panels stay empty, the usual culprits are database versus bucket, a measurement name typo, or a time range with no data — the same family of causes laid out in Grafana showing no Telegraf data in InfluxDB.
What makes this pipeline fail silently? #
Four failures stay invisible on a healthy-looking dashboard: a retention policy shorter than promised, a restart replaying a retained message as a new sample, malformed payloads written as zeros, and dropped writes during a broker outage.
- Retention drift. Attach every write to the 365-day policy and audit it by querying a timestamp from six months back; an empty result means the policy is deleting on schedule, which is correct only if six months sits inside your promise.
- Retained replay. Do not set the retain flag on measurement topics. If a publisher must retain, have the flow compare the incoming source timestamp against the last stored one and discard anything older, or every Node-RED restart turns the last state into a fresh-looking sample.
- Zeros from malformed payloads. A parse failure must reach the dead-letter path, never the database: a run of zeros in a trend is nearly indistinguishable from a real process excursion.
- Outages and duplicates. QoS 1 delivers at least once, so a reconnect can replay messages — deduplicate on the source timestamp — and a database rejection is lost unless the flow checks the write node's error output. The trade-offs between delivery levels are compared in choosing QoS and FFT analysis for MQTT vibration alerts.
Treat the dashboard as trustworthy only once all four are handled; until then it demos well and audits badly.
What hardware should host the whole stack? #
Run Node-RED, InfluxDB and Grafana together on one fanless industrial PC inside the OT network: the example load is 144 writes per second on average, which a current fanless box with an SSD and 8 GB of RAM handles with room to spare.
Place the host next to the broker's switch, feed it from the panel's 24 V DC supply, and put the 2 TB volume on solid-state storage — the rate is low but constant, and storage without power-loss protection is where edge databases die first. Fanless construction is the cabinet answer: check the datasheet's declared operating-temperature range against the cabinet's worst case, not the room's.
When the line is new and the host must be specified rather than improvised, pick a fanless industrial mini PC sized for the RAM and storage above and mount it in the cabinet on the broker's network drop. Keep Grafana and the broker off the internet: the tablet reads the dashboard over the plant network or a VPN, never through a raw port-forward out of the OT segment.
The decision: one fanless edge PC co-hosting all three services covers this example outright; split them across machines only when a second plant's worth of lines lands on the same database.
Questions asked
Does the tablet need any app installed to view the dashboard?
No. Grafana serves its interface in a browser, so the tablet only needs the server address and a viewer-level login. A viewer account can open, scroll and full-screen dashboards but cannot edit panels or data sources, which is exactly the split a shop-floor tablet wants.
What happens to sensor data while the broker or database is down?
Samples published while the Node-RED subscription is disconnected are lost unless the session is persistent with QoS 1 or higher, and writes the database rejects are lost unless the flow retries them. Plan for gaps after any outage, and mark the gap on the dashboard rather than letting a flat line read as a calm process.
How much network bandwidth does a 5-second poll of 720 signals use?
About 144 messages per second. At roughly 150 bytes of payload each, that is 21,600 bytes per second, or about 0.17 Mbit/s — nothing on a 100 Mbit/s plant network. Bandwidth never sizes this design; the 908 GB storage figure is what decides the hardware.
Can something other than Node-RED subscribe to the broker and write InfluxDB?
Yes. Any collector with an MQTT consumer can subscribe, parse and write — Telegraf's MQTT consumer is the common example — and Grafana reads the database either way. Node-RED earns its place because the parsing logic sits visible in a flow, which makes field mapping and dead-letter handling easy to review during commissioning.