ModPackQTModPackQT
Node-RED ExamplesResourcesSign up
HomeResourcesNode-RED ExamplesLog Modbus Data to InfluxDB
IntegrationNode-RED Modbus Example

Log Modbus Data to InfluxDB

Store Modbus register values as time-series data in InfluxDB for trending, analytics, and dashboards (Grafana, Chronograf). This example polls every minute, scales the values, and writes a measurement point.

What you need

  • Node-RED v3+
  • node-red-contrib-modbus installed
  • node-red-contrib-influxdb installed (npm install node-red-contrib-influxdb)
  • InfluxDB v1 or v2 instance

Flow Overview


Modbus Device    Node-RED                          InfluxDB
    │               │                                  │
    │◀── FC03 ──────│                                  │
    │── reg[0..3] ──▶│                                  │
    │               │── scale & map to fields ──────▶ │
    │               │   measurement: modbus_device     │
    │               │   tags: unit=1, line=line1        │
                                                   (Grafana reads ▶)

Node-RED Flow JSON

Node-RED Flow JSON
[
  {"id":"inj12","type":"inject","name":"Poll 60s","repeat":"60","once":true,"wires":[["req12"]],"x":120,"y":1200},
  {"id":"req12","type":"modbus-flex-getter","name":"Read 4 regs","dataType":"HoldingRegister","adr":0,"quantity":4,"server":"srv1","wires":[["fn12"],[]],"x":310,"y":1200},
  {"id":"fn12","type":"function","name":"Build InfluxDB point","func":"const d = msg.payload.data;
msg.payload = [{
  measurement: 'modbus_device',
  fields: {
    temperature: d[0] / 10,
    voltage:     d[1] / 100,
    current:     d[2] / 1000,
    power:       d[3]
  },
  tags: { unit: '1', line: 'line1' }
}];
return msg;","wires":[["influx12"]],"x":530,"y":1200},
  {"id":"influx12","type":"influxdb out","name":"Write to InfluxDB","influxdb":"idb12","measurement":"modbus_device","wires":[],"x":750,"y":1200},
  {"id":"idb12","type":"influxdb","hostname":"localhost","port":8086,"database":"industrial"},
  {"id":"srv1","type":"modbus-client","name":"My Slave","clienttype":"tcp","tcpHost":"192.168.1.100","tcpPort":502,"unit_id":1}
]

To import: open Node-RED → Hamburger menu → Import → paste this JSON → Deploy.

Expected Output

// InfluxDB point written every 60 seconds:
// measurement=modbus_device
// fields: temperature=24.5, voltage=230.12, current=1.234, power=285
// tags:   unit=1, line=line1

Common Gotchas

  • Scale raw register values in the function node before writing — InfluxDB stores what you send.
  • For InfluxDB v2, use the influxdb-v2 output node and a token-based connection — different from v1.
  • Tag values must be strings in InfluxDB; cast them if needed (String(unitId)).
  • Keep the poll interval above the InfluxDB write precision — 1-second precision requires 1s polling.
  • Handle Modbus errors: wire the second output of modbus-flex-getter to a catch node that avoids writing on failure.

Same in ModPackQT — in 30 seconds

ModPackQT has built-in CSV export for logged register values. For long-term storage you can also connect the ModPackQT MQTT output to an InfluxDB Telegraf bridge without writing any Node-RED flows.

Was this example helpful?

More Integration examples

All Node-RED Modbus Examples (30)

ModPackQT · Node-RED Modbus Examples · Updated 2026