node-red-contrib-uos-nats 1.0.2 → 1.0.3
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/provider.js +23 -3
- package/nodes/datahub-output.js +5 -5
- package/package.json +1 -1
package/lib/provider.js
CHANGED
|
@@ -2,8 +2,8 @@ import { connect } from 'nats';
|
|
|
2
2
|
import { requestToken } from './auth.js';
|
|
3
3
|
import { CLIENT_NAME, NATS_SERVER, PROVIDER_ID, PUBLISH_INTERVAL_MS, VARIABLE_DEFINITIONS, } from './config.js';
|
|
4
4
|
import { SimulationEngine } from './simulation.js';
|
|
5
|
-
import { buildProviderDefinitionEvent, buildReadVariablesResponse, buildVariablesChangedEvent, } from './payloads.js';
|
|
6
|
-
import { providerDefinitionChanged, readVariablesQuery, varsChangedEvent } from './subjects.js';
|
|
5
|
+
import { buildProviderDefinitionEvent, buildReadVariablesResponse, buildVariablesChangedEvent, parseRegistryStateEvent, } from './payloads.js';
|
|
6
|
+
import { providerDefinitionChanged, readVariablesQuery, varsChangedEvent, registryStateEvent } from './subjects.js';
|
|
7
7
|
async function main() {
|
|
8
8
|
console.log(`[provider] Node Provider für ${PROVIDER_ID} wird gestartet…`);
|
|
9
9
|
const token = await requestToken();
|
|
@@ -15,8 +15,28 @@ async function main() {
|
|
|
15
15
|
});
|
|
16
16
|
console.log('[provider] NATS verbunden:', nc.getServer());
|
|
17
17
|
const simulation = new SimulationEngine(VARIABLE_DEFINITIONS);
|
|
18
|
-
|
|
18
|
+
|
|
19
|
+
// Initial Publish
|
|
20
|
+
let { payload: definitionPayload, fingerprint } = buildProviderDefinitionEvent(VARIABLE_DEFINITIONS);
|
|
19
21
|
await nc.publish(providerDefinitionChanged(PROVIDER_ID), definitionPayload);
|
|
22
|
+
|
|
23
|
+
// Registry State Listener (Keep Alive)
|
|
24
|
+
nc.subscribe(registryStateEvent(), {
|
|
25
|
+
callback: async (err, msg) => {
|
|
26
|
+
if (err) return;
|
|
27
|
+
try {
|
|
28
|
+
const state = parseRegistryStateEvent(msg.data);
|
|
29
|
+
if (state === 1) { // 1 = RUNNING
|
|
30
|
+
console.log('[provider] Registry restart detected. Re-publishing definition...');
|
|
31
|
+
const { payload: newPayload } = buildProviderDefinitionEvent(VARIABLE_DEFINITIONS);
|
|
32
|
+
await nc.publish(providerDefinitionChanged(PROVIDER_ID), newPayload);
|
|
33
|
+
}
|
|
34
|
+
} catch (e) {
|
|
35
|
+
console.error('[provider] Error handling registry state:', e);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
20
40
|
const readSubject = readVariablesQuery(PROVIDER_ID);
|
|
21
41
|
const sub = nc.subscribe(readSubject, {
|
|
22
42
|
callback: async (err, msg) => {
|
package/nodes/datahub-output.js
CHANGED
|
@@ -276,17 +276,17 @@ module.exports = function (RED) {
|
|
|
276
276
|
|
|
277
277
|
this.status({ fill: 'green', shape: 'dot', text: 'ready' });
|
|
278
278
|
|
|
279
|
-
// Heartbeat
|
|
280
|
-
//
|
|
281
|
-
/*
|
|
279
|
+
// Heartbeat Restored: Provider disappears after ~20 minutes if definition is not refreshed.
|
|
280
|
+
// Set to 15 minutes (900000ms) to avoid frequent UI flickering but ensure persistence.
|
|
282
281
|
const outputHeartbeat = setInterval(() => {
|
|
283
282
|
if (nc && !nc.isClosed()) {
|
|
283
|
+
console.log('[DataHub Output] Sending Definition Heartbeat...');
|
|
284
284
|
sendDefinitionUpdate(payloads, subjects).catch(err => {
|
|
285
285
|
this.warn(`Heartbeat error: ${err.message}`);
|
|
286
286
|
});
|
|
287
287
|
}
|
|
288
|
-
},
|
|
289
|
-
|
|
288
|
+
}, 900000);
|
|
289
|
+
|
|
290
290
|
|
|
291
291
|
this.on('input', async (msg, send, done) => {
|
|
292
292
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-uos-nats",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
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",
|