UNPKG

node-red-contrib-octocore

Version:

OctoCore implementation for node-red

278 lines (243 loc) 9.6 kB
<script type="text/javascript"> RED.nodes.registerType('uns-subscribe', { category: 'OctoCore', color: '#e7e9ea', defaults: { name: { value: '', }, server: { value: '', type: 'uns-server', }, dataformat: { value: '', required: true, }, datapointid: { value: '', required: true, }, topicfield: { value: 'subject', }, }, inputs: 0, outputs: 1, icon: 'icons/icon-primary-positive.png', label: function () { return this.name || 'uns-subscribe'; }, }); </script> <script type="text/x-red" data-template-name="uns-subscribe"> <div class="form-row"> <label for="node-input-name"><i class="fa fa-stack-exchange"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name"> </div> <div class="form-row"> <label for="node-input-server"><i class="fa fa-server"></i> OctoCore Server</label> <input type="text" id="node-input-server" placeholder="localhost"> </div> <!--<div class="form-row"> <label for="node-input-channel"><i class="fa fa-stack-exchange"></i> Channel</label> <input type="text" id="node-input-channel" placeholder="Channel"> </div> --> <div class="form-row"> <label for="node-input-dataformat"><i class="fa fa-stack-exchange"></i> Dataformat</label> <select id="node-input-dataformat" style="width:70%"> <option value="uns_value">UNS Value</option> <option value="uns_command">UNS Command</option> <option value="uns_event">UNS Event</option> <option value="specific_subject">Specific Subject</option> </select> </div> <div class="form-row"> <label for="node-input-datapointid"><i class="fa fa-stack-exchange"></i>Datapoint / Subject</label> <input type="text" id="node-input-datapointid" placeholder="Datapoint / Subject"> </div> <div class="form-row"> <label for="node-input-topicfield"><i class="fa fa-tag"></i> Topic Field</label> <select id="node-input-topicfield" style="width:70%"> <option value="subject">NATS Subject</option> <option value="id">Datapoint ID</option> <option value="name">Datapoint Name</option> <option value="datatype">Data Type</option> </select> </div> </script> <script type="text/x-red" data-help-name="uns-subscribe"> <p>Subscribes to messages from the OctoCore platform using NATS.</p> <h3>Outputs</h3> <dl class="message-properties"> <dt>payload <span class="property-type">any</span></dt> <dd>The received message data. Format depends on the subscription type.</dd> <dt>topic <span class="property-type">string</span></dt> <dd>The topic field value based on configuration (NATS subject, datapoint ID, name, or data type).</dd> <dt>_unsreply <span class="property-type">string</span></dt> <dd>Reply subject (if present) for request-reply patterns.</dd> <dt>datatype <span class="property-type">number</span></dt> <dd>Data type of the UNS value (only for UNS Value format).</dd> <dt>id <span class="property-type">string</span></dt> <dd>Datapoint ID (only for UNS Value format).</dd> <dt>name <span class="property-type">string</span></dt> <dd>Datapoint name (only for UNS Value format).</dd> <dt>timestamp <span class="property-type">number</span></dt> <dd>Timestamp of the message (only for UNS Value format).</dd> <dt>id <span class="property-type">string</span></dt> <dd>Event ID (only for UNS Event format).</dd> <dt>type <span class="property-type">string</span></dt> <dd>Event type (only for UNS Event format).</dd> <dt>startTime <span class="property-type">string</span></dt> <dd>Event start time (only for UNS Event format).</dd> <dt>endTime <span class="property-type">string</span></dt> <dd>Event end time (only for UNS Event format).</dd> </dl> <h3>Data Formats</h3> <h4>UNS Value</h4> <p>Subscribes to UNS datapoint values.</p> <ul> <li><strong>Subject:</strong> <code>uns.{datapointid}</code></li> <li><strong>Payload:</strong> Only the value of the datapoint</li> <li><strong>Additional Properties:</strong> datatype, id, name, timestamp are available as msg properties</li> <li><strong>Example Input:</strong> <pre><code>{ "datatype": 1, "id": "f059f1c0-13bc-4011-a6d7-b49afaf36a2c", "name": "Processed items", "timestamp": 1755851218462, "value": 164653 }</code></pre> </li> <li><strong>Unix Timestamp Example:</strong> <pre><code>{ "datatype": 5, "id": "550e8400-e29b-41d4-a716-446655440004", "name": "Last Maintenance", "timestamp": 1704112800000, "value": "1704112800000" }</code></pre> </li> <li><strong>Example Output:</strong> <pre><code>msg.payload = 164653 msg.datatype = 1 msg.id = "f059f1c0-13bc-4011-a6d7-b49afaf36a2c" msg.name = "Processed items" msg.timestamp = 1755851218462</code></pre> </li> </ul> <h4>UNS Command</h4> <p>Subscribes to UNS commands.</p> <ul> <li><strong>Subject:</strong> <code>cmd.{datapointid}</code></li> <li><strong>Payload:</strong> Command data</li> </ul> <h4>UNS Event</h4> <p>Subscribes to UNS events published by the publish node.</p> <ul> <li><strong>Subject:</strong> <code>event.{datapointid}</code></li> <li><strong>Payload:</strong> Event payload data</li> <li><strong>Additional Properties:</strong> id, type, startTime, endTime are available as msg properties</li> <li><strong>Example Input:</strong> <pre><code>{ "id": "b3be95e3-7671-4b32-ad14-924b57d70e7c", "type": "point", "startTime": "2025-08-15T20:07:10.071Z", "endTime": "2025-08-15T20:07:10.071Z", "payload": { "temperature": 23.5, "humidity": 45 } }</code></pre> </li> <li><strong>Example Output:</strong> <pre><code>msg.payload = { "temperature": 23.5, "humidity": 45 } msg.id = "b3be95e3-7671-4b32-ad14-924b57d70e7c" msg.type = "point" msg.startTime = "2025-08-15T20:07:10.071Z" msg.endTime = "2025-08-15T20:07:10.071Z"</code></pre> </li> </ul> <h4>Specific Subject</h4> <p>Subscribes to custom NATS subjects.</p> <ul> <li><strong>Subject:</strong> Custom subject (e.g., <code>event.sensor.alarm</code>)</li> <li><strong>Payload:</strong> Raw message data</li> </ul> <h3>Event Message Examples</h3> <h4>Point Event</h4> <pre><code>{ "id": "b3be95e3-7671-4b32-ad14-924b57d70e7c", "type": "point", "startTime": "2025-08-15T20:07:10.071Z", "endTime": "2025-08-15T20:07:10.071Z", "payload": { "temperature": 23.5 } }</code></pre> <h4>Interval Start Event</h4> <pre><code>{ "id": "8e5624b2-4f43-484c-897e-e02f12769c90", "type": "interval_start", "startTime": "2025-08-15T21:04:40.058Z", "payload": { "af": "af" } }</code></pre> <h4>Interval End Event</h4> <pre><code>{ "id": "8e5624b2-4f43-484c-897e-e02f12769c90", "type": "interval_end", "endTime": "2025-08-15T21:04:45.123Z", "payload": { "result": "success" } }</code></pre> <h3>Configuration</h3> <dl class="message-properties"> <dt>Name</dt> <dd>Display name for the node.</dd> <dt>OctoCore Server</dt> <dd>OctoCore server configuration node.</dd> <dt>Data Format</dt> <dd>Format of the data to subscribe to.</dd> <dt>Datapoint / Subject</dt> <dd>Target datapoint ID or subject for subscription.</dd> <dt>Topic Field</dt> <dd>Select what value to use for msg.topic: <ul> <li><strong>NATS Subject:</strong> Use the NATS subject (e.g., "uns.sensor.temperature")</li> <li><strong>Datapoint ID:</strong> Use the datapoint ID (e.g., "f059f1c0-13bc-4011-a6d7-b49afaf36a2c")</li> <li><strong>Datapoint Name:</strong> Use the datapoint name (e.g., "Processed items")</li> <li><strong>Data Type:</strong> Use the data type as string (e.g., "1", "2", "3", "4", "5")</li> </ul> </dd> </dl> <h3>Features</h3> <ul> <li><strong>Automatic Reconnection:</strong> Handles connection drops with exponential backoff</li> <li><strong>Message Parsing:</strong> Automatically parses UNS values and events</li> <li><strong>Status Monitoring:</strong> Real-time connection status display</li> <li><strong>Error Handling:</strong> Comprehensive error handling with detailed logging</li> <li><strong>Performance Optimized:</strong> Efficient message processing for high throughput</li> </ul> <h3>Connection Status</h3> <ul> <li><strong>Connected:</strong> Shows uptime (e.g., "connected (2h 15m)")</li> <li><strong>Disconnected:</strong> Shows reconnect attempts (e.g., "disconnected (3/10)")</li> <li><strong>Connecting:</strong> Shows current attempt (e.g., "connecting (4)")</li> <li><strong>Failed:</strong> Shows when max attempts reached</li> </ul> <h3>Usage Examples</h3> <h4>Subscribe to Temperature Sensor</h4> <pre><code>// Configure node: // - Data Format: "UNS Value" // - Datapoint: "sensor.temperature" // Output will be: msg.payload = 23.5 msg.datatype = 2 msg.id = "sensor.temperature" msg.timestamp = 1703123456789</code></pre> <h4>Subscribe to Alarm Events</h4> <pre><code>// Configure node: // - Data Format: "Specific Subject" // - Subject: "event.sensor.alarm" // Output will be: msg.payload = { "id": "alarm-001", "type": "alarm", "startTime": "2025-08-15T20:07:10.071Z", "payload": { "severity": "high" } };</code></pre> </script>