node-red-contrib-uos-nats 0.2.54 → 0.2.56

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
@@ -288,28 +288,26 @@ function buildVariableList(defs, states, fingerprint) {
288
288
  variables.push(encodeVariableState(def, state));
289
289
  }
290
290
  // Always provide a baseTimestamp to satisfy strict schema requirements
291
- // Use current time (now) for the transmission timestamp, NOT the variable timestamp.
292
- // This ensures Heartbeat packets are fresh and not discarded by DataHub.
293
- let baseTimestamp = nowNs();
294
- /*
295
- const firstId = Object.keys(states)[0];
296
- if (firstId && states[firstId] && states[firstId].timestamp) {
297
- const totalNs = BigInt(states[firstId].timestamp);
298
- const secs = totalNs / 1_000_000_000n;
299
- const nanos = Number(totalNs % 1_000_000_000n);
300
- baseTimestamp = new TimestampT(secs, nanos);
291
+ // Use the timestamp of the first item if available, otherwise NOW.
292
+ // This allows relative timestamps in the list to be non-negative if we tracked deltas,
293
+ // but mostly ensures logical consistency (Base <= Item).
294
+ let baseTimestamp = null;
295
+ if (variables.length > 0 && variables[0].timestamp) {
296
+ baseTimestamp = variables[0].timestamp;
297
+ } else {
298
+ baseTimestamp = nowNs();
301
299
  }
302
- */
303
300
 
304
301
  const list = new VariableListT(fingerprint, baseTimestamp, variables);
305
- // console.log(`[Payloads] Built VariableList with baseTimestamp: ${baseTimestamp ? 'SET' : 'NULL'}`);
306
302
  return list;
307
303
  }
308
304
  function encodeVariableState(def, state) {
309
305
  const varT = new VariableT();
310
306
  varT.id = def.id;
311
307
  varT.quality = VariableQuality[state?.quality?.toUpperCase?.()] ?? VariableQuality[DEFAULT_QUALITY];
312
- if (state?.timestamp !== undefined) {
308
+
309
+ // Logic matches Sample: use state.timestamp or now
310
+ if (state?.timestamp) {
313
311
  const totalNs = BigInt(state.timestamp);
314
312
  const secs = totalNs / 1_000_000_000n;
315
313
  const nanos = Number(totalNs % 1_000_000_000n);
@@ -84,7 +84,7 @@ module.exports = function (RED) {
84
84
  id: nextId += 1,
85
85
  key: normalized,
86
86
  dataType,
87
- access: 'READWRITE',
87
+ access: 'READ_ONLY',
88
88
  };
89
89
  defMap.set(normalized, def);
90
90
  definitions.push(def);
@@ -175,7 +175,10 @@ module.exports = function (RED) {
175
175
  nc = await connection.acquire();
176
176
  console.log('[DataHub Output] NATS acquired.');
177
177
 
178
- await sendDefinitionUpdate(payloads, subjects);
178
+ // Only publish definition if we have one. Empty definitions might be rejected?
179
+ if (definitions.length > 0) {
180
+ await sendDefinitionUpdate(payloads, subjects);
181
+ }
179
182
 
180
183
  // Listen for Variable READ requests
181
184
  sub = nc.subscribe(subjects.readVariablesQuery(this.providerId), {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-uos-nats",
3
- "version": "0.2.54",
3
+ "version": "0.2.56",
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",