UNPKG

@ifp-software/node-red-contrib-oee-ai-connector

Version:

Easily connect your production machines to oee.ai – The Industry 4.0 solution for OEE optimization.

249 lines (235 loc) 9.09 kB
<!-- Node configuration --> <script type="text/javascript"> // Using an extra scope here to avoid collision with names declared inside other // nodes' directly injected `<script>` elements. { const servers = ["preview", "production"]; const protocols = [ "mqtt-1883", "mqtts-8883", "ws-80", "ws-8083", "wss-443", "wss-8084", "tcp", // migrated "wss", // migrated ]; let nodeConfig = { category: "network", color: "#f3b567", defaults: { name: { value: "", }, server: { value: "preview", required: true, validate: (val) => servers.includes(val), }, protocol: { value: "wss-443", required: true, validate: (val) => !val || protocols.includes(val), // !val is for migration }, }, credentials: { id: { type: "text", required: true }, token: { type: "password", required: true }, proxy: { type: "text", required: true }, // URL proxyUsername: { type: "text", required: false }, proxyPassword: { type: "password", required: false }, }, inputs: 1, outputs: 0, icon: "connector.png", paletteLabel: "oee.ai Connector", label: function () { return this.name || "oee.ai Connector"; }, // Don't save the proxy credentials if the proxy is not used oneditsave: function () { if (!$("#node-input-proxyEnabled").is(":checked")) { $("#node-input-proxy").val(""); $("#node-input-proxyUsername").val(""); $("#node-input-proxyPassword").val(""); } }, }; // Invoked when the edit dialog is built function onEditPrepare(node) { // Migrations: // // `protocol` was previously: // - `undefined` (until 2.3.0) // - "wss" or "tcp" (until 2.9.0) // // Please make sure to keep this migration code equivalent to the one in the // `.js` file of the node if you change it. if (node.protocol === undefined || node.protocol === "tcp") { if (node.server === "preview") { $("#node-input-protocol").val("mqtt-1883"); } else if (node.server === "production") { $("#node-input-protocol").val("mqtts-8883"); } } else if (node.protocol === "wss") { $("#node-input-protocol").val("wss-8084"); } // Proxy fields, protocol options and their interdependencies function updateProxyOptions() { const tcpOptions = $("#node-input-protocol option[value^='mqtt']"); if ($("#node-input-proxyEnabled").is(":checked")) { $("#proxy-fields").show(); tcpOptions.attr("disabled", "disabled"); if (tcpOptions.is(":selected")) { $("#node-input-protocol").val("wss-443"); } } else { $("#proxy-fields").hide(); tcpOptions.removeAttr("disabled"); } RED.tray.resize(); } if (node.credentials.proxy) { $("#node-input-proxyEnabled").prop("checked", true); } else { $("#node-input-proxyEnabled").prop("checked", false); } updateProxyOptions(); $("#node-input-proxyEnabled").on("click", updateProxyOptions); } // Check if Node-RED is running on ctrlX $.get("/systeminfo/api/v1.0/typeplate", function (response) { if (typeof response != "object") { // The response type is not a JSON object, so Node-RED is not running on ctrlX. nodeConfig.oneditprepare = function () { $("#ctrlx-config").remove(); onEditPrepare(this); }; } }) .fail(function () { // The request failed, so Node-RED is not running on ctrlX. nodeConfig.oneditprepare = function () { $("#ctrlx-config").remove(); onEditPrepare(this); }; }) .always(function () { RED.nodes.registerType("oee-ai-connector", nodeConfig); }); } </script> <!-- Edit template --> <script type="text/html" data-template-name="oee-ai-connector"> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name" /> </div> <hr /> <h3>oee.ai Sensor</h3> <div class="form-row"> <label for="node-input-id"><i class="fa fa-id-badge"></i> ID</label> <input type="text" id="node-input-id" /> </div> <div class="form-row"> <label for="node-input-token"><i class="fa fa-key"></i> Token</label> <input type="password" id="node-input-token" /> </div> <div class="form-row"> <label for="node-input-server"><i class="fa fa-server"></i> Server</label> <select id="node-input-server"> <option value="preview">Preview (Testing)</option> <option value="production">Production</option> </select> </div> <div class="form-row"> <label for="node-input-protocol"><i class="fa fa-exchange"></i> Port</label> <select id="node-input-protocol"> <option value="ws-80">80 &ndash; WebSocket</option> <option value="wss-443">443 &ndash; WebSocket Secure</option> <option value="mqtt-1883">1883 &ndash; TCP</option> <option value="ws-8083">8083 &ndash; WebSocket</option> <option value="wss-8084">8084 &ndash; WebSocket Secure</option> <option value="mqtts-8883">8883 &ndash; TCP + SSL</option> </select> </div> <h3>Proxy</h3> <div class="form-row"> <input type="checkbox" id="node-input-proxyEnabled" style="display: inline-block; width: auto; vertical-align: top;" /> <label for="node-input-proxyEnabled" style="width: auto;">Enabled</label> </div> <div id="proxy-fields" class="hide"> <div class="form-row"> <label for="node-input-proxy"><i class="fa fa-sitemap"></i> URL</label> <input type="text" id="node-input-proxy" /> </div> <div class="form-row"> <label for="node-input-proxyUsername"><i class="fa fa-user"></i> Username</label> <input type="text" id="node-input-proxyUsername" /> </div> <div class="form-row"> <label for="node-input-proxyPassword"><i class="fa fa-key"></i> Password</label> <input type="password" id="node-input-proxyPassword" /> </div> <p>Note: Connecting through a proxy is only supported for WebSocket connections.</p> </div> <div id="ctrlx-config"> <hr /> <h3>ctrlX license required if running on ctrlX CORE.</h3> </div> </script> <!-- Help text --> <script type="text/html" data-help-name="oee-ai-connector"> <p>Send measurements to the oee.ai MQTT broker.</p> <h3>Inputs</h3> <dl class="message-properties"> <dt class="optional">count <span class="property-type">number</span></dt> <dd> The number of produced units for the current timeframe to be sent to oee.ai. Optional; defaults to <code>0</code>. </dd> <dt class="optional">to <span class="property-type">timestamp</span></dt> <dd>The end of the current timeframe. Optional; defaults to <code>now</code>.</dd> <dt class="optional">from <span class="property-type">timestamp</span></dt> <dd> The start of the current timeframe. Optional; defaults to <code>to - 30 seconds</code>. </dd> </dl> <h3>Details</h3> <p> Connecting your machine to oee.ai is easy &ndash; the only requirement is sending the number of produced units (<code>msg.count</code>) during a short period of time (between <code>msg.from</code> and <code>msg.to</code>, usually 30 seconds) continuously via MQTT. </p> <p> This node takes care of formatting the payload into the required JSON document as well as creating and maintaining the connection to the oee.ai MQTT broker and sending the formatted payload every time it is called. </p> <p> Easily triggered by an Inject node that repeats every 30 seconds, the only thing left to do is adding the number of produced units in the last 30 seconds from the production machine (e.g. via an OPC UA node) to <code>msg.count</code>. This task is individual depending on the actual production machine and not covered by the scope of this node. </p> <p> If you are collecting machine data through an oee.ai SICK TDC gateway solution, we encourage the use of the oee.ai SICK TDC connector node as an input to this node. See its documentation for more information on how to set up an according flow. </p> <p> Note that the <code>msg.count</code> property is not the total number of units produced over all, but only the number of units produced in the current timeframe (i.e. the last 30 seconds). In other words, it is not the running total of the production machine and should reset to <code>0</code> after each 30 second period. </p> <h3>References</h3> <ul> <li> <a href="https://gitlab.com/ifp-software/node-red-contrib-oee-ai-connector"> GitLab </a> &ndash; this node&apos;s repository </li> </ul> </script>