IMD SolutionComputing LibraryShop main store

Troubleshooting

Extract single InfluxDB fields from Node-RED for a dashboard chart

Edge computing and IIoT Published 8 min read

Short answer

Store each sensor value as its own numeric field, then chart one field: parse the comma-separated MQTT payload into an object with the CSV node, select the temperature field from the measurement in ascending time order, and reshape the returned rows into the point array the dashboard chart expects. A write that lands as one string leaves no selectable temperature field, so fix the parse and write path before touching the chart.

On this page
  1. Why does the chart stay empty when the writes succeed?
  2. What does the payload BMP2801 temp=23.57,pres=1013.8 actually store?
  3. How do you split one comma-separated payload into separate fields?
  4. Which query returns only the temperature series?
  5. How do you shape the query result for the dashboard chart?
  6. How do you prove the fix with one known reading?
  7. Which mistakes bring the empty chart back?
  8. Questions asked

You do not need a cleverer query; you need two things stored correctly: separate numeric fields at write time, and a query result reshaped into the point array the dashboard chart expects. Convert the comma-separated sensor payload into an object with the CSV node, keep temp and pres as numbers, then query one field with SELECT "temp" FROM "BMP2801" ORDER BY time ASC and rebuild the returned rows as chart points. If the writer received the entire line BMP2801 temp=23.57,pres=1013.8 as one string, the database holds a single text value, no query returns a numeric temperature series, and the fix belongs in the write path, not in the chart.

Why does the chart stay empty when the writes succeed? #

A successful write only proves that something reached the database; the chart needs one numeric field delivered as the point array the chart node documents, so the fault sits in how the payload was stored or how the query result was reshaped.

Trace one reading end to end and tap the wire at each handoff with a Debug node, wired in parallel so it never disturbs the flow:

  • MQTT in output — the raw payload text and its data type
  • after the parser — the object, its property names and their types
  • writer input — the exact message the database node receives
  • query result — the returned rows, keys and timestamps
  • chart input — the point array as the chart finally sees it

A tap that shows the whole sensor line as one string convicts the parse stage; a tap that shows correct numbers feeding a flat chart convicts the query or the reshape. The same tracing discipline across the whole stack is what troubleshooting missing data in a Node-RED, InfluxDB and Grafana stack walks through step by step.

What does the payload BMP2801 temp=23.57,pres=1013.8 actually store? #

That line follows InfluxDB line protocol: the text before the space, BMP2801, is the measurement, and each equal-signed pair after it is a named field, so a writer that receives the whole string as one payload may store a single text value instead of two numeric fields.

In line protocol the space separates the measurement from the field set, the commas separate the field pairs, and each equals sign binds a name to a value. A writer that documents raw line-protocol input can take the string exactly as the sensor publishes it. Most Node-RED database writers instead expect a JavaScript object, and what they do with a plain string varies by node version: some refuse it at write time, others store the line as one text field. Either outcome matches the reported symptom, queries that appear to succeed while no usable series comes back.

Before trusting any query, list what the measurement really holds. Any InfluxQL console answers with SHOW FIELD KEYS FROM "BMP2801", and temp must appear there with a numeric type. If it does not, no SELECT statement will help, because the field was never split at write time. Note also that the stored name is whatever the writer used, BMP2801 with its trailing 1, not the sensor model — the query must match the stored name exactly.

How do you split one comma-separated payload into separate fields? #

Convert the comma-separated text into a JavaScript object before the writer sees it: the CSV node does this in one step, mapping each value onto a named property so the database receives temp and pres as two separate numeric fields.

Work in this order:

  1. Check the MQTT in node's output tap. Plain comma-separated text stays a string; the node's parsed JSON output only helps when the device actually publishes JSON, and setting it on CSV text splits nothing.
  2. Add the CSV node with a comma delimiter, and give it the two column names in its columns setting so the first value lands in temp and the second in pres. With columns defined, a one-row input comes out as an object.
  3. Read the tap after the node: both properties must be numbers, not quoted strings.
  4. Drop bad samples. A small check that rejects a row missing either number keeps zeros out of the trend, where they would plot as a false cold snap.
  5. Give the writer its object and one source for the measurement name — its own configuration or the message, never both.
  6. Write one controlled reading and query it back before reconnecting the chart.

If the device publishes the complete line-protocol string rather than bare values, that string is not two-column CSV: the measurement prefix and the equals signs break a naive split. Either publish bare values from the device, split the string in a function node, or hand the line to a writer that documents raw line-protocol input. Splitting one transport message into one field per value is the same discipline whether the mapper is a Node-RED node or Telegraf; turning an MQTT topic into InfluxDB fields with Telegraf shows the mapping done at the collector instead of in the flow.

Which query returns only the temperature series? #

On a database that accepts InfluxQL, SELECT "temp" FROM "BMP2801" ORDER BY time ASC returns exactly the temperature series, oldest sample first, once the measurement and field names in your database really are BMP2801 and temp.

The statement selects temp and ignores pres, and ORDER BY time ASC puts the oldest sample at the left edge, where most charts expect history to begin. Restate the two conditions before running it: the measurement name and the field name are the ones your field-list check shows, not the ones you intended to store.

For a dashboard, bound the query to the visible window instead of reading the whole measurement. In InfluxQL a time predicate does that, so the working form becomes SELECT "temp" FROM "BMP2801" WHERE time > now() - 1h ORDER BY time ASC, which keeps the last hour. Scope the exact statement to the query language your node speaks: an interface configured for Flux rejects InfluxQL, and rewriting the stored sensor values cannot fix a query-language mismatch — the equivalent range-and-filter expression in that language is the fix.

Inspect one returned row before wiring the chart: the row must carry a timestamp and the temperature value together, or the reshape stage has nothing valid to work with.

How do you shape the query result for the dashboard chart? #

The query node returns an array of rows, one object per stored sample, each carrying a timestamp and the selected field, while the chart node consumes a point array with its own documented keys, so a small function node rebuilds every row as one chart point.

Print msg.payload on a Debug tap first and use the key names it actually shows. The next block is illustrative: time and temp are the row keys a temperature query returns, while x and y stand in for the point keys your chart node's help documents for the installed dashboard version.

// Illustrative reshape; confirm both key sets on Debug taps first.
var points = [];
var rows = msg.payload;              // array of query result rows
for (var i = 0; i < rows.length; i++) {
    points.push({
        x: Date.parse(rows[i].time), // sample timestamp in milliseconds
        y: Number(rows[i].temp)      // coerced in case a row held text
    });
}
msg.payload = points;
return msg;

Two details decide whether the chart tells the truth. First, the timestamp: the query returns the time stored at write, so the points land in the past at their true positions instead of arriving as live readings at the top of the window. Second, the unit: the numbers carry whatever scale the sensor library applies, so convert once, at one deliberate node, and label the pen with that unit.

How do you prove the fix with one known reading? #

Write one controlled reading whose values you know, then read the same number at four Debug taps between the MQTT input and the chart, because the tap where the value first changes or disappears marks the faulty stage.

Run one injection through the repaired path:

  1. Inject a two-value payload at the CSV node's input, in the publisher's own order.
  2. Tap after the CSV node: the object shows temp of 23.57 and pres of 1013.8, both numeric.
  3. Let the write land, run the temperature query, and read the returned row: the field reads the injected temperature and the timestamp is the write time.
  4. Tap after the reshape function: one point, carrying the same temperature at that timestamp.
  5. Read the chart: a single dot at that position on the temperature pen, and the pressure value nowhere on it.

The arithmetic is a chain of equalities: 23.57 written must equal 23.57 queried, which must equal 23.57 plotted. The tap where the chain breaks — a string appears, the pressure value substitutes, or the point vanishes — names the stage to fix. Then let the flow run for a few publishing intervals and confirm the chart shows evenly spaced dots in ascending time; a cluster at the right edge means the points arrived as live readings, which points back to the timestamp handling in the reshape.

Which mistakes bring the empty chart back? #

Three relapses account for most empty charts after a working fix: a publisher payload change that the parser no longer matches, an unbounded query that grows until it trips a row limit, and old records stored before the fix that still hold text instead of numbers.

  • Position-based column mapping. If the columns setting maps by position, a publisher that swaps its two values exchanges temperature and pressure while both stay numeric. Map by name, and after any publisher change compare the parse tap against the sensor's own readout.
  • Header rows and new fields. A header line parsed as data writes a garbage row, and a publisher that adds a third value shifts every mapping. Both show up at the parse tap as wrong names or wrong counts.
  • Growth without a bound. A query with no time clause reads more history every day until the flow slows or the result clips; when a chart that once drew correctly goes flat, check the query row limit behind a flat historian trend before touching the flow.
  • Old records stay wrong. Correcting the flow repairs future writes only; rows stored as one text value keep that shape, so expect the chart's older stretch to stay blank or broken until those records expire under your retention setting. Before deleting or rewriting stored history on a shared historian, confirm that no other client reads those blocks — a cleanup touches everyone's trends.

Re-run the four-tap test after any change to the publisher, the parser or the database node; the test takes a minute and the chart hides nothing.

Questions asked

Why does the temperature query return nothing when the writes look successful?

Because the writer received the whole sensor line as one string and stored it as a single text value, so no numeric field named temp exists in the measurement. List the measurement's field keys to confirm. Fix the parse stage first, and remember that records stored before the fix keep the old structure; they will not repair themselves.

What should the parsed payload look like after the CSV node?

A JavaScript object with one property per sensor value, for example temp equal to 23.57 and pres equal to 1013.8, and both properties must be numbers, not quoted strings. A Debug node placed after the CSV node shows the types directly: numbers print without quotes, and strings print with them.

Can temperature and pressure share one dashboard chart?

Yes, as separate series on the chart, each fed by its own query and its own reshape. Keep one axis or scaling per unit, and label each pen with its unit from the sensor configuration. The failure mode to avoid is a mapping error that plots the pressure field on the temperature pen, which the four-tap test catches.

Does this change when the database speaks Flux instead of InfluxQL?

Yes. The InfluxQL statement is the 1.x query language; a query node set to Flux will not run it. Keep the same storage split and express the same intent in Flux: a range over the display window and a filter that keeps only the temp field. Verify which language your query node is set to before rewriting the statement.

How many points should the dashboard query return?

Only the visible window. For example, one reading every ten seconds over a one-hour chart window is 360 points, and a full day at that rate is 8,640, which is where slow flows and query row limits start. Set the query's time clause to the chart window and let historical analysis run as a separate query.

Keep reading

  • How-to

    Recursively browse PLC nodes in Node-RED for InfluxDB

    A single read of the PLC root path returns that node's value only — nested levels are never collected. Browse the tree once to every leaf, cache the paths in Node-RED global context, then poll the cached list every 10 seconds and write one payload to InfluxDB with relative paths as field names. The deciding number is cycle duration: about 200 paths at a 20 ms mean read take 4.0 s, so the 10 s timer holds only while a measured cycle stays inside the interval.

    Edge computing and IIoT

  • How-to

    Route MQTT sensor data into Grafana on an edge PC

    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.

    Edge computing and IIoT

  • Troubleshooting

    Troubleshoot missing data in a Node-RED InfluxDB Grafana stack

    Work the chain in order: acquisition into Node-RED, the InfluxDB service and its storage mount, the write settings, then the Grafana query. In a 2.x stack most empty panels trace to a wrong token, bucket, URL or a controller clock that stamps points outside the panel's time range.

    Edge computing and IIoT