IMD SolutionComputing LibraryShop main store

Troubleshooting

Troubleshooting a Node-RED CSV email report on ctrlX CORE

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

Short answer

Work through three checkpoints in order: the three PLC values arrive joined in one trigger cycle, the CSV file is written with append to file before anything reads it, and Gmail accepts the app password created after 2-Step Verification. Each checkpoint names the node, setting or account step that decides it.

On this page
  1. Why does the report fail when the email node looks fine?
  2. Why does one trigger send several reports?
  3. Why do values from different cycles land in one row?
  4. Why does the CSV file keep only one row?
  5. Why does the attachment arrive empty or stale?
  6. How do I set up Gmail for the Node-RED email node?
  7. How fast does the report file grow?
  8. How do I test the chain end to end?
  9. Questions asked

A Node-RED CSV email report on ctrlX CORE rarely fails in the email node itself. Work three checkpoints in order — values collected, CSV saved, email delivered — and the fault is usually in an earlier stage: a join that mixes trigger cycles, a write file node left in overwrite, a file read that races the write, or a Gmail account that needs an app password created after 2-Step Verification rather than another password change. The two settings that decide most cases are named right here: the data writes must use the append to file option in the write file node (overwrite is reserved for the one-time header), and the report file, such as temp2.csv under the solution's activeConfiguration TEMP directory, must be read only from the write node's completion output so the attachment cannot beat the write. Each section below names the node, setting or account step that decides its checkpoint, and a growth check tells you when the report file needs a retention rule.

Why does the report fail when the email node looks fine? #

Split the flow into three checkpoints and test them in order — the three PLC values arrive joined in one trigger cycle, the CSV file holds the completed row before anything reads it, and the Gmail connection authenticates with the app password — the email node is the last thing to touch.

Work the checkpoints in sequence and stay at each one until it passes:

  • Values collected: the Boolean trigger starts exactly one cycle and the three Datalayer reads for that cycle arrive complete.
  • CSV saved: the write file node appends one complete row per accepted cycle to the report file.
  • Email delivered: the Gmail connection authenticates with the app password and the send completes.

Two faults hide behind a healthy-looking send: an email that succeeds while carrying an empty or stale file, and an authentication error while the file itself is perfect. Reinstalling node-red-node-email repairs neither, because installation changes nothing about network access, credentials or attachment content, and changing the Google account password reaches the wrong credential entirely — the flow authenticates with the app password. Read the email node's status and the runtime error instead, and let them name the failed stage.

Decision: work through the chain from values to file to send, changing one stage at a time.

Why does one trigger send several reports? #

Checking that the Boolean equals true fires on every poll while the bit stays asserted; detect the transition to true instead, so one false-to-true edge starts exactly one acquisition cycle, and a hold-true test proves no extra cycle hides behind a held bit.

A function that only compares the Boolean against true re-fires on every poll while the bit stays high; if the flow polls every 500 ms, one commanded event can queue dozens of report cycles. Keep the previous state in a context variable and compare on each message, or use a dedicated edge node — node-red-contrib-pulse-edge is one documented example, built to output a pulse when a rising or falling edge is detected, reading the rising edge as false-to-true (0 to 1) on Boolean input.

Verify with three checks: command a single false-to-true transition and confirm one cycle starts; hold the bit true and confirm no further cycle starts; return it to false before requesting the next event.

When a second edge arrives while a cycle is still writing, decide explicitly: queue it and release the queued event after the current write — the queue-then-flush pattern behind store-and-forward SQL buffering during MES outages — or reject it when only the latest state matters.

Decision: an edge detector plus an explicit queue-or-reject rule, never a bare comparison against true.

Why do values from different cycles land in one row? #

A join node groups whichever three messages arrive next, so Datalayer reads started by different trigger events can land in one row with columns swapped or cycles mixed; gate every event through one rising-edge detector and release the joined record only when all three reads of that cycle arrived.

Three Datalayer request nodes run in parallel, and Node-RED processes messages as they arrive, so after one read is delayed the next cycle's value can complete the previous row — a plausible-looking CSV that hides the swap. Give each read a distinct message topic and put a debug node after every read and after the join; a mispairing then shows up as topics that do not match the cycle instead of as numbers that merely look reasonable.

Decision: when the three values drift slowly between reads, parallel reads meet the report's purpose; when the row must describe one machine state, capture all three together in the PLC first and read them as one set, so the join has nothing to mix.

Why does the CSV file keep only one row? #

The write file node replaces the whole file in overwrite mode, so every trigger writing in overwrite erases the rows before it; the data writes must use the append to file option, with overwrite reserved for one deliberate initialization that writes the header.

The example report lives at /var/snap/rexroth-solutions/common/solutions/activeConfiguration/TEMP/temp2.csv, with the write file node set to create the directory when it is missing. Keep header generation and data collection on separate paths: the header is built once by function nodes that set the three column names, joined into the structure the CSV node expects, and written with overwrite during a deliberate initialization; the data path joins the three values in the same column order and writes with append to file, with the separator checked so each trigger produces its own line.

A redeploy that reruns the header path erases every row the report has collected, so gate the header behind a manual inject and inspect the existing file before any initialization runs. Browsing the directory from another session proves nothing about the Node-RED app's write permission; the check that matters is a written row.

Decision: overwrite exactly once per report file, append to file for everything after it.

Why does the attachment arrive empty or stale? #

A file read that starts before the write finishes attaches the previous content, so wire the read file node from the output of the write file node — the message reaches the read only once the write has completed — and never feed both stages from the same join output.

The report chain is a sequence, not parallel branches: the write file node completes, its output passes downstream, and only then does the read file node run, followed by the function that fills in the email's subject, body text and attachment — the same function can add the current date. If the read starts from the same source as the write, the read wins the race, the email succeeds, and the inbox shows a report with the numbers from the previous trigger.

A debug node after the read file node settles the question in one event: its payload must equal the row written for that same trigger, checked against the captured values.

Decision: read the file only from the write node's completion output, and prove the match on the first commanded event.

How do I set up Gmail for the Node-RED email node? #

Create an app password in the Google account after enabling 2-Step Verification under Signing in to Google, and put that password in the node-red-node-email credentials, because the node's documentation points Gmail users at an application password rather than the account password.

Install node-red-node-email from the palette, enable 2-Step Verification in the account's security settings, then open the app passwords page, create an entry named for this report, and enter the generated password in the email node's credential fields. Account policy can hide the app-password option; Google's own account guidance covers that case.

Test in the order that isolates faults: a small email without an attachment proves transport and authentication first, and only then does the full report with the file go out. A send that fails with a connection error after a network outage is a transport failure of the same class as Node-RED InfluxDB write errors after an outage — give the send path a retry, not a reinstall.

Decision: one app password, stored in the node's credentials; rotating the Google account password cannot fix a send.

One boundary note: the report mails production values through an external mail service, so count that path when you draw the OT data boundary.

How fast does the report file grow? #

Growth is linear in trigger rate and row width, and at one report a minute the example arithmetic gives a row of 14 characters plus a line ending, about 23 kB of new rows a day and roughly 8.0 MiB in a year.

Worked example, with illustrative inputs: a row such as 1234,2345,3456 measures 4 + 1 + 4 + 1 + 4 = 14 characters, and with a two-byte line ending each accepted trigger adds 16 bytes. At one trigger a minute, a day contributes 1440 × 16 = 23,040 bytes, about 22.5 KiB, and a year contributes 23,040 × 365 = 8,409,600 bytes, about 8.0 MiB. Two inputs move that result linearly: five-digit columns (a maximum value of 65535) widen the worst-case row to 17 + 2 = 19 bytes, lifting the daily figure to 1440 × 19 = 27,360 bytes, about 26.7 KiB, and a faster trigger rate scales it in the same proportion.

Storage at one row a minute is trivial, but the attachment carries the whole accumulated file on every send, so attachment size grows with retention, not with one row. Decide the restart rule from the measured rate — row width times trigger rate — archive the previous file, and read the attachment size limit from the mail provider's current documentation instead of assuming one.

Decision: at the example rate nothing needs deciding for months, so set the retention interval from your own row width and trigger rate and archive on schedule.

How do I test the chain end to end? #

Prove each stage with debug nodes before the report goes live: confirm the three Datalayer values for one commanded event, watch exactly one row appear per false-to-true edge, compare the attached row against the file, then send a small email without an attachment to separate authentication from content.

Run the checks on a test file, not on the production report:

  1. Command one event and read the three values in debug nodes after the Datalayer request nodes.
  2. Confirm exactly one row appears in the test CSV per false-to-true edge, and none while the bit is held true.
  3. Debug after the join: one message, three values, one cycle.
  4. Debug after the read file node: the payload equals the row written for that event.
  5. Send the attachment-free test email, then activate the full flow with the Enable button and confirm the report lands with the correct row attached.

Leave the edge and join debug nodes attached through the first production day; a flow that passes once at the bench can still mix cycles under real trigger timing.

Decision: enable the production schedule only after all five checks pass on the deployed target, not only in the editor.

Questions asked

What does the setup need before the flow runs?

A ctrlX CORE X3, X5 or X7, a ctrlX OS device, or ctrlX COREvirtual with an internet connection; the Node-RED app; and node-red-node-email installed through the palette. The PLC app is optional for reporting in general — this example uses it for one Boolean trigger and three integer variables. The Google account needs 2-Step Verification enabled before an app password can be created.

Why does a report fire the moment the flow deploys?

If the trigger Boolean is already true when the flow starts, an edge detector may read that first sample as a transition and send a report nobody asked for. Decide whether an asserted bit at deploy counts as an event, gate the detector until the first false-to-true transition, and test the choice on every redeploy.

How do I add a fourth column to the report?

Add a fourth function node, include its output in the same join and cycle, extend the CSV node's column list, and rewrite the header once through a deliberate initialization while the data writes keep the append to file setting. Header and data must name the columns in the same order, or every value lands under the wrong name.

Should I turn on less secure app access instead?

No. The email node's documented Gmail path is an application password created after 2-Step Verification, and it survives account policy that blocks the less-secure option. Keep the app password in the email node's credential store, and replace it through Google's app password page if a send starts failing with an authentication error.

When should I start a new report file?

Start one when the reporting period closes, when the columns change, or when the file reaches a size your mail path and storage accept — archive the old file and initialize a fresh one with the header, never append across the boundary. Size the interval from the measured growth rate, the row width times the trigger rate.

Keep reading

  • How-to

    Connect Node-RED on ctrlX CORE to a MySQL server

    Send the SQL as msg.topic to a node-red-node-mysql node: create the table once as an administrator, prove one INSERT and SELECT from Inject nodes, then route Read Datalayer values into a multi-row insert. Grant the runtime account only SELECT and INSERT on db1, match its host part to the client address the server reports, and keep a local snap's data directory on external media.

    Edge computing and IIoT

  • Troubleshooting

    Node-RED crash and memory growth: systemd restart recovery

    Set a Restart policy in the Service section of the Node-RED unit file so systemd brings the process back after a crash, and prove it with a controlled failure test. Then trend Node-RED and device memory side by side: a climb that ends in a crash after about 30 hours is flow-side growth, and no restart policy removes it.

    Edge computing and IIoT

  • How-to

    Sum one minute of groov trend pen data in Node-RED

    Each groov trend pen exposes a CSV endpoint that Node-RED can read every 60 seconds. Split the text, take the twelve 5-second values at array positions 3 to 25, convert with Number(), keep only finite results, and sum them; an on/off pulse totals 6. Reuse a tag already on a trend, because the scanner reads once per second and never scans the same value twice.

    Edge computing and IIoT

Fix Ignition Core Historian high CPU usage