IMD SolutionComputing LibraryShop main store

How-to

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

Edge computing and IIoT Published 7 min read

Short answer

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.

On this page
  1. What does a groov trend pen endpoint return?
  2. How do you copy the pen's data URL?
  3. How do you fetch and split the CSV in Node-RED?
  4. Which array positions hold the one-minute values?
  5. How do you keep NaN out of the total?
  6. What total should the pulse test produce?
  7. How much load does the pen add to the device?
  8. Questions asked

Summing one minute of a groov trend in Node-RED takes one copied URL and a short flow. Every pen on a groov trend publishes its logged samples as a CSV file, and a flow can fetch that file each minute, pick out the sample values and add them up. The pulse test below totals 6. Because the trend scanner already reads each value once per second whether or not this flow exists, pointing the pen at a tag that already sits on a trend adds no device load. What follows is the flow, the parsing arithmetic and the checks that keep one bad sample from turning a whole total into NaN.

What does a groov trend pen endpoint return? #

Every pen on a groov trend has its own URL that returns its logged samples as CSV, so a Node-RED flow, or any client that can fetch a URL and parse a file, can read any device type the trend carries and reduce the values to a total. The trend gadget in groov View shows up to 4 pens on 2 axes with live data for up to 7 days, and a pen's tag can come from any device the groov handles: Modbus, OPC UA, System and Simulation devices all work, which is what makes this route useful for tags Node-RED cannot poll directly. The endpoint only serves data — nothing in this technique writes back to the device, so treat it as monitoring and aggregation. The same batch suits a total, an average or an anomaly test; this article builds the sum, because a sum is the pattern that punishes sloppy value handling fastest.

Controlling a groov RIO's data services from Node-RED is a different job with its own mechanism, covered in starting and stopping Data Services from Node-RED, not in this endpoint.

How do you copy the pen's data URL? #

Right-click the pen's top-right corner in the trend gadget and copy the link address; it already carries the pen's identifier and the API key as a URL property, so one copy operation captures everything the fetch needs.

  1. Open the trend gadget in groov View and identify the pen holding the tag you want to total.
  2. Right-click the pen's top-right corner and copy the link; the reference flow reached the same address through Save Link as.
  3. Expect an address of the form /api/v0/data-logging/<pen-id>/scanned-data.csv?api_key=<key>: the data-logging path holds the pen's identifier, and the API key rides along as the ?api_key= URL property, which is how groov View REST requests authenticate.
  4. The key itself is listed near the bottom of the groov View API configuration page, so a copied link is a credential — keep it out of shared flow exports, screenshots and tickets.

How do you fetch and split the CSV in Node-RED? #

Trigger the fetch with an inject node repeating every 60 seconds, feed the URL to an exec node running curl -k, then split the returned text on commas and on newlines and join it back into one array.

  1. Add an inject node with its repeat set to 60 seconds; the reference flow also fires once at deploy so you get a first batch immediately.
  2. Add a function node (named set logging url in the reference flow) that returns the copied address as msg.payload.
  3. Add an exec node whose command is curl -k and which appends the incoming payload to the command, so the shell fetches the pen's CSV and the node's output is the file's text. The -k flag skips certificate verification, which is tolerable against a lab box with a self-signed certificate but not on a plant network: install the groov's certificate or its signing CA on the Node-RED host and drop the flag so no other device can answer in the endpoint's place.
  4. Add a split node that splits the text on commas, then a second split node that splits each part on newlines.
  5. Add a join node in build-array mode set to 27 parts; the assembled array arrives in msg.payload ready for the total function.

Which array positions hold the one-minute values? #

The values sit at array positions 3, 5, 7 and so on up to 25: twelve numbers, one per 5-second sample, because 60 seconds divided by the 5-second trend interval gives 12 samples.

Array position Content
0 the timestamp header field
1 the value header field
2, 4, 6 … 24 the sample timestamps
3, 5, 7 … 25 the sample values the sum uses
26 an empty part left by the trailing newline

Two header fields plus a timestamp and a value for each sample make 26 fields, and the trailing newline adds one empty part, which is why the join node waits for 27. The loop in the total function begins at 3, steps by 2 and stops at 25, so it reads each value once and never touches a timestamp or the empty part.

How do you keep NaN out of the total? #

Convert every field with Number() and add it to the running total only when Number.isFinite() accepts it, because one NaN or Infinity reaching the addition turns the whole total into NaN.

Any value read into a trend is promoted to a 64-bit floating-point number before it reaches the CSV, so an integer register or a bit pattern may not render the way it does in the device's own data view, and a field that does not parse becomes NaN under Number(). NaN is contagious in arithmetic: one bad sample silently poisons the whole batch, and the debug sidebar shows NaN where a number belongs. The reference flow guarded with a greater-than-or-equal-to-zero test — correct for an on/off pulse, wrong for any tag allowed to go negative — so define validity from the tag's engineering range and reject non-finite conversions as a separate check.

// One Minute Total: sum the value fields of one batch.
// OneMinuteTotal: number, initial value 0 (illustrative variable).
// FiveSecondValue: number, reassigned each pass (illustrative variable).
// accepted: number, initial value 0 (illustrative variable).
let OneMinuteTotal = 0;
let accepted = 0;

for (let i = 3; i <= 25; i += 2) {
    const FiveSecondValue = Number(msg.payload[i]);
    if (Number.isFinite(FiveSecondValue)) {
        OneMinuteTotal += FiveSecondValue;
        accepted += 1;
    }
    // a rejected sample is routed to the alarm path downstream, not summed
}

msg.payload = OneMinuteTotal;
msg.accepted = accepted;
return msg;

The loop counts what it accepts and passes the count along, so downstream nodes can tell a total built from a full batch from one built on a thin batch. A rejected sample belongs on the alarm or diagnostic path, never inside the sum.

What total should the pulse test produce? #

A test signal that pulses on and off every 5 seconds should total 6: the batch holds six samples of 1 and six samples of 0, and 6 × 1 + 6 × 0 = 6.

Wire the total function's output to a debug node and check three things: the payload shows the total, the accepted count matches the number of samples in the window, and the timestamps in the joined array actually span the minute you believe you summed. For the pulse, 6 is the whole proof — any other number means the parsing picked the wrong positions or a value failed conversion, so fix the flow before pointing it at process tags. When the minute totals must be stored alongside faster data, pair this flow with a historian arranged as described in logging one-second trends and one-minute reports in one historian.

How much load does the pen add to the device? #

The trend scanner reads the device once per second no matter what trend interval you configure, so a pen on a tag that no other trend uses adds one scan per second of load.

That scan rate is hard-coded; it does not follow the interval set on the pen. A trend keeps only the samples its interval needs and throws the rest away, so a long interval saves storage and display work but not device scans. Two consequences decide the design: more trends over distinct tags means more load on the devices, and a value is never scanned twice, so a pen on a tag that already appears on some trend costs the device nothing. Before building the flow, look at the trends you already run: if the tag is there, copy that pen's link and the device sees no new scan; if it is not, the new pen begins a scan of that tag every second, so prefer an already-trended tag or accept that cost deliberately.

Questions asked

Is there a JSON version of the pen endpoint?

Changing the extension in the address from csv to json may return a JSON body, but that behavior is undocumented and subject to change. In that form the values arrive as strings so the format can carry NaN and Infinity. Use the CSV form for anything you depend on, and if you evaluate the JSON form, parse and validate every value explicitly and retest after each groov update.

What changes if the pen's trend interval is not 5 seconds?

The endpoint returns one timestamp-and-value pair per logged sample, so a different interval packs a different number of pairs into the file, and the loop bounds in the total function must follow. Count the pairs the address actually returns, set the start, step and stop to match, and confirm the change against the timestamps before trusting a total.

How do you turn the total into a one-minute average?

Divide the total by the number of samples the loop actually accepted, not by 12, so rejected values do not drag the average toward zero. The function passes the accepted count alongside the total for exactly this. If the accepted count falls well below the batch size, raise a data-quality alarm instead of publishing an average built on a thin batch.

Can one flow read several pens?

Yes. Every pen has its own address, so clone the fetch, split and total chain once per pen, or keep a list of addresses in the first function node and iterate over them. Use a single inject node for all of them so the batches stay aligned in time, and keep one total variable per pen so the sums never mix.

Keep reading

  • Comparison

    Historian-like data logging on a restricted edge network

    On a restricted plant network the approved destination decides the architecture: write directly from Node-RED to the database when that connection is approved, publish MQTT and land it in InfluxDB with Telegraf when only a broker is approved, and capture to local files when nothing outbound is allowed. Whatever the path, prove store-and-forward with an outage test sized from your tag count and write period.

    Edge computing and IIoT

  • How-to

    Log production data from a panel PC to SQL Server

    Run Node-RED on the panel PC, read the production values straight from the controller, and insert one row per event into SQL Server with the mssql-plus node. Keep the panel's CSV-plus-FTP file relay only as a fallback, block duplicates with a last-record check and a unique key, and expect about 86,400 rows, roughly 8.6 MB, per day at one record per second.

    Edge computing and IIoT

  • Troubleshooting

    Fix MQTT sensor data missing in Node-RED

    A green MQTT connection in Node-RED proves only a broker session, not that the GSM module published a value or that the flow subscribes to its topic. An http in node cannot receive MQTT publications at all: use an mqtt in node. Trace RS-485 acquisition, publish result, broker identity and topic match in order, and fix the first stage with no positive result.

    Edge computing and IIoT