Skip to main content

Status and source time of a value

An OPC UA value has three parts: the value, a status code and a source timestamp. A client uses the status to know if it can trust the value. A client uses the source timestamp to know when the device measured the value.

When a Node-RED flow writes a value with ua-write, the flow can also give the status and the source timestamp. If the flow does not give them, the value is Good and its time is the time of the write. Then a value from a device that the flow cannot reach still reads Good. To prevent this, give the status.

How a message flows through ua-write​

msg ──► ua-write ──► Edge Link ──► OPC UA variable: value, StatusCode, SourceTimestamp
│
└──► msg out: msg.statusCode = the result of the write

ua-write reads these fields of the message:

FieldContains
msg.payloadThe value, a batch of values, or a nested object.
msg.topicThe path, when the node has no path.
msg.uaStatusCodeThe status of the value.
msg.uaSourceTimestampThe time the device measured the value.

ua-write does not read msg.statusCode and msg.sourceTimestamp. Other nodes already set these fields, in other forms: the http request node puts the HTTP status (200) in msg.statusCode, and the ua nodes put their result there. After the write, msg.statusCode contains the result of the write.

The forms of the status and the time​

msg.uaStatusCode can be:

  • a status name: "Good", "UncertainLastUsableValue", "BadNoCommunication";
  • a numeric status code: 0x80310000;
  • a StatusCode object of node-opcua, also after a JSON round trip ({ "value": 2150694912 });
  • an OPC UA JSON status: { "Code": 2150694912 } or { "Symbol": "BadNoCommunication" }.

msg.uaSourceTimestamp can be:

  • a Date, also a Date made in a function node;
  • an ISO-8601 text with a time zone: "2026-03-04T05:06:07Z", "2026-03-04T06:06:07+01:00";
  • a number of milliseconds since 1970.

How to give the status and the time​

Only the value​

msg.payload = 12.5;
return msg;

The client reads the value 12.5, the status Good and the time of the write.

The value and a status​

msg.payload = lastWeight;
msg.uaStatusCode = "BadNoCommunication";
return msg;

The client reads lastWeight with the status BadNoCommunication, at the time of the write. For a last usable value, use an Uncertain status, for example "UncertainLastUsableValue".

The value, a status and the time of the device​

msg.payload = reading.value;
msg.uaStatusCode = "Good";
msg.uaSourceTimestamp = reading.time;
return msg;

The client reads reading.value with the status Good and the time reading.time.

A batch of values​

When the node has no path, msg.payload can be a list of writes. Each item can have its own uaStatusCode and uaSourceTimestamp. The fields of an item replace the fields of the message.

msg.uaStatusCode = "UncertainLastUsableValue";
msg.payload = [
{ path: "/Balance/Weight", value: 1 },
{ path: "/Balance/Tare", value: 2, uaStatusCode: "Good", uaSourceTimestamp: deviceTime }
];
return msg;

/Balance/Weight gets UncertainLastUsableValue. /Balance/Tare gets Good and deviceTime.

A nested object under an object node​

When the path of the node is an object, msg.payload can be a nested object. Each value of the object gets the status and the time of the message. The values are written together, so the clients see them change at the same time.

// the path of the node is /Balance
msg.payload = { Weight: 1, Tare: 2 };
msg.uaStatusCode = "BadNoCommunication";
msg.uaSourceTimestamp = new Date();
return msg;

A full OPC UA JSON value​

msg.payload can be an OPC UA JSON DataValue. Its own StatusCode and SourceTimestamp replace the fields of the message. A field with the value undefined does not replace them.

msg.payload = {
UaType: 11,
Value: 7,
StatusCode: { Code: 2150694912 },
SourceTimestamp: "2026-03-04T05:06:07Z"
};
return msg;

Which status and time win​

From the most specific to the default:

  1. the StatusCode and SourceTimestamp of an OPC UA JSON payload;
  2. the uaStatusCode and uaSourceTimestamp of a batch item;
  3. msg.uaStatusCode and msg.uaSourceTimestamp;
  4. the default: Good and the time of the write.

What ua-write refuses​

ua-write checks the status and the time before it writes. In a batch, it checks all the items before it writes the first one.

The message containsResult
msg.uaStatusCode = "Bda": not a status nameua-write refuses the message and writes nothing.
msg.uaSourceTimestamp = "yesterday": not a dateua-write refuses the message and writes nothing.
A time in seconds, such as 1772600767ua-write refuses the message. Give milliseconds.
A text without a time zone, such as "2026-03-04 05:06"ua-write refuses the message. Add Z or an offset.
A time before the year 1601 or after the year 9999ua-write refuses the message.
msg.uaStatusCode = "BadNoComunication": a correct form, but not a known statusThe gateway refuses this value only, with BadInvalidArgument.
msg.statusCode = 200, from an http request nodeua-write ignores it. The value is Good.
msg.sourceTimestamp, from another nodeua-write ignores it. The time is the time of the write.
tip

The error of a refused message names the field that is wrong. A catch node receives the first error. When the same error occurs again, ua-write only counts it in its status, so the log does not fill up. A good write ends the count.