node-red-contrib-uos-nats 0.2.32 → 0.2.34

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/README.md CHANGED
@@ -1,465 +1,93 @@
1
1
  # node-red-contrib-uos-nats
2
2
 
3
- **Unofficial Node-RED Package for u-OS Data Hub**
3
+ **Unofficial Node-RED Package for Weidmüller u-OS Data Hub**
4
4
 
5
- Built and maintained by [IoTUeli](https://iotueli.ch). This is **not** an official Weidmüller product.
6
- Repository: <https://github.com/uiff/nats-NodeRed-Node-uc20>
5
+ Read, write, and provide variables via NATS protocol using **OAuth2 authentication**.
6
+ Optimized for high performance and real-time updates.
7
7
 
8
- ---
9
-
10
- ## What is this?
11
-
12
- Node-RED nodes to **read**, **write**, and **provide** variables for the **Weidmüller u-OS Data Hub** via NATS protocol.
13
-
14
- ### The Four Nodes
15
-
16
- 1. **u-OS Config** – Connection settings (Host, OAuth credentials, NATS connection)
17
- 2. **DataHub - Read** – Read variables from Data Hub providers
18
- 3. **DataHub - Provider** – Create your own provider (publish variables)
19
- 4. **DataHub - Write** – Send write commands to other providers
20
-
21
- ---
22
-
23
- ## Installation
24
-
25
- ### From npm (Recommended)
26
- ```bash
27
- cd ~/.node-red
28
- npm install node-red-contrib-uos-nats
29
- ```
30
-
31
- ### From Local Folder (Development)
32
- ```bash
33
- npm install /path/to/NATS-NodeRED
34
- ```
35
-
36
- Restart Node-RED. The nodes appear in the **"u-OS DataHub NATS"** category in the palette.
37
-
38
- ---
39
-
40
- ## What's New in v0.2.6 (Critical Fixes)
41
- - **FIXED:** `Snapshot failed: ts.value is not a function` error in Read node.
42
- - **FIXED:** Invalid timestamp encoding in Provider node (Seconds/Nanoseconds mismatch).
43
- - **FIXED:** Label and Category logic for all nodes.
44
-
45
- ## What's New in v0.2.0
46
-
47
- ### 🎯 Variable Key Support
48
- Write Node now supports **Variable Keys** (e.g., `machine.temp`) in addition to numeric IDs!
49
- - Automatic Key→ID resolution via provider definition query
50
- - Cached for performance (5 min TTL)
51
- - More user-friendly than remembering IDs
52
-
53
- ### 🎨 Custom Icons
54
- Each node now has a unique, meaningful icon:
55
- - **Read:** Database with down arrow (data out)
56
- - **Provider:** Broadcast antenna (publishing)
57
- - **Write:** Database with up arrow (commands in)
58
-
59
- ### 📦 Example Flows
60
- Ready-to-import example flows included in `examples/` directory:
61
- - `basic-read-write.json` - Getting started with Read & Write
62
- - `advanced-provider.json` - Creating your own provider
63
-
64
- **Import:** Node-RED menu (☰) → Import → select file from `examples/`
65
-
66
- ---
67
-
68
- ## Why NATS Instead of REST API?
69
-
70
- The u-OS Data Hub offers both **NATS** (this package) and **REST API** access. Here's why NATS is the better choice for Node-RED:
71
-
72
- ### Feature Comparison
73
-
74
- | Feature | NATS Protocol | REST API |
75
- |---------|---------------|----------|
76
- | **Real-time Updates** | ✅ Event-driven (instant) | ❌ Polling required (delays) |
77
- | **Performance** | ✅ Binary protocol, high-throughput | ❌ HTTP/JSON overhead |
78
- | **Communication** | ✅ Bidirectional (Pub/Sub + Request/Reply) | ❌ Client-initiated only |
79
- | **Provider Registration** | ✅ Dynamic discovery & auto-registration | ❌ Static endpoints |
80
- | **Scalability** | ✅ Many-to-many connections | ❌ Point-to-point requests |
81
- | **Network Efficiency** | ✅ Push notifications (no polling waste) | ❌ Repeated GET requests |
82
-
83
- ### Event-Driven Architecture
84
-
85
- **NATS enables true event-driven workflows:**
86
-
87
- ```
88
- Sensor changes value
89
-
90
- Data Hub publishes event via NATS
91
-
92
- Node-RED receives update INSTANTLY (0ms delay)
93
-
94
- Process & forward to other systems
95
- ```
96
-
97
- **With REST API you'd need:**
98
- - Constant polling (e.g., every 100ms)
99
- - Increased network traffic
100
- - Delayed reactions
101
- - Higher CPU usage
102
-
103
- ### Use NATS when
104
-
105
- ✅ You need **real-time reactions** to value changes
106
- ✅ You want to **create providers** (publish data to Data Hub)
107
- ✅ You need **event subscriptions** (get notified on changes)
108
- ✅ You're building **scalable industrial workflows**
109
-
110
- ### Use REST API when
111
-
112
- ⚠️ You only need **occasional manual reads**
113
- ⚠️ You're debugging or doing one-time queries
114
- ⚠️ NATS port (49360) is blocked in your network
8
+ Maintained by [IoTUeli](https://iotueli.ch). Source: [GitHub](https://github.com/uiff/nats-NodeRed-Node-uc20)
115
9
 
116
10
  ---
117
11
 
118
- ## Quick Start Guide
119
-
120
- ### Step 1: Create OAuth Client in u-OS
121
-
122
- Before configuring Node-RED, create an OAuth client on your u-OS device:
12
+ ## 📦 Nodes Overview
123
13
 
124
- 1. Open the **u-OS Web Interface** (e.g., `http://<YOUR_UOS_IP>`)
125
- 2. Go to **u-OS Control Center** → **Identity & access** → **Clients**
126
- 3. Click **"Add client"**
127
- 4. Enter:
128
- - **Name:** `nodered`
129
- - **Scopes:** Select **all** `hub.variables.*` scopes:
130
- - `hub.variables.provide` (for creating providers)
131
- - `hub.variables.readonly` (for reading)
132
- - `hub.variables.readwrite` (for writing)
133
- 5. **Save** and copy the **Client ID** and **Client Secret**
134
-
135
- ### Step 2: Configure u-OS Config Node in Node-RED
136
-
137
- 1. Drag any **DataHub - IN** or **DataHub - OUT** node onto the canvas
138
- 2. Double-click it to open settings
139
- 3. Click the **pencil icon** next to "Config"
140
- 4. Select **"Add new uos-config..."**
141
- 5. Fill in:
142
-
143
- | Field | Example | Description |
144
- |-------|---------|-------------|
145
- | **Host** | `<YOUR_UOS_IP>` | IP of your u-OS device |
146
- | **Port** | `49360` | NATS port (default) |
147
- | **Client Name** | `nodered` | Unique name for this instance |
148
- | **Client ID** | `my-oauth-client` | From Step 1 |
149
- | **Client Secret** | `****************` | From Step 1 |
150
-
151
- 6. Click **"Test Connection"** to verify
152
- 7. On success, click **"Add"** then **"Done"**
153
-
154
- ### Step 3: Deploy Your First Flow
155
-
156
- Import this example flow to test both reading and writing:
157
-
158
- ```json
159
- [{"id":"cdad2fa96dc6eeec","type":"datahub-input","z":"c221537c994b056a","name":"","connection":"a0ba0e15c8dad779","providerId":"u_os_adm","manualVariables":"digital_nameplate.address_information.zipcode:2","triggerMode":"poll","pollingInterval":"100","x":110,"y":40,"wires":[["315d179d66bf9b93"]]},{"id":"315d179d66bf9b93","type":"debug","z":"c221537c994b056a","name":"debug 7","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":740,"y":40,"wires":[]},{"id":"09f29f6bfc4e1be2","type":"inject","z":"c221537c994b056a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":140,"wires":[["43b2fcf73c370f7c"]]},{"id":"43b2fcf73c370f7c","type":"function","z":"c221537c994b056a","name":"Random Data","func":"function randomBetween(min, max) {\n return Math.random() * (max - min) + min;\n}\n\nmsg.payload = {\n machine: {\n status: \"running\",\n details: {\n temp: randomBetween(30, 80)\n }\n }\n};\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":140,"wires":[["a90304487fe19b3a"]]},{"id":"a90304487fe19b3a","type":"datahub-output","z":"c221537c994b056a","name":"","connection":"a0ba0e15c8dad779","providerId":"","x":500,"y":140,"wires":[["e53fa58e4c1987ba"]]},{"id":"e53fa58e4c1987ba","type":"debug","z":"c221537c994b056a","name":"debug 6","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":740,"y":140,"wires":[]},{"id":"a0ba0e15c8dad779","type":"uos-config","host":"127.0.0.1","port":49360,"clientName":"hub","scope":"hub.variables.provide hub.variables.readwrite hub.variables.readonly"}]
160
- ```
161
-
162
- **What this flow does:**
163
-
164
- **Top Row** (Reading):
165
- - **DataHub - IN** reads `zipcode` variable from provider `u_os_adm`
166
- - Polls every 100ms
167
- - Outputs to Debug node
168
-
169
- **Bottom Row** (Writing):
170
- - **Inject** node triggers data generation
171
- - **Function** node creates random temperature data
172
- - **DataHub - OUT** publishes to Data Hub as provider `hub`
173
- - Creates variables: `machine.status` and `machine.details.temp`
174
-
175
- **To customize:**
176
- 1. Edit the **DataHub - IN** node:
177
- - Change `Provider ID` to match your system
178
- - Update variable mappings in the table
179
- 2. Edit the **Function** node to generate your data structure
180
- 3. Click **Deploy**
14
+ | Node | Icon | Purpose |
15
+ |------|------|---------|
16
+ | **u-OS Config** | ⚙️ | Central configuration for NATS connection and OAuth credentials. |
17
+ | **DataHub - Read** | 📥 | Subscribe to variable changes from system providers (e.g. `u_os_adm`). |
18
+ | **DataHub - Write** | 📤 | Send commands to change variables in other providers. |
19
+ | **DataHub - Provider** | 📡 | Create your own provider to publish variables to the Data Hub. |
181
20
 
182
21
  ---
183
22
 
184
- ## Finding Variable IDs
185
-
186
- The **DataHub - IN** node requires variable IDs (numbers). Here's how to find them:
187
-
188
- ### Option 1: u-OS Web Interface
189
-
190
- 1. Open **Data Hub** → **Providers**
191
- 2. Click on your target provider (e.g., `u_os_adm`)
192
- 3. Click **Variables** tab
193
- 4. Note the **ID** column (e.g., `0`, `1`, `2`)
23
+ ## 🚀 Installation
194
24
 
195
- ### Option 2: REST API Query
25
+ Run the following command in your Node-RED user directory (usually `~/.node-red`):
196
26
 
197
27
  ```bash
198
- curl -H "Authorization: Bearer $TOKEN" \
199
- http://<YOUR_UOS_IP>/datahub/v1/providers/u_os_adm/variables
200
- ```
201
-
202
- Response shows variable definitions with IDs:
203
- ```json
204
- {
205
- "variables": [
206
- {"id": 0, "key": "manufacturer_name", ...},
207
- {"id": 2, "key": "digital_nameplate.address_information.zipcode", ...}
208
- ]
209
- }
210
- ```
211
-
212
- ### Option 3: Check Other Apps
213
-
214
- If you have other Data Hub clients (apps, PLCs), check their variable definitions to find the IDs.
215
-
216
- ---
217
-
218
- ## DataHub - Read Node
219
-
220
- ### Purpose
221
- Subscribe to variables from a Data Hub provider and output their values as JSON messages.
222
-
223
- ### Configuration
224
-
225
- 1. **Config Node:** Select your u-OS connection
226
- 2. **Provider ID:** Enter the provider name (e.g., `u_os_adm`, `hub`, `u_os_sbm`)
227
- 3. **Variables Table:** Manually map variable names to IDs
228
-
229
- | Variable Name | ID |
230
- |--------------|-----|
231
- | `manufacturer_name` | `0` |
232
- | `zipcode` | `2` |
233
-
234
- Click **"Add Variable"** for each entry.
235
-
236
- 4. **Trigger Mode:**
237
- - **Event (on change):** Efficient. Outputs only when values change.
238
- - **Poll (interval):** Forces periodic reads (e.g., every 100ms).
239
-
240
- ### Output Format
241
-
242
- ```json
243
- {
244
- "type": "snapshot",
245
- "variables": [
246
- {
247
- "providerId": "u_os_adm",
248
- "id": 2,
249
- "key": "zipcode",
250
- "value": "12345",
251
- "quality": "GOOD",
252
- "timestampNs": 1234567890000000000
253
- }
254
- ]
255
- }
256
- ```
257
-
258
- ### Triggering Reads
259
-
260
- Connect an **Inject** node to the input port to trigger manual reads.
261
-
262
- ---
263
-
264
- ## DataHub - Provider Node
265
-
266
- ### Purpose
267
- Creates a real Data Hub provider that publishes variables. Other applications can subscribe to your data in real-time.
268
-
269
- ### How It Works
270
-
271
- The OUT node:
272
- 1. **Registers as a Provider** on the Data Hub (uses `Client Name` from Config)
273
- 2. **Publishes variable definitions** automatically when new variables are sent
274
- 3. **Sends value updates** via NATS when you send JSON messages
275
- 4. **Answers read requests** from other consumers
276
- 5. **Supports event-driven subscriptions** - other apps get updates **instantly**
277
-
278
- ### Configuration
279
-
280
- 1. **Config Node:** Select your u-OS connection
281
- 2. **Provider ID:** Leave **empty** to use `Client Name` (recommended)
282
-
283
- ### Send Data
284
-
285
- Send JSON to the input:
286
-
287
- ```json
288
- {
289
- "temperature": 25.5,
290
- "machine": {
291
- "status": "running",
292
- "speed": 1500
293
- }
294
- }
295
- ```
296
-
297
- This creates:
298
- - `temperature` → Variable ID 0
299
- - `machine.status` → Variable ID 1
300
- - `machine.speed` → Variable ID 2
301
-
302
- **Other apps can now:**
303
- - Subscribe to value changes (event-driven, instant updates)
304
- - Query current values (on-demand reads)
305
- - View in u-OS Web UI (**Data Hub** → **Providers** → `nodered`)
306
-
307
- ### Event-Driven Communication
308
-
309
- ```
310
- [Node-RED: DataHub - OUT] → [u-OS Data Hub (NATS)]
311
-
312
- ┌─────────────┼─────────────┐
313
- ↓ ↓ ↓
314
- [Other Apps] [Dashboards] [PLCs]
315
- (subscribe) (subscribe) (subscribe)
28
+ npm install node-red-contrib-uos-nats
316
29
  ```
317
30
 
318
- **All subscribers receive updates IMMEDIATELY** - no polling needed!
31
+ Restart Node-RED. The nodes will appear in the **"Weidmüller DataHub"** category.
319
32
 
320
33
  ---
321
34
 
322
- ## DataHub - Write Node
323
-
324
- ### Purpose
325
- Send **write commands** to **external Data Hub providers** to change variable values. This is different from the Provider node - you're controlling **other** systems, not creating your own provider.
35
+ ## Quick Start
326
36
 
327
- ### Use Cases
37
+ ### 1. Create OAuth Client (in u-OS)
328
38
 
329
- **Control external devices** - Toggle flags, update setpoints
330
- **Machine control** - Start/stop operations via Data Hub
331
- **Configuration updates** - Change parameters in other apps
332
- **Integration scenarios** - Write to PLCs, other Node-RED instances, etc.
39
+ 1. Open **u-OS Web UI** (Control Center Identity & access → Clients).
40
+ 2. Click **Add client**.
41
+ 3. Name: `nodered` (example).
42
+ 4. Scopes: Select **all** `hub.variables.*` scopes.
43
+ 5. Copy **Client ID** and **Client Secret**.
333
44
 
334
- ### Configuration
45
+ ### 2. Configure Node-RED
335
46
 
336
- 1. **Config Node:** Select your u-OS connection
337
- 2. **Provider ID:** Target provider to write to (e.g., `u_os_adm`, `u_os_sbm`)
338
- 3. **Variable ID:** Numeric ID of the variable to write
47
+ 1. Drag a **DataHub - Read** node to the canvas.
48
+ 2. Click the pencil ✏️ next to **Connection**.
49
+ 3. Enter:
50
+ - **Host:** IP of your u-OS device (e.g. `192.168.10.100`)
51
+ - **Client ID / Secret:** Paste from Step 1.
52
+ 4. Click **Connect**.
339
53
 
340
- ### Finding Variable IDs
54
+ ### 3. Example Flow
341
55
 
342
- Same as Read node - check u-OS Web UI:
343
-
344
- 1. Go to **Data Hub** → **Providers** → Select target provider
345
- 2. Click **Variables** tab
346
- 3. Note the **ID** column
347
-
348
- ### Input Format
349
-
350
- Send the new value as `msg.payload`:
351
-
352
- **Toggle Boolean:**
353
- ```javascript
354
- msg.payload = false;
355
- return msg;
356
- ```
357
-
358
- **Update Number:**
359
- ```javascript
360
- msg.payload = 42.5;
361
- return msg;
362
- ```
363
-
364
- **Change String:**
365
- ```javascript
366
- msg.payload = "stopped";
367
- return msg;
368
- ```
369
-
370
- ### Output
371
-
372
- Outputs confirmation when write command is sent:
56
+ Import this flow to test reading and writing immediately:
373
57
 
374
58
  ```json
375
- {
376
- "success": true,
377
- "providerId": "u_os_adm",
378
- "variableId": 5,
379
- "value": false
380
- }
381
- ```
382
-
383
- ### Example Flow
384
-
385
- ```
386
- [Inject: false] → [DataHub - Write] → [Debug]
387
- (Provider: u_os_adm,
388
- Variable ID: 5)
59
+ [{"id":"cdad2fa96dc6eeec","type":"datahub-input","z":"c221537c994b056a","name":"Read Zipcode","connection":"a0ba0e15c8dad779","providerId":"u_os_adm","manualVariables":"digital_nameplate.address_information.zipcode:2","triggerMode":"poll","pollingInterval":"1000","x":190,"y":100,"wires":[["315d179d66bf9b93"]]},{"id":"315d179d66bf9b93","type":"debug","z":"c221537c994b056a","name":"Debug Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":440,"y":100,"wires":[]},{"id":"a0ba0e15c8dad779","type":"uos-config","host":"127.0.0.1","port":49360,"clientName":"hub"}]
389
60
  ```
390
61
 
391
- ### Important Notes
392
-
393
- ⚠️ **Requires write permissions:** OAuth client must have `hub.variables.readwrite` scope
394
- ⚠️ **Provider must accept writes:** Some providers are read-only
395
- ⚠️ **Variable must exist:** The variable ID must be valid
396
-
397
62
  ---
398
63
 
399
- ## Troubleshooting
64
+ ## 🔧 Node Usage
400
65
 
401
- ### No Output from IN Node
66
+ ### 📥 DataHub - Read
67
+ Reads values from existing providers (like `u_os_adm`).
68
+ - **Provider ID:** Name of the source provider.
69
+ - **Variables:** Enter `Key:ID` manually (e.g. `temperature:0`).
70
+ - **Trigger:** "Event" (instant update) or "Poll" (interval).
402
71
 
403
- Config node deployed?
404
- Provider ID correct? (check u-OS Web UI → Data Hub → Providers)
405
- Variable IDs correct? (check u-OS Web UI → Variables)
406
- Inject signal sent to input port?
72
+ ### 📤 DataHub - Write
73
+ Changes values in other providers.
74
+ - **Input:** Send `msg.payload` with the new value.
75
+ - **Config:** Target `Provider ID` and `Variable ID` (or Key).
407
76
 
408
- ### "Variable not found" Error
409
-
410
- - Double-check IDs in the Variables table
411
- - Verify IDs match those in u-OS Web UI
412
-
413
- ### Connection Test Fails
414
-
415
- - Check Host/Port are correct and device is reachable
416
- - Verify Client ID/Secret match exactly
417
- - Ensure OAuth client exists in u-OS
418
- - Verify all `hub.variables.*` scopes are granted
419
-
420
- ### Why Manual IDs?
421
-
422
- Auto-discovery requires special permissions on the provider definition endpoint, which are often restricted for security. The manual table works **without** this permission by querying specific IDs directly.
423
-
424
- ---
425
-
426
- ## FAQ
427
-
428
- ### Q: Can I use the provider created by Provider node in the Read node?
429
- **A:** **No, don't do this!** The Provider node's provider only exists while Node-RED runs. On restart, it disappears and the Read node fails. Read from **system providers** (`u_os_sbm`, `u_os_adm`) or other persistent apps instead.
430
-
431
- ### Q: What's the difference between Provider and Write nodes?
432
- **A:**
433
- - **DataHub - Provider:** Creates your **own** provider. Other apps read **from** you.
434
- - **DataHub - Write:** Sends commands **to other** providers. You write **to** them.
435
-
436
- ### Q: Where do I get Client ID/Secret?
437
- **A:** u-OS Web Interface → **u-OS Control Center** → **Identity & access** → **Clients** → **Add client**
438
-
439
- ### Q: What are the required OAuth scopes?
440
- **A:**
441
- - **Read Node:** `hub.variables.readonly`
442
- - **Provider Node:** `hub.variables.provide` + `hub.variables.readwrite`
443
- - **Write Node:** `hub.variables.readwrite`
444
- - **Recommended:** Select all `hub.variables.*` scopes when creating the client
445
-
446
- ### Q: Can I use this outside the local network?
447
- **A:** Yes, if your u-OS device is reachable over the network and you configure the correct Host/Port.
448
-
449
- ### Q: Event vs Poll - which is better?
450
- **A:** **Event** (default) is more efficient. Use **Poll** only if you need guaranteed periodic readings regardless of value changes.
77
+ ### 📡 DataHub - Provider
78
+ Publishes your own data to the Data Hub.
79
+ - **Input:** Send a JSON object: `{ "machine": { "status": "active" } }`.
80
+ - **Auto-Discovery:** Automatically creates variable definitions based on your JSON structure.
451
81
 
452
82
  ---
453
83
 
454
- ## Support
84
+ ## 🆘 Troubleshooting
455
85
 
456
- **Issues, Questions, or Feature Requests:**
457
- Contact [IoTUeli](https://iotueli.ch) or open an issue on [GitHub](https://github.com/uiff/nats-NodeRed-Node-uc20)
86
+ - **Connection Failed?** Check Host/IP and ensure Client ID/Secret are correct.
87
+ - **Variable not found?** IDs in Node-RED must match the IDs in the u-OS Data Hub Web UI.
88
+ - **Write not working?** Ensure your OAuth client has `hub.variables.readwrite` scope.
458
89
 
459
90
  ---
460
91
 
461
- ## License
462
-
463
- MIT License
464
-
465
- **Disclaimer:** This package is a community contribution, not an official Weidmüller product.
92
+ **License:** MIT
93
+ **Disclaimer:** Community project, not an official Weidmüller product.
@@ -56,7 +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
+ console.log('DataHub Write Node initialized');
60
60
 
61
61
  // Get config node
62
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.32",
3
+ "version": "0.2.34",
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",