How-to
Recursively browse PLC nodes in Node-RED for InfluxDB
Short answer
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.
On this page
A read request against a PLC root node returns that node's value and nothing else — no nested level is collected automatically. Getting a deeply nested PLC structure into InfluxDB therefore splits into two jobs. A discovery pass browses the tree once from the configured root down to every leaf path; a polling cycle then reads the cached paths on a fixed timer and hands one payload per cycle to InfluxDB. In the reported setup — a ctrlX CORE X3 running ctrlX OS with PLC, Node-RED and InfluxDB installed — the flow finds roughly 200 leaf paths under plc/app/Application/sym, polls them every 10 seconds, and names each InfluxDB field by its path relative to that root. What decides whether the timer holds is cycle duration against interval, and the worked numbers below show how to check that on your own controller.
A read returns one node, not the tree #
The read used by this flow answers one path with one node: requested at plc/app/Application/sym, it returns that node, and a child structure beneath it never arrives in the same response. Browsing is the different operation — it lists the children of a path, and it is how the flow learns which paths exist. A structure can nest several branch levels before a value appears, so reading only the root, or browsing only its immediate children, leaves everything deeper uncollected.
The traversal walks down from the root: for each path, browse; children in the response mean a branch, so queue each child path; no children means a leaf, and a value read applies to it. Treat the two no-children outcomes differently. An empty child list on a real path is a leaf; a browse that fails — link drop, timeout, access rights — is an error, and recording an error as a leaf silently deletes whole branches from the historian. Rerun discovery whenever any branch errored.
This discover-the-tree, then-poll-the-leaves split is the pattern OPC UA clients follow as well: IEC 62541 defines the OPC UA address space and the Browse service a client uses to walk it node by node, and recursive browsing to collect every node in an OPC UA address space works the same way on that protocol.
One access rule for the whole flow: keep the Data Layer credentials read-only. A logging flow reads the controller and should have no right to write to it.
Manual paths or recursive discovery #
| Approach | Setup work | When the PLC structure changes | What gets polled |
|---|---|---|---|
| Explicit variable paths | Configure each variable by hand | Edit the path list every time | Only the configured paths |
| Recursive discovery with a cached leaf list | Configure one root and the traversal logic | Rerun discovery to refresh the cache | Every leaf found under the root |
Explicit paths suit a fixed, audited subset of variables and nothing more. Recursive discovery pays when the structure is deep, grows often, and you want every leaf under one root; the cost is that the polled set now depends on what the root contains and on when discovery last ran.
Build the flow step by step #
- Prove the base path. Browse
plc/app/Application/symonce and read one known variable beneath it. Resolve connection, authentication and path errors before building anything, because a broken base produces an empty tree rather than an obvious failure. - Traverse each branch. For every path, request its children. Children in the response mean a branch: queue each child path. No children means a leaf: record the full path. Collect leaves in a temporary list and drop duplicates.
- Keep errors out of the tree. Count browse failures as failures, never as leaves. Publish nothing until a pass completes with zero errored branches, so a wrong or partial tree never reaches polling.
- Publish the cache. Write the finished path array to Node-RED global context under one key; the polling side reads that key each cycle and nothing in it is changed by hand.
- Start the timer. Set the inject to repeat every 10 seconds, and give each cycle its own payload assembly so values from one tick cannot mix into another's message.
- Read every cached path. A failed read logs the path and error and lets the cycle continue; that field stays out of the payload instead of writing a stale value under a fresh timestamp.
- Build the field names. Strip the root
plc/app/Application/sym/by comparing it as a path boundary, and use what remains of each path as the InfluxDB field name. - Write, then check the write. Hand the payload to the installed InfluxDB integration in the message format it requires, and judge its write result separately from read completion — a successful PLC read is not evidence of a stored point.
Budget the cycle against the 10 second timer #
The timer is only valid while a complete cycle — every read plus payload assembly plus the write handoff — finishes before the next tick. For sequential reads the estimate is T_cycle ≈ N × t_read + t_write, with N the discovered leaf count and t_read the mean read time per path.
Worked example, using illustrative latencies you should replace with measured ones: the reported flow polls about 200 paths every 10 s. At a mean of 20 ms per read, 200 × 20 ms = 4,000 ms = 4.0 s; adding roughly 0.5 s for payload assembly and write handoff gives a 4.5 s cycle, and 10 s − 4.5 s = 5.5 s of margin. The cycle fills 45% of the interval, so the timer holds.
Hold the same 200 paths against a 50 ms mean read and the arithmetic turns: 200 × 50 ms = 10,000 ms = 10.0 s, equal to the interval before any write. The next tick fires into unfinished reads, outstanding requests accumulate and payload assembly mixes. That configuration has already failed; repair it by raising the interval to at least twice the measured cycle — 20 s here — or by reading paths concurrently and re-measuring.
The same inputs give a planning ceiling: at 20 ms sequential reads, 10 s ÷ 20 ms per path = 500 paths is where the interval fills exactly, so the reported 200 paths sit at 40% of it. Concurrency raises that ceiling but also raises instantaneous load on the controller; set it from measured cycle times, not by opening it until the timer appears to keep up.
The host running this stack continuously is part of the same budget: a machine-side computer running Node-RED and InfluxDB around the clock is normally a fanless industrial mini PC in the cabinet. For the storage half of the budget — retention, series cardinality, disk — sizing a self-hosted Node-RED, InfluxDB and Grafana historian works the numbers.
Field names and value types #
Field identity comes from the relative path, stripped as a boundary: a discovered leaf such as plc/app/Application/sym/Conveyor/Drive1/Current — illustrative — becomes the field Conveyor/Drive1/Current. Keeping the intermediate levels is what keeps values apart: a Temperature under two different structures stays LineA/Uut/Temperature against LineB/Uut/Temperature instead of collapsing into one field. Flattening every leaf to its final member name merges unrelated values.
Types need the same deliberate handling. Check how the installed InfluxDB integration maps each PLC data type before trusting the first days of data; a type change in the PLC application, a REAL becoming an INT for instance, can collide with the field type already stored in the measurement, and Booleans and strings behave differently from numbers in the line format. The write side itself depends on the InfluxDB release: endpoint, authentication and payload format differ between API generations, and connecting Node-RED to InfluxDB 2.6 with the v2 API documents the current one.
Keep the cache honest #
Discovery produces a snapshot, not a subscription. When the PLC application adds, renames or removes symbols, the cached list does not follow: deleted paths fail on every cycle, and new members are absent from the historian with no error at all. Rerun discovery after every application change that touches the symbol structure, and publish the refreshed list the same way as the first — completed pass only, no partial results.
Scope comes from the reported deployment, not a specification: the design behaved well on its ctrlX CORE X3 target and is not intended for very high variable counts or sub-second sampling from the Data Layer. Near either edge, measure the cycle on your own controller and treat fitness as a cycle-budget question, not a tag-count question. If values still go missing while the flow reports clean cycles, the stack-level checklist for missing data in a Node-RED, InfluxDB and Grafana stack is the next diagnostic layer.
The decisions #
Commit from three inputs you own: leaf count N, mean read time t_read, interval.
- Cycle completes with margin — the 4.5 s against 10 s case: keep the timer, and record N and t_read next to the flow so the next PLC growth is checked against the same inequality before it bites.
- Cycle reaches the interval — the 10.0 s against 10 s case: the flow has already failed; double the interval or parallelize reads, re-measure, and only then trust the data.
- Very high variable counts or sub-second rates: outside the reported scope; evaluate controller and host resources for the specific application before deploying.
- Structure that changes often: recursive discovery with reruns. A fixed, audited subset wanted: explicit paths instead.
Questions asked
Does the recursive browse run on every 10 second cycle?
No. Discovery runs once at commissioning and again after a PLC change; only the polling timer repeats, and it reads the cached path list from global context. Repeating the full browse every tick would multiply Data Layer traffic by the total node count of the tree while the structure is unchanged, which buys nothing and loads the controller.
Is roughly 200 variables a hard limit for this flow?
No, it is the reported working example on a ctrlX CORE X3, not a documented capacity. The working ceiling follows from your cycle budget: with sequential 20 ms reads, 10 seconds divided by 20 milliseconds per path gives 500 paths before the interval fills exactly. Count your leaves, measure your mean read time, and compare the product against your interval.
What happens to field names if discovery starts at a deeper root?
Field names are the discovered paths relative to whichever root you configured, so a deeper root yields shorter field names. Two overlapping roots discover the same leaves twice, and identical relative paths then collide as fields within one measurement. Use roots that do not overlap, or write each root's values into a separate measurement.
How do I verify the data landed in InfluxDB end to end?
Check two layers. First read the write result the InfluxDB integration returns for each cycle message, which catches rejected payloads. Then query one known tag back through the same instance: its most recent timestamp and value should match what the flow logged for the last completed cycle. That confirms storage and timestamping, not just a clean write response.