UNPKG

node-red-contrib-iiot-opcua

Version:

An Industrial IoT OPC UA toolbox contribution package for Node-RED based on node-opcua.

73 lines (70 loc) 2.98 kB
/* The BSD 3-Clause License Copyright 2022 - DATATRONiQ GmbH (https://datatroniq.com) Copyright (c) 2018-2022 Klaus Landsdorf (http://node-red.plus/) All rights reserved. node-red-contrib-iiot-opcua */ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); const opcua_iiot_core_1 = require("./core/opcua-iiot-core"); const node_opcua_1 = require("node-opcua"); const opcua_iiot_core_connector_1 = require("./core/opcua-iiot-core-connector"); var internalDebugLog = opcua_iiot_core_connector_1.logger.internalDebugLog; /** * Address space object Node-RED node. * * @param RED */ module.exports = (RED) => { // SOURCE-MAP-REQUIRED function OPCUAIIoTASO(config) { RED.nodes.createNode(this, config); this.nodeId = config.nodeId; this.browsename = config.browsename; this.displayname = config.displayname; this.objecttype = config.objecttype; this.referencetype = config.referencetype; this.referenceNodeId = config.referenceNodeId; this.datatype = config.datatype; this.value = config.value; this.name = config.name; let self = this; internalDebugLog('Open ASO Node'); this.on('input', (msg) => { if (msg.payload.nodetype === 'inject') { self.nodeId = msg.payload.topic || self.nodeId; self.datatype = msg.payload.datatype || self.datatype; self.value = msg.payload.payload || self.value; } const value = self.value || msg.payload.value; msg = { payload: {} }; // clean message msg.topic = 'ServerAddressSpaceObject'; msg.payload.nodetype = 'inject'; msg.payload.injectType = 'ASO'; if (self.nodeId.includes('i=') || self.nodeId.includes('s=') || self.nodeId.includes('b=')) { msg.payload.nodeId = self.nodeId; msg.payload.browsename = self.browsename; msg.payload.displayname = self.displayname; msg.payload.objecttype = self.objecttype; msg.payload.datatype = self.datatype; msg.payload.value = value; msg.payload.referenceNodeId = self.referenceNodeId || opcua_iiot_core_1.OBJECTS_ROOT; msg.payload.referencetype = self.referencetype || node_opcua_1.ReferenceTypeIds.Organizes; internalDebugLog('node msg stringified: ' + JSON.stringify(msg)); this.send(msg); } else { /* istanbul ignore next */ this.error(new Error('ASO NodeId Is Not Valid'), msg); } }); this.on('close', (done) => { internalDebugLog('Close ASO Node'); (0, opcua_iiot_core_1.resetIiotNode)(self); done(); }); } RED.nodes.registerType('OPCUA-IIoT-Server-ASO', OPCUAIIoTASO); }; //# sourceMappingURL=opcua-iiot-server-aso.js.map