IMD SolutionComputing LibraryShop main store

How-to

Export InfluxDB CSV from ctrlX CORE Device Bridge data

Edge computing and IIoT Published 7 min read By IMD Solution engineering team

Short answer

Post a bounded Flux query to the /api/v2/query endpoint with Accept: application/csv and a read token, or run an InfluxDB in node into csv and file nodes in Node-RED. Keep each request's row count small: rows equal series count times window length divided by sample interval.

On this page
  1. Why is the CSV button missing in the Data Explorer?
  2. How large can one export request be?
  3. How do I export CSV through the query API?
  4. Should I pivot before exporting?
  5. How do I automate the export with Node-RED?
  6. How do I check the exported file?
  7. Is the fault a load fault or a logic fault?
  8. Steps in order
  9. Questions asked

Data that Device Bridge writes into the InfluxDB app on a ctrlX CORE leaves the device as CSV through one mechanism: a Flux query that returns CSV. You can submit that query from the Data Explorer, from the HTTP query API on another device, or from a Node-RED flow that writes the result to a file. The format is never the hard part. The row count you ask for in one call decides whether the export finishes, because the query engine builds its tables in memory on a device whose CPU and RAM are shared with your other apps.

Why is the CSV button missing in the Data Explorer? #

The download control appears only for a submitted query whose result is currently displayed, and some InfluxDB 2.6 builds hide it when the web UI is reached over plain HTTP from a remote computer. This is a reported UI behavior, not a data problem. Submit a query over a short time range first and check that rows render in the table view.

If rows are visible but no download control appears, stop fighting the UI build and call the query API directly. The API path returns the same CSV the button would have produced, does not depend on how the device is reached, and works unchanged for scheduled exports. The same behavior shows up behind reverse proxies and SSH tunnels, where the UI URL no longer matches what the server advertises, so the API is the dependable path in any of these setups.

How large can one export request be? #

Size each request by its row count: rows equal series count times window length divided by sample interval. A Device Bridge application with 20 variables, each written once per second, produces 20 series. A one-hour window on that application asks for 20 × 3600 s ÷ 1 s = 72,000 rows in one call, which is large for a controller-class device. A five-minute window asks for 20 × 300 s ÷ 1 s = 6,000 rows, which finishes comfortably. Cut the window until each call returns a modest count, then loop over consecutive windows.

Three settings decide that product. The series count comes from the tag and field lists in the bucket, the sample interval from the Device Bridge publish configuration, and the window length from your own range values. An unbounded range, such as an open-ended start, multiplies the product by the whole retention period in a single call; never do this on a shared device. If you need days of history, loop over hourly windows and concatenate the parts.

How do I export CSV through the query API? #

Create an API token with read permission on the one bucket that holds the Device Bridge data, then note the organization name and the base URL shown in the browser address bar when the InfluxDB app's own web UI is open. A missing or mis-scoped token is the most common API failure; the error text talks about authorization even when the query itself is fine, which is why the fix is a correct token, not a different query.

Prototype the Flux text in the Data Explorer script editor over a short window and confirm the exact measurement and field names Device Bridge produced. Then post it. The request below is an example; replace the bucket, times, measurement and credentials with your own values:

curl --request POST "http://192.168.1.50:8086/api/v2/query?org=plant-line1" \
  --header "Authorization: Token your-read-token" \
  --header "Accept: application/csv" \
  --header "Content-Type: application/json" \
  --data '{"query": "from(bucket: \"device-bridge\") |> range(start: 2024-05-06T06:00:00Z, stop: 2024-05-06T06:05:00Z) |> filter(fn: (r) => r._measurement == \"vars\")", "dialect": {"annotations": [], "header": true, "delimiter": ","}}' \
  --output part_001.csv

The dialect block matters. InfluxDB prefixes each result with annotation lines such as datatype and group markers; naive importers choke on them, so set annotations to an empty list. Advance the start and stop times by the window length and repeat, writing part_002.csv and so on. Keep windows contiguous and non-overlapping: the stop bound is exclusive, so a stop of 06:05:00 and a next start of 06:05:00 leave no gap and no duplicate.

Should I pivot before exporting? #

Pivot on _time when the receiving tool wants one column per variable; skip it when the tool ingests long-format rows directly. Without a pivot, each CSV row carries one field name and one value, so 20 variables over five minutes produce 6,000 rows for 300 timestamps. With pivot, rows carry one row key _time and one column per field, so the same five minutes produce 300 rows with 20 value columns.

Add the pivot step to the Flux text before the API call:

|> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")

This costs one scan when the query is shaped correctly, and the details of keeping that scan cheap are covered in the pivot article linked above. After a pivot, empty cells are normal: Device Bridge variables written at different instants simply have no value at some shared timestamps, and the pivot leaves those cells blank rather than interpolating.

How do I automate the export with Node-RED? #

Build a flow of four nodes: an inject node that sets the window, the InfluxDB in node holding the read token in its credential field, the csv node, and the file node. The InfluxDB in node runs your Flux text against the bucket, the csv node converts the returned array of records to CSV text, and the file node writes one part file per run. This suits systematic, scheduled exports; the one-off pull stays with the API or the Data Explorer.

Setting up the InfluxDB side of such a flow, including the v2 API connection the in node uses, is the same work as any Node-RED-to-InfluxDB link and is walked through in the Node-RED article linked above. Store the token in credentials, keep each query bounded to the window you sized earlier, and trigger consecutive windows with the inject node's repeat or by advancing the window in a function node between runs.

How do I check the exported file? #

Compare each part against the expected row count: series count times window divided by interval, or timestamps times fields after a pivot. A large shortfall means logging gaps or a filter that dropped a field. Then confirm three things: the first and last _time values sit inside the requested window, consecutive parts share no timestamp, and the file loads with the expected column count. A shortfall inside the expected window points at Device Bridge variables that publish on different periods, not at a broken query.

Timestamps are stored and returned in UTC as RFC 3339 text. Convert to local time on the receiving device; shifting times inside the query invites double-shifts across exports. If a spreadsheet opens the file as one column, the locale expects semicolons, so change the delimiter in the dialect or in the import tool.

Is the fault a load fault or a logic fault? #

Halve the window and repeat the failing request. If the failure disappears, it was a load fault: timeouts, 5xx responses, a restarted InfluxDB app, or sustained CPU and memory load on the device. Shrink the window further, or add an aggregateWindow step and export downsampled data if full resolution is not needed. If a tiny window still fails, the query logic is wrong: a misspelled measurement, a filter on a tag that does not exist, the wrong organization name, or a token without read scope on that bucket. Distinguishing the two before changing anything saves hours; the same discipline applies when a write into InfluxDB from another PC times out, as covered in the write-timeout article linked above.

Steps in order #

  1. List the bucket's fields and tags to get the series count, and read the sample interval from the Device Bridge configuration.
  2. Choose a window so series count times window divided by interval stays in the low thousands of rows per call; for the 20-variable, 1-second example, use five minutes.
  3. Create a read token scoped to that bucket and note the organization name and base URL.
  4. Prototype the Flux text, including pivot if wanted, in the Data Explorer over one window.
  5. Post the query to /api/v2/query with Accept: application/csv, annotations suppressed, and write one part file per window.
  6. Loop over consecutive non-overlapping windows until the whole range is exported.
  7. Check row counts, boundary timestamps and column counts on each part, then concatenate in order.

Questions asked

Rows returned are far fewer than the row-count estimate. What changed?

The estimate assumes every field is written at every interval. A shortfall usually means Device Bridge variables publish on different periods, some fields were filtered out, or logging gaps exist while the controller was offline. Check each field's last write time in the Data Explorer and compare intervals per variable before blaming the query.

Why does the exported file open as one column in my spreadsheet?

Some locales expect semicolons as list separators. In the query request, set the dialect delimiter to a semicolon, or tell the import tool which character separates fields. In Node-RED, set the delimiter on the csv node instead of changing the query.

Where should the token live in a Node-RED flow?

Put it in the flow's credentials, not as a plain-text node property or in a message. Anyone who can read the flow JSON can read a plain-text token, and exports often run on devices reachable from more than one network. The InfluxDB in node has a credential field for the token for exactly this purpose.

Can I export from Grafana instead?

Grafana panels are built for display, and the community asks for a download button that is not there. The query API stays the supported export path: run the same Flux you use in the panel against /api/v2/query with the CSV accept header, and you get the identical data in a file.

Keep reading

  • Selection guide

    SCADAPack 47Xi RTU tags into AVEVA Insight: pick the path

    When the SCADAPack 47Xi sites already report to GeoSCADA Expert or AVEVA System Platform, forward to Insight with that platform's connector; standalone sites should run Node-RED against AVEVA's Historian Data REST API from a verified host, with a disk-backed queue sized from collection interval and worst outage — about 20 MB covers 100 tags at one sample per minute through an 8-hour outage.

    Edge computing and IIoT

  • Explainer

    Connect on-premise OPC UA and SQL servers to a cloud PI System

    Yes. Install the AVEVA adapters on-premise, on a small host next to the OPC UA and SQL servers, and point egress at PI Web API in the cloud; the PI Data Archive port is not a supported egress destination. Only the adapter-to-Web API direction needs an outbound route.

    Edge computing and IIoT

  • How-to

    Deploying Edge Data Store in Docker on a controller PC

    Run Edge Data Store as a Docker container on the controller-class edge PC and let its OPC UA adapter ingest the local server over localhost. Define egress targets, buffering and forwarding schedules in the JSON configuration, size the buffer from tag count, scan rate and outage target—50 tags at 1 event/s across an 8-hour outage is about 288 MB—and sign off only after a live pulled-cable test.

    Edge computing and IIoT

Export CSV when a Canary historian event closes a batch