node-red-contrib-uos-nats 0.2.25 → 0.2.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/payloads.js CHANGED
@@ -49,15 +49,19 @@ export function buildReadVariablesResponse(defs, states, fingerprint) {
49
49
  }
50
50
 
51
51
  // Calculate baseTimestamp from the first available state, if any
52
+ // Calculate baseTimestamp from the first available state, if any, or use now
52
53
  let baseTimestamp = null;
53
54
  const firstState = Object.values(states)[0];
54
- if (firstState) {
55
- // In a real implementation we might want the oldest or newest,
56
- // but here we just take one if available, or leave it null as per previous logic.
57
- // Actually, VariableListT constructor takes null fine.
55
+ if (firstState && firstState.timestamp) {
56
+ const totalNs = BigInt(firstState.timestamp);
57
+ const secs = totalNs / 1_000_000_000n;
58
+ const nanos = Number(totalNs % 1_000_000_000n);
59
+ baseTimestamp = new TimestampT(secs, nanos);
60
+ } else {
61
+ baseTimestamp = nowNs();
58
62
  }
59
63
 
60
- const varList = new VariableListT(fingerprint, null, variables);
64
+ const varList = new VariableListT(fingerprint, baseTimestamp, variables);
61
65
 
62
66
  const response = new ReadVariablesQueryResponseT();
63
67
  response.variables = varList;
@@ -101,7 +105,8 @@ export function encodeWriteVariablesCommand(variables) {
101
105
  // variables: [{id: number, value: any}, ...]
102
106
  // variables: [{id: number, value: any}, ...]
103
107
  // VariableListT constructor: fingerprint, baseTimestamp, items
104
- const varList = new VariableListT(BigInt(0), null, []);
108
+ // VariableListT constructor: fingerprint, baseTimestamp, items
109
+ const varList = new VariableListT(BigInt(0), nowNs(), []);
105
110
  varList.items = variables.map(v => {
106
111
  const varT = new VariableT();
107
112
  varT.id = v.id;
@@ -252,7 +257,19 @@ function buildVariableList(defs, states, fingerprint) {
252
257
  if (!state) continue;
253
258
  variables.push(encodeVariableState(def, state));
254
259
  }
255
- const list = new VariableListT(fingerprint, null, variables);
260
+ // Always provide a baseTimestamp to satisfy strict schema requirements
261
+ // Use the timestamp of the first variable or now()
262
+ let baseTimestamp = nowNs();
263
+ const firstId = Object.keys(states)[0];
264
+ if (firstId && states[firstId] && states[firstId].timestamp) {
265
+ const totalNs = BigInt(states[firstId].timestamp);
266
+ const secs = totalNs / 1_000_000_000n;
267
+ const nanos = Number(totalNs % 1_000_000_000n);
268
+ baseTimestamp = new TimestampT(secs, nanos);
269
+ }
270
+
271
+ const list = new VariableListT(fingerprint, baseTimestamp, variables);
272
+ // console.log(`[Payloads] Built VariableList with baseTimestamp: ${baseTimestamp ? 'SET' : 'NULL'}`);
256
273
  return list;
257
274
  }
258
275
  function encodeVariableState(def, state) {
@@ -56,6 +56,7 @@ module.exports = function (RED) {
56
56
  function DataHubWriteNode(config) {
57
57
  RED.nodes.createNode(this, config);
58
58
  const node = this;
59
+ // console.log('DataHub Write Node initialized');
59
60
 
60
61
  // Get config node
61
62
  const configNode = RED.nodes.getNode(config.connection);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-uos-nats",
3
- "version": "0.2.25",
3
+ "version": "0.2.29",
4
4
  "description": "Node-RED nodes for Weidmüller u-OS Data Hub. Read, write, and provide variables via NATS protocol with OAuth2 authentication. Features: Variable Key resolution, custom icons, example flows, and provider definition caching.",
5
5
  "author": {
6
6
  "name": "IoTUeli",