node-red-contrib-uos-nats 0.1.65 → 0.1.66

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.
Files changed (2) hide show
  1. package/README.md +168 -165
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,16 +2,16 @@
2
2
 
3
3
  **Unofficial Node-RED Package for u-OS Data Hub**
4
4
 
5
- Built and maintained by [IoTUeli](https://www.linkedin.com/in/iotueli/). This is **not** an official Weidmüller product.
5
+ Built and maintained by [IoTUeli](https://iotueli.ch). This is **not** an official Weidmüller product.
6
6
  Repository: <https://github.com/uiff/nats-NodeRed-Node-uc20>
7
7
 
8
8
  ---
9
9
 
10
10
  ## What is this?
11
11
 
12
- Node-RED nodes to **read** and **write** variables from the **u-OS Data Hub** via NATS protocol.
12
+ Node-RED nodes to **read** and **write** variables from the **Weidmüller u-OS Data Hub** via NATS protocol.
13
13
 
14
- ### The Three Nodes:
14
+ ### The Three Nodes
15
15
 
16
16
  1. **u-OS Config** – Connection settings (Host, OAuth credentials, NATS connection)
17
17
  2. **DataHub - IN** – Read variables from Data Hub providers
@@ -71,14 +71,14 @@ Process & forward to other systems
71
71
  - Delayed reactions
72
72
  - Higher CPU usage
73
73
 
74
- ### Use NATS when:
74
+ ### Use NATS when
75
75
 
76
76
  ✅ You need **real-time reactions** to value changes
77
77
  ✅ You want to **create providers** (publish data to Data Hub)
78
78
  ✅ You need **event subscriptions** (get notified on changes)
79
79
  ✅ You're building **scalable industrial workflows**
80
80
 
81
- ### Use REST API when:
81
+ ### Use REST API when
82
82
 
83
83
  ⚠️ You only need **occasional manual reads**
84
84
  ⚠️ You're debugging or doing one-time queries
@@ -86,164 +86,174 @@ Process & forward to other systems
86
86
 
87
87
  ---
88
88
 
89
- ## 1. u-OS Config Node
89
+ ## Quick Start Guide
90
90
 
91
- ### Purpose
92
- Stores connection details and OAuth credentials. All DataHub nodes share this configuration.
91
+ ### Step 1: Create OAuth Client in u-OS
92
+
93
+ Before configuring Node-RED, create an OAuth client on your u-OS device:
93
94
 
94
- ### Setup Steps
95
+ 1. Open the **u-OS Web Interface** (e.g., `http://192.168.10.100`)
96
+ 2. Go to **System** → **Access Control** → **OAuth Clients**
97
+ 3. Click **"Add Client"**
98
+ 4. Enter:
99
+ - **Name:** `nodered`
100
+ - **Scopes:** Select **all** `hub.variables.*` scopes:
101
+ - `hub.variables.provide` (for creating providers)
102
+ - `hub.variables.readonly` (for reading)
103
+ - `hub.variables.readwrite` (for writing)
104
+ 5. **Save** and copy the **Client ID** and **Client Secret**
95
105
 
96
- 1. **Add a Config Node:**
97
- - Open any DataHub node (IN or OUT)
98
- - Click the pencil icon next to "Config"
99
- - Click "Add new uos-config..."
106
+ ### Step 2: Configure u-OS Config Node in Node-RED
100
107
 
101
- 2. **Fill in the Fields:**
108
+ 1. Drag any **DataHub - IN** or **DataHub - OUT** node onto the canvas
109
+ 2. Double-click it to open settings
110
+ 3. Click the **pencil icon** next to "Config"
111
+ 4. Select **"Add new uos-config..."**
112
+ 5. Fill in:
102
113
 
103
114
  | Field | Example | Description |
104
115
  |-------|---------|-------------|
105
- | **Host** | `192.168.10.100` | IP address of your u-Control device |
106
- | **Port** | `49360` | NATS port (default: 49360) |
107
- | **Client Name** | `nodered` | Unique name for this Node-RED instance |
108
- | **Client ID** | `my-oauth-client` | OAuth2 Client ID (from Control Center) |
109
- | **Client Secret** | `****************` | OAuth2 Client Secret (from Control Center) |
110
- | **Scopes** | `hub.variables.*` | Leave default or customize (see below) |
111
-
112
- 3. **Create OAuth Client in Control Center:**
113
- - Open the u-Control Web Interface
114
- - Go to **System** → **Access Control** → **OAuth Clients**
115
- - Click **"Add Client"**
116
- - **Name:** `nodered`
117
- - **Scopes:** Select all `hub.variables.*` (provide, readonly, readwrite)
118
- - **Copy the Client ID and Secret** into Node-RED
116
+ | **Host** | `192.168.10.100` | IP of your u-OS device |
117
+ | **Port** | `49360` | NATS port (default) |
118
+ | **Client Name** | `nodered` | Unique name for this instance |
119
+ | **Client ID** | `my-oauth-client` | From Step 1 |
120
+ | **Client Secret** | `****************` | From Step 1 |
119
121
 
120
- 4. **Test Connection:**
121
- - Click **"Test Connection"** button
122
- - ✅ Success: Shows "Connected" + granted scopes
123
- - ❌ Error: Check Host/Port/Credentials
122
+ 6. Click **"Test Connection"** to verify
123
+ 7. On success, click **"Add"** then **"Done"**
124
124
 
125
- ---
125
+ ### Step 3: Deploy Your First Flow
126
126
 
127
- ## 2. DataHub - IN Node (Read Variables)
127
+ Import this example flow to test both reading and writing:
128
128
 
129
- ### Purpose
130
- Subscribe to variables from a Data Hub provider and output their values as JSON messages.
129
+ ```json
130
+ [{"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"}]
131
+ ```
131
132
 
132
- ### Setup Steps
133
+ **What this flow does:**
133
134
 
134
- #### Step 1: Select Config
135
- - Choose your **u-OS Config** node
135
+ **Top Row** (Reading):
136
+ - **DataHub - IN** reads `zipcode` variable from provider `u_os_adm`
137
+ - Polls every 100ms
138
+ - Outputs to Debug node
136
139
 
137
- #### Step 2: Enter Provider ID
138
- - **What is it?** The name of the data source (e.g., `u_os_sbm`, `hub`, `custom-provider`)
139
- - **Where to find it?**
140
- - u-Control Web Interface **Data Hub** **Providers**
141
- - Or use the Python sample's `PROVIDER_ID`
140
+ **Bottom Row** (Writing):
141
+ - **Inject** node triggers data generation
142
+ - **Function** node creates random temperature data
143
+ - **DataHub - OUT** publishes to Data Hub as provider `hub`
144
+ - Creates variables: `machine.status` and `machine.details.temp`
142
145
 
143
- **Example:** `u_os_sbm`
146
+ **To customize:**
147
+ 1. Edit the **DataHub - IN** node:
148
+ - Change `Provider ID` to match your system
149
+ - Update variable mappings in the table
150
+ 2. Edit the **Function** node to generate your data structure
151
+ 3. Click **Deploy**
144
152
 
145
- #### Step 3: Add Variables (Manual Table)
146
- Since auto-discovery often fails due to permissions, you **manually map** variable names to their IDs.
153
+ ---
147
154
 
148
- **How to find Variable IDs:**
155
+ ## Finding Variable IDs
149
156
 
150
- **Option A: From Python Config**
151
- ```python
152
- # Your working Python config.py
153
- VARIABLE_DEFINITIONS = [
154
- {"id": 0, "key": "manufacturer_name", ...},
155
- {"id": 2, "key": "machine.details.temp", ...}
156
- ]
157
- ```
158
- → Use these IDs!
157
+ The **DataHub - IN** node requires variable IDs (numbers). Here's how to find them:
158
+
159
+ ### Option 1: u-OS Web Interface
160
+
161
+ 1. Open **Data Hub** → **Providers**
162
+ 2. Click on your target provider (e.g., `u_os_adm`)
163
+ 3. Click **Variables** tab
164
+ 4. Note the **ID** column (e.g., `0`, `1`, `2`)
159
165
 
160
- **Option B: From u-Control Web UI**
161
- 1. Open **Data Hub** → **Providers** → Select your provider
162
- 2. Click on **Variables**
163
- 3. Note the **ID** column (usually 0, 1, 2, ...)
166
+ ### Option 2: REST API Query
164
167
 
165
- **Option C: From REST API**
166
168
  ```bash
167
169
  curl -H "Authorization: Bearer $TOKEN" \
168
- http://192.168.10.100/datahub/v1/providers/u_os_sbm/variables
170
+ http://192.168.10.100/datahub/v1/providers/u_os_adm/variables
169
171
  ```
170
172
 
171
- **Fill the Table:**
173
+ Response shows variable definitions with IDs:
174
+ ```json
175
+ {
176
+ "variables": [
177
+ {"id": 0, "key": "manufacturer_name", ...},
178
+ {"id": 2, "key": "digital_nameplate.address_information.zipcode", ...}
179
+ ]
180
+ }
181
+ ```
182
+
183
+ ### Option 3: Check Other Apps
184
+
185
+ If you have other Data Hub clients (apps, PLCs), check their variable definitions to find the IDs.
186
+
187
+ ---
188
+
189
+ ## DataHub - IN Node (Read Variables)
190
+
191
+ ### Purpose
192
+ Subscribe to variables from a Data Hub provider and output their values as JSON messages.
193
+
194
+ ### Configuration
195
+
196
+ 1. **Config Node:** Select your u-OS connection
197
+ 2. **Provider ID:** Enter the provider name (e.g., `u_os_adm`, `hub`, `u_os_sbm`)
198
+ 3. **Variables Table:** Manually map variable names to IDs
172
199
 
173
200
  | Variable Name | ID |
174
201
  |--------------|-----|
175
202
  | `manufacturer_name` | `0` |
176
- | `machine.details.temp` | `2` |
203
+ | `zipcode` | `2` |
177
204
 
178
205
  Click **"Add Variable"** for each entry.
179
206
 
180
- #### Step 4: Choose Trigger Mode
181
-
182
- | Mode | When to Use |
183
- |------|-------------|
184
- | **Event (on change)** | Default. Efficient. Outputs only when values change. |
185
- | **Poll (interval)** | Forces periodic reads (e.g., every 1000ms). Less efficient. |
186
-
187
- #### Step 5: Deploy & Test
188
- 1. Click **Deploy**
189
- 2. Connect a **Debug** node to the output
190
- 3. Send a message to the **Input Port** (using an **Inject** node) to trigger a read
191
- 4. Check the Debug panel for output:
192
- ```json
193
- {
194
- "type": "snapshot",
195
- "variables": [
196
- {"providerId": "u_os_sbm", "id": 0, "key": "manufacturer_name", "value": "Weidmüller", ...}
197
- ]
198
- }
199
- ```
200
-
201
- ### Troubleshooting
202
-
203
- | Problem | Solution |
204
- |---------|----------|
205
- | No output | Check: (1) Config deployed? (2) Provider ID correct? (3) Variable IDs correct? (4) Inject signal sent? |
206
- | "Variable not found" | Double-check IDs in the table. Use Python config or Web UI to verify. |
207
- | Permission errors | This is expected! That's why we use the manual table. |
207
+ 4. **Trigger Mode:**
208
+ - **Event (on change):** Efficient. Outputs only when values change.
209
+ - **Poll (interval):** Forces periodic reads (e.g., every 100ms).
210
+
211
+ ### Output Format
212
+
213
+ ```json
214
+ {
215
+ "type": "snapshot",
216
+ "variables": [
217
+ {
218
+ "providerId": "u_os_adm",
219
+ "id": 2,
220
+ "key": "zipcode",
221
+ "value": "12345",
222
+ "quality": "GOOD",
223
+ "timestampNs": 1234567890000000000
224
+ }
225
+ ]
226
+ }
227
+ ```
228
+
229
+ ### Triggering Reads
230
+
231
+ Connect an **Inject** node to the input port to trigger manual reads.
208
232
 
209
233
  ---
210
234
 
211
- ## 3. DataHub - OUT Node (Write Variables)
235
+ ## DataHub - OUT Node (Write Variables)
212
236
 
213
237
  ### Purpose
214
- **Creates a real Data Hub provider** that publishes variables to the u-OS Data Hub. Other applications, devices, or even other Node-RED instances can **subscribe to your data in real-time**.
238
+ Creates a real Data Hub provider that publishes variables. Other applications can subscribe to your data in real-time.
215
239
 
216
240
  ### How It Works
217
241
 
218
242
  The OUT node:
219
- 1. **Registers as a Provider** on the Data Hub (e.g., provider ID: `nodered`)
243
+ 1. **Registers as a Provider** on the Data Hub (uses `Client Name` from Config)
220
244
  2. **Publishes variable definitions** automatically when new variables are sent
221
245
  3. **Sends value updates** via NATS when you send JSON messages
222
- 4. **Answers read requests** from other consumers (apps can query your latest values)
223
- 5. **Supports event-driven subscriptions** - other apps get updates **instantly** when values change
224
-
225
- **Important:** This provider only exists **while Node-RED is running**. When you restart Node-RED, the provider re-registers automatically.
226
-
227
- ### Real-World Use Cases
246
+ 4. **Answers read requests** from other consumers
247
+ 5. **Supports event-driven subscriptions** - other apps get updates **instantly**
228
248
 
229
- **IoT Data Collection:** Node-RED reads sensor data (Modbus, MQTT, etc.) and publishes it to the Data Hub
230
- ✅ **Edge Processing:** Process data locally in Node-RED, then share results with other apps
231
- ✅ **System Integration:** Bridge between different protocols (e.g., OPC UA → Data Hub)
232
- ✅ **Custom Dashboards:** Other apps can subscribe to Node-RED's variables for visualization
249
+ ### Configuration
233
250
 
234
- ### Setup Steps
251
+ 1. **Config Node:** Select your u-OS connection
252
+ 2. **Provider ID:** Leave **empty** to use `Client Name` (recommended)
235
253
 
236
- #### Step 1: Select Config
237
- - Choose your **u-OS Config** node
254
+ ### Send Data
238
255
 
239
- #### Step 2: Provider ID (Optional)
240
- - **Leave EMPTY** to use the `Client Name` from your Config (recommended)
241
- - Or enter a custom provider ID (e.g., `my-machine-data`)
242
-
243
- **Example:** If your Config's Client Name is `nodered`, the provider will be `nodered`
244
-
245
- #### Step 3: Send JSON Messages
246
- Send a JSON object with your data:
256
+ Send JSON to the input:
247
257
 
248
258
  ```json
249
259
  {
@@ -255,66 +265,65 @@ Send a JSON object with your data:
255
265
  }
256
266
  ```
257
267
 
258
- This creates variables:
259
- - `temperature` → ID 0
260
- - `machine.status` → ID 1
261
- - `machine.speed` → ID 2
268
+ This creates:
269
+ - `temperature` → Variable ID 0
270
+ - `machine.status` → Variable ID 1
271
+ - `machine.speed` → Variable ID 2
262
272
 
263
- **The variables are INSTANTLY available to other apps via:**
264
- - **Event subscriptions** (other apps get updates when values change)
265
- - **Read queries** (other apps can request current values)
266
- - **u-Control Web UI** (visible in Data Hub → Providers → `nodered`)
273
+ **Other apps can now:**
274
+ - Subscribe to value changes (event-driven, instant updates)
275
+ - Query current values (on-demand reads)
276
+ - View in u-OS Web UI (**Data Hub****Providers** → `nodered`)
267
277
 
268
278
  ### Event-Driven Communication
269
279
 
270
- When you send a message to the OUT node:
271
-
272
280
  ```
273
- [Function: {"temp": 22.5}] → [DataHub - OUT]
274
-
275
- ┌───────────────────────────────┐
276
- │ u-OS Data Hub (NATS) │
277
- └───────────────────────────────┘
278
- ↓ ↓ ↓
279
- [Python App] [Dashboard] [Other Node-RED]
280
- (subscribes) (subscribes) (subscribes)
281
+ [Node-RED: DataHub - OUT] → [u-OS Data Hub (NATS)]
282
+
283
+ ┌─────────────┼─────────────┐
284
+ ↓ ↓ ↓
285
+ [Other Apps] [Dashboards] [PLCs]
286
+ (subscribe) (subscribe) (subscribe)
281
287
  ```
282
288
 
283
- **All subscribers receive the update IMMEDIATELY** - no polling needed!
284
-
285
- #### Step 4: Deploy & Test
286
- 1. Connect a **Function** or **Inject** node
287
- 2. Click **Deploy**
288
- 3. Check the u-Control Web Interface → **Data Hub** → Your Provider
289
+ **All subscribers receive updates IMMEDIATELY** - no polling needed!
289
290
 
290
291
  ---
291
292
 
292
- ## Example Flow
293
+ ## Troubleshooting
293
294
 
294
- ```
295
- [Inject] → [DataHub - IN] → [Debug]
296
- (u_os_sbm)
295
+ ### No Output from IN Node
297
296
 
298
- [Inject: {"temp": 22}] → [DataHub - OUT]
299
- (nodered)
300
- ```
297
+ Config node deployed?
298
+ ✓ Provider ID correct? (check u-OS Web UI → Data Hub → Providers)
299
+ ✓ Variable IDs correct? (check u-OS Web UI → Variables)
300
+ ✓ Inject signal sent to input port?
301
301
 
302
- **Copy this flow:**
303
- ```json
304
- [{"id":"inject1","type":"inject","name":"Trigger Read"},
305
- {"id":"datahub-in","type":"datahub-input","connection":"config1","providerId":"u_os_sbm","manualVariables":"manufacturer_name:0"},
306
- {"id":"debug1","type":"debug"}]
307
- ```
302
+ ### "Variable not found" Error
303
+
304
+ - Double-check IDs in the Variables table
305
+ - Verify IDs match those in u-OS Web UI
306
+
307
+ ### Connection Test Fails
308
+
309
+ - Check Host/Port are correct and device is reachable
310
+ - Verify Client ID/Secret match exactly
311
+ - Ensure OAuth client exists in u-OS
312
+ - Verify all `hub.variables.*` scopes are granted
313
+
314
+ ### Why Manual IDs?
315
+
316
+ 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.
308
317
 
309
318
  ---
310
319
 
311
320
  ## FAQ
312
321
 
313
- ### Q: Why manual IDs? Can't it auto-discover?
314
- **A:** Auto-discovery requires `hub.variables.readonly` permission on the **provider definition** endpoint, which is often restricted. The manual table works **without** this permission because it queries specific IDs directly.
322
+ ### Q: Can I use the provider created by OUT node in the IN node?
323
+ **A:** **No, don't do this!** The OUT provider only exists while Node-RED runs. On restart, it disappears and the IN node fails. Read from **system providers** (`u_os_sbm`, `u_os_adm`) or other persistent apps instead.
315
324
 
316
325
  ### Q: Where do I get Client ID/Secret?
317
- **A:** u-Control Web Interface → **System** → **Access Control** → **OAuth Clients** → **Add Client**
326
+ **A:** u-OS Web Interface → **System** → **Access Control** → **OAuth Clients** → **Add Client**
318
327
 
319
328
  ### Q: What are the required OAuth scopes?
320
329
  **A:**
@@ -323,23 +332,17 @@ When you send a message to the OUT node:
323
332
  - **Recommended:** Select all `hub.variables.*` scopes when creating the client
324
333
 
325
334
  ### Q: Can I use this outside the local network?
326
- **A:** Yes, if your u-Control device is reachable over the network and you configure the correct Host/Port.
335
+ **A:** Yes, if your u-OS device is reachable over the network and you configure the correct Host/Port.
327
336
 
328
337
  ### Q: Event vs Poll - which is better?
329
338
  **A:** **Event** (default) is more efficient. Use **Poll** only if you need guaranteed periodic readings regardless of value changes.
330
339
 
331
340
  ---
332
341
 
333
- ## Changelog
334
-
335
- See [GitHub Releases](https://github.com/uiff/nats-NodeRed-Node-uc20/releases)
336
-
337
- ---
338
-
339
342
  ## Support
340
343
 
341
344
  **Issues, Questions, or Feature Requests:**
342
- Contact [IoTUeli](https://www.linkedin.com/in/iotueli/) or open an issue on [GitHub](https://github.com/uiff/nats-NodeRed-Node-uc20)
345
+ Contact [IoTUeli](https://iotueli.ch) or open an issue on [GitHub](https://github.com/uiff/nats-NodeRed-Node-uc20)
343
346
 
344
347
  ---
345
348
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-uos-nats",
3
- "version": "0.1.65",
3
+ "version": "0.1.66",
4
4
  "description": "Node-RED nodes for Weidmüller u-OS Data Hub. Read and write variables via NATS protocol with OAuth2 authentication. Supports event-based subscriptions and manual variable mapping.",
5
5
  "author": {
6
6
  "name": "IoTUeli",