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

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 +93 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -36,6 +36,56 @@ Restart Node-RED. The nodes appear in the **"u-OS DataHub NATS"** category in th
36
36
 
37
37
  ---
38
38
 
39
+ ## Why NATS Instead of REST API?
40
+
41
+ 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:
42
+
43
+ ### Feature Comparison
44
+
45
+ | Feature | NATS Protocol | REST API |
46
+ |---------|---------------|----------|
47
+ | **Real-time Updates** | ✅ Event-driven (instant) | ❌ Polling required (delays) |
48
+ | **Performance** | ✅ Binary protocol, high-throughput | ❌ HTTP/JSON overhead |
49
+ | **Communication** | ✅ Bidirectional (Pub/Sub + Request/Reply) | ❌ Client-initiated only |
50
+ | **Provider Registration** | ✅ Dynamic discovery & auto-registration | ❌ Static endpoints |
51
+ | **Scalability** | ✅ Many-to-many connections | ❌ Point-to-point requests |
52
+ | **Network Efficiency** | ✅ Push notifications (no polling waste) | ❌ Repeated GET requests |
53
+
54
+ ### Event-Driven Architecture
55
+
56
+ **NATS enables true event-driven workflows:**
57
+
58
+ ```
59
+ Sensor changes value
60
+
61
+ Data Hub publishes event via NATS
62
+
63
+ Node-RED receives update INSTANTLY (0ms delay)
64
+
65
+ Process & forward to other systems
66
+ ```
67
+
68
+ **With REST API you'd need:**
69
+ - Constant polling (e.g., every 100ms)
70
+ - Increased network traffic
71
+ - Delayed reactions
72
+ - Higher CPU usage
73
+
74
+ ### Use NATS when:
75
+
76
+ ✅ You need **real-time reactions** to value changes
77
+ ✅ You want to **create providers** (publish data to Data Hub)
78
+ ✅ You need **event subscriptions** (get notified on changes)
79
+ ✅ You're building **scalable industrial workflows**
80
+
81
+ ### Use REST API when:
82
+
83
+ ⚠️ You only need **occasional manual reads**
84
+ ⚠️ You're debugging or doing one-time queries
85
+ ⚠️ NATS port (49360) is blocked in your network
86
+
87
+ ---
88
+
39
89
  ## 1. u-OS Config Node
40
90
 
41
91
  ### Purpose
@@ -161,7 +211,25 @@ Click **"Add Variable"** for each entry.
161
211
  ## 3. DataHub - OUT Node (Write Variables)
162
212
 
163
213
  ### Purpose
164
- Publish variables to the Data Hub (creates your own provider that other apps can read).
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**.
215
+
216
+ ### How It Works
217
+
218
+ The OUT node:
219
+ 1. **Registers as a Provider** on the Data Hub (e.g., provider ID: `nodered`)
220
+ 2. **Publishes variable definitions** automatically when new variables are sent
221
+ 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
228
+
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
165
233
 
166
234
  ### Setup Steps
167
235
 
@@ -172,6 +240,8 @@ Publish variables to the Data Hub (creates your own provider that other apps can
172
240
  - **Leave EMPTY** to use the `Client Name` from your Config (recommended)
173
241
  - Or enter a custom provider ID (e.g., `my-machine-data`)
174
242
 
243
+ **Example:** If your Config's Client Name is `nodered`, the provider will be `nodered`
244
+
175
245
  #### Step 3: Send JSON Messages
176
246
  Send a JSON object with your data:
177
247
 
@@ -190,6 +260,28 @@ This creates variables:
190
260
  - `machine.status` → ID 1
191
261
  - `machine.speed` → ID 2
192
262
 
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`)
267
+
268
+ ### Event-Driven Communication
269
+
270
+ When you send a message to the OUT node:
271
+
272
+ ```
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
+ ```
282
+
283
+ **All subscribers receive the update IMMEDIATELY** - no polling needed!
284
+
193
285
  #### Step 4: Deploy & Test
194
286
  1. Connect a **Function** or **Inject** node
195
287
  2. Click **Deploy**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-uos-nats",
3
- "version": "0.1.63",
3
+ "version": "0.1.65",
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",