Issue with Telegraf OPC UA Input Plugin (B&R PLC)

Hello everyone,

Hello everyone,

I have set up Telegraf and InfluxDB in Docker containers and a simulation of a B&R PLC running on my host machine. I am trying to collect OPC UA data using the Telegraf OPC UA plugin.

Issue:
The connection to the OPC UA server appears to be working, as I receive an error message when I restart the PLC:

telegraf  | 2025-03-13T05:29:50Z E! [inputs.opcua] Error in plugin: not connected, in state "Reconnecting"
telegraf  | 2025-03-13T05:29:50Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics

However, no data are written. After restarting the PLC, i got additional Errors from Telegraf:

telegraf  | 2025-03-13T05:44:46Z E! [inputs.opcua] status not OK for node node1 (ns=6;s=::Program:stRtcTime.millisec): The node id refers to a node that does not exist in the server address space. StatusBadNodeIDUnknown (0x80340000)

The Telegraf Config for the OPC UA node as follows:

  [[inputs.opcua.nodes]]
    name = "node1"
    namespace = "6"
    identifier_type = "s"
    identifier = "::Program:stRtcTime.millisec"

I also tried the workaround I’ve found, to wrap the identifier string with single quotes as mention by @R290 in this post, but it did not work either

    identifier = '::"Program":"stRtcTime"."millisec"'

This results in

telegraf  | 2025-03-13T05:44:50Z E! [inputs.opcua] status not OK for node node1 (ns=6;s=::"Program":"stRtcTime"."millisec"): The node id refers to a node that does not exist in the server address space. StatusBadNodeIDUnknown (0x80340000)

Next i tried to log to a datapoint with numeric identifier type:

  [[inputs.opcua.nodes]]
    name = "node2"
    namespace = "0"
    identifier_type = "i"
    identifier = "2264"

This will not log any data but also not raise any error…

following the complete opcua configuration:

[[outputs.influxdb_v2]]
  urls = ["http://influxdb:8086"]
  token = "${DOCKER_INFLUXDB_INIT_ADMIN_TOKEN}"
  organization = "${DOCKER_INFLUXDB_INIT_ORG}"
  bucket = "${DOCKER_INFLUXDB_INIT_BUCKET}"
  insecure_skip_verify = true

[outputs.influxdb_v2.tagpass]
  source = ["PlcData"]

[[inputs.opcua]]
  endpoint = "opc.tcp://host.docker.internal:4840"
  connect_timeout = "10s"
  request_timeout = "5s"
  security_policy = "None"
  security_mode = "None"
  auth_method = "UserName"
  username = "telegraf"
  password = "1234"

[[inputs.opcua.nodes]]
  name = "node1"
  namespace = "6"
  identifier_type = "s"
  identifier = '::"Program":"stRtcTime"."millisec"'

[[inputs.opcua.nodes]]
  name = "node2"
  namespace = "0"
  identifier_type = "i"
  identifier = "2264"

Any hints or suggestions are highly appreciated!

So to be clear, Telegraf works as expected for both node1 and node2 before you restart the PLC? I see you’re using tagpass on the influxdb output but you’re not setting the tag in the OPC UA input?

The system is now working as expected. The missing tagpass was indeed one issue, which somehow got lost while experimenting with different configurations.

In the end, it turned out that the OPC-UA server is responding, but not all namespaces are loaded. Since I am not an OPC-UA expert, I am unsure whether this is expected behavior. This seems to be the reason why I occasionally receive StatusBadNodeIDUnknown (0x80340000) for certain data points.

As this is just a proof of concept, it is not a major concern for now. However, for the final product, it looks like I will need an additional script to handle this situation.