IMD SolutionComputing LibraryShop main store

Troubleshooting

Why a Node-RED OPC UA server shows no data for Integer variables

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

Short answer

The Integer declaration is the fault: Integer is an abstract type in the OPC UA hierarchy, so the variable carries no encoding a client can read, while Double is concrete and works. Declare one concrete integer type such as Int16 identically in namespace.addVariable() and the Variant, store a context number that fits its range, then verify the reported type, a Good status, a changed read and a write that returns Good.

On this page
  1. The three lines that define the fault
  2. Integer is abstract, Double is concrete
  3. Pick the concrete type from the value's range
  4. Change both declarations to the same concrete type
  5. Verify the read and the write, not just the browse
  6. Strings follow the same consistency rule
  7. The decision
  8. Questions asked

Your Double variable reads back 0.0 through the OPC UA client, and the same flow stops returning data as soon as the variable is declared Integer. The type declaration is the fault. In the OPC UA type hierarchy, Integer is an abstract type: it has no wire encoding, so a client read has nothing to decode. Double is a concrete type one branch over, with a defined encoding, which is why the original flow worked. The fix is to declare one concrete integer type - Int16, Int32, UInt16 and their siblings - identically in namespace.addVariable() and in the Variant your getter returns, and to store a flow-context number that fits that type's range.

The three lines that define the fault #

The failing flow is the working Double flow with exactly three substitutions:

  • "dataType": "Double" became "dataType": "Integer" in namespace.addVariable()
  • DataType.Double became DataType.Integer in the getter's Variant
  • parseFloat(variant.value) became parseInt(variant.value) in the setter

Everything else is untouched: the nodeId ns=1;s=wc01_raw_mat, the browseName raw_mat, the organizedBy folder, the getter's context read and the setter's opcua.StatusCodes.Good return. That narrows the boundary before you test anything. The working Double read already proves the endpoint, the session and the transport, so do not spend time on security policy or connection settings. And parseInt does the same storage job parseFloat did, so the two type strings are the only suspects.

Declaration line Working flow Failing flow
addVariable dataType "Double" "Integer"
Variant dataType DataType.Double DataType.Integer
Setter conversion parseFloat(variant.value) parseInt(variant.value)
Client result reads 0.0 no value displayed

Integer is abstract, Double is concrete #

The OPC UA specification's DataType hierarchy puts Integer and UInteger under Number as abstract groupings. The usable leaves are concrete: SByte, Int16, Int32 and Int64 on the signed Integer branch, Byte, UInt16, UInt32 and UInt64 on the unsigned UInteger branch, and Float and Double as concrete leaves under Number directly. Abstract types define shared semantics, not an encoding, and a variable node must carry a concrete type for its value to be encodable. Declared Integer, the variable has no encoding a client can decode, so the read returns without a value. Declared Double, it has one, which is why the same structure read 0.0 before the edit. Whether or not your package's enum exposes an Integer member, the type itself cannot back a readable variable, so replace it rather than debug around it.

Pick the concrete type from the value's range #

Concrete type Range
SByte -128 to 127
Int16 -32,768 to 32,767
UInt16 0 to 65,535
Int32 -2,147,483,648 to 2,147,483,647
UInt32 0 to 4,294,967,295

Int64 and UInt64 cover values beyond 32-bit. Pick the smallest type whose range covers the lowest and highest value the context can ever hold, including fault and reset excursions. Use the signed branch if the value can go negative even briefly; use the UInt branch only for values that are never negative.

Worked example: suppose WC01_raw_mat holds a bin quantity that sits at -1 when the bin is empty and otherwise counts stock between 0 and 18,000. The negative idle marker rules out the unsigned branch. Check Int16: 18,000 is below 32,767 and -1 is above -32,768, leaving 14,767 counts of headroom at the top, so Int16 is the type. If the line later stocks 40,000-piece bins, 40,000 exceeds 32,767 and Int16 overflows; move up to Int32, whose range covers that with room to spare.

Change both declarations to the same concrete type #

Keep the structure of the working Double declaration and change the three lines. With Int16 as the worked choice:

const WC01_raw_mat = namespace.addVariable({
  "organizedBy": wc01,
  "browseName": "raw_mat",
  "nodeId": "ns=1;s=wc01_raw_mat",
  "dataType": "Int16",
  "value": {
    "get": function () {
      return new Variant({
        "dataType": DataType.Int16,
        "value": flexServerInternals.sandboxFlowContext.get("WC01_raw_mat")
      });
    },
    "set": function (variant) {
      flexServerInternals.sandboxFlowContext.set(
        "WC01_raw_mat", parseInt(variant.value)
      );
      return opcua.StatusCodes.Good;
    }
  }
});

Three checks as you deploy it:

  • The type string in addVariable and the enum member in the Variant must name the same concrete type: "Int16" with DataType.Int16, never one concrete and one abstract.
  • The context value must be a JavaScript number inside the chosen range. Read flexServerInternals.sandboxFlowContext.get("WC01_raw_mat") once through a debug node: a missing entry or a numeric string such as "12480" reproduces the same no-value symptom without any type fault.
  • parseInt(variant.value) stays as the setter conversion; it stores an integer and returns opcua.StatusCodes.Good.

Make the type change while no client is mid-write, and reconnect the client afterwards: a session that read the old type keeps its view of the variable until it reconnects.

Verify the read and the write, not just the browse #

  1. Redeploy the flow and refresh or reconnect the client session.
  2. Read the node by its nodeId, the way Find OPC UA variables in Node-RED: browse, not wildcard describes, and confirm the client reports the concrete type you declared with a Good status.
  3. Change the context value in the flow - set WC01_raw_mat to 12,480, for example - and read again; the displayed value must follow, because the getter runs when the client reads, the behavior explained in Why a Node-RED OPC UA server updates values only when a client reads.
  4. Write a value back from the client, confirm the setter stores it through parseInt and returns opcua.StatusCodes.Good, then read it back.
  5. If the node browses but still carries no value, capture the client's exact status code and the server log before changing anything else; that separates a Variant construction fault from a context-value fault.

A Node-RED restart rebuilds the server and its variables from the flow; if values vanish after a restart instead of after this edit, work through Node-RED OPC UA server persistence after a restart instead.

Strings follow the same consistency rule #

String is a concrete built-in type with its own encoding, so a string variable should read the way the Double did. If your string variable shows nothing, apply the same line-by-line check: the addVariable call and the Variant must both declare the string type, and the getter must return a JavaScript string, not a number or an object. The integer fault is explained by the abstract type; a string fault is not, so do not assume one cause covers both. Align each declaration against the working Double flow and capture the client's status and the server log for whichever variable still fails.

The decision #

Keep the structure, keep parseInt, and replace the abstract declaration with one concrete pair:

  • Value can go negative and stays within -32,768 to 32,767: declare "Int16" with DataType.Int16.
  • Never negative and within 0 to 65,535: declare "UInt16" with DataType.UInt16.
  • Beyond 16-bit in either direction: declare the matching Int32 or UInt32 pair.
  • Small signed value within -128 to 127: SByte is the smallest signed choice.

Declare the same type string in both places, store a context number inside that range, reconnect the client, and confirm the reported type, a Good status, a changed read and a Good write before you call the variable fixed.

Questions asked

Why does the Double variable work while the Integer variable shows no data?

Double is a concrete OPC UA type with a defined wire encoding, so the client reads 0.0 from the unchanged flow. Integer is an abstract type in the same hierarchy: it groups SByte, Int16, Int32 and Int64 but has no encoding of its own, so a read of a variable declared Integer has nothing to display.

Which concrete type fits a count that can reach 40,000?

Int16 stops at 32,767, so 40,000 does not fit. If the count is never negative, UInt16 covers 0 to 65,535 and is the smallest safe choice. If it can go negative, declare Int32, which covers -2,147,483,648 to 2,147,483,647. Use the same type string in addVariable and the Variant.

Is parseInt the wrong conversion for the setter?

No. parseInt converts the value the client writes into a JavaScript number for the flow context, the same job parseFloat did in the working Double flow. The read side fails because the declared type has no encoding, not because of the setter. Keep parseInt and store a number inside the chosen type's range.

How do I prove the fix before trusting the variable?

Reconnect the client, read the node and confirm it reports the concrete type with a Good status. Change the flow-context value and confirm the next read follows it. Write a value back, confirm the setter stores it and returns Good. A node that merely browses is not proof the value path works.

Keep reading

  • Selection guide

    Node-RED OPC UA server node selection for edge gateways

    Install node-red-contrib-opcua as the pilot OPC UA server package on the first edge gateway, through the Node-RED editor's Manage palette, and keep node-red-contrib-opcua-server as the evaluated fallback. A fleet rollout past a thousand gateways is justified only when the pilot passes the qualification table: server function, real-client interoperability, NodeId stability across restarts, quality behavior, security policy and install reproducibility, all on a recorded software stack.

    Edge computing and IIoT

  • Comparison

    How Node-RED reads PLC data: OPC UA, MQTT or Modbus

    Pick the protocol by what the controller already serves, in this order: OPC UA if the PLC runtime exposes an OPC UA server, MQTT if the application can publish through an MQTT client library, Modbus TCP when only a register map exists. Node-RED has a client for all three; the deciding side is the PLC.

    Edge computing and IIoT

  • Troubleshooting

    Why an OPC UA client rejects the server certificate on clock mismatch

    When one OPC UA client connects and the edge PC's client fails while collecting the server certificate, compare the server clock and the client PC clock first: a difference of a few minutes makes certificate validity checks fail. Fix the client's time, restart it, then compare the endpoint text character-for-character with the working client.

    Edge computing and IIoT

Why historized variable tags store no real values