Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
});
subscription.on("started", function () {
console.log("subscription id: ", subscription.subscriptionId);
}).on("terminated", function () {
cb();
});
setTimeout(function () {
subscription.terminate();
}, 5000);
// install monitored item
var monitor = subscription.monitor({
attributeId: opcua.AttributeIds.Value,
nodeId: opcua.resolveNodeId("ns=1;s=Variable1"),
},
{
discardOldest: true,
samplingInterval: 50,
queueSize: 5,
},
opcua.read_service.TimestampsToReturn.Both
);
monitor.on("changed", function (dataValue) {
console.log("Variable1 = ", dataValue.value.value);
// send to receiver
var data = {
device: "sensor1",
timestamp: Date.now(),
function _getAllEventTypes(baseNodeId, tree, callback) {
//xx console.log(" exploring elements,",element.nodeId.toString());
const browseDesc1 = {
nodeId: baseNodeId,
referenceTypeId: opcua.resolveNodeId("HasSubtype"),
browseDirection: BrowseDirection.Forward,
includeSubtypes: true,
nodeClassMask: opcua.NodeClassMask.ObjectType, // Objects
resultMask: 63
};
session.browse(browseDesc1, function (err, browseResult) {
if (err) {
console.log(" ERROR = ", err);
} else {
// to do continuation points
browseResult.references.forEach(function (reference) {
const subtree = { nodeId: reference.nodeId.toString() };
tree[reference.browseName.toString()] = subtree;
q.push({ nodeId: reference.nodeId, tree: subtree });
});
const q = async.queue(function worker(element, callback) {
//xx console.log(" exploring elements,",element.nodeId.toString());
const browseDesc1 = {
nodeId: element.nodeId,
referenceTypeId: opcua.resolveNodeId("HierarchicalReferences"),
browseDirection: BrowseDirection.Forward,
includeSubtypes: true,
nodeClassMask: 0x1, // Objects
resultMask: 63
};
const nodesToBrowse = [browseDesc1];
session.browse(nodesToBrowse, function (err, browseResults) {
if (err) {
console.log("err =", err);
}
if (!err) {
browseResults[0].references.forEach(function (ref) {
if (isConditionEventType(ref.typeDefinition)) {
//
const alarm = {
async function _getAllEventTypes(session: ClientSession, baseNodeId: NodeId, tree: any) {
const browseDesc1 = {
nodeId: baseNodeId,
referenceTypeId: resolveNodeId("HasSubtype"),
browseDirection: BrowseDirection.Forward,
includeSubtypes: true,
nodeClassMask: NodeClassMask.ObjectType, // Objects
resultMask: 63
};
const browseResult = await session.browse(browseDesc1);
const promises = [];
// to do continuation points
for (const reference of browseResult.references!) {
const subtree = { nodeId: reference.nodeId.toString() };
tree[reference.browseName.toString()] = subtree;
promises.push(_getAllEventTypes(session, reference.nodeId, subtree));
}
await Promise.all(promises);
async function worker(element: any) {
const nodeToBrowse = {
nodeId: element.nodeId,
referenceTypeId: resolveNodeId("HierarchicalReferences"),
browseDirection: BrowseDirection.Forward,
includeSubtypes: true,
nodeClassMask: 0x1, // Objects
resultMask: 63
};
const browseResult = await session1.browse(nodeToBrowse);
for (const ref of browseResult.references!) {
if (isConditionEventType(ref.typeDefinition)) {
//
const alarm = {
parent: element.nodeId,
alarmNodeId: ref.nodeId,
this.browse = function (node) {
let nodeId = (node) ? node.id : opcua.resolveNodeId('RootFolder');
return new Promise(function (resolve, reject) {
// "RootFolder"
if (the_session) {
const b = [{
nodeId: nodeId,
referenceTypeId: 'Organizes',
includeSubtypes: true,
browseDirection: opcua.BrowseDirection.Forward,
resultMask: 0x3f
},
{
nodeId: nodeId,
referenceTypeId: 'Aggregates',
includeSubtypes: true,
browseDirection: opcua.BrowseDirection.Forward,
async function findAllNodeOfType(tree, typeNodeId, browseName) {
const browseDesc1 = {
nodeId: typeNodeId,
referenceTypeId: opcua.resolveNodeId("HasSubtype"),
browseDirection: BrowseDirection.Forward,
includeSubtypes: true,
resultMask: 63
};
const browseDesc2 = {
nodeId: typeNodeId,
referenceTypeId: opcua.resolveNodeId("HasTypeDefinition"),
browseDirection: BrowseDirection.Inverse,
includeSubtypes: true,
resultMask: 63
};
const browseDesc3 = {
nodeId: typeNodeId,
referenceTypeId: opcua.resolveNodeId("HasTypeDefinition"),
browseDirection: BrowseDirection.Forward,
includeSubtypes: true,
resultMask: 63
};
const nodesToBrowse = [
browseDesc1,
browseDesc2,
browseDesc3
];
const browseResults = await session.browse(nodesToBrowse);
tree1[browseName] = {};
browseResults[0].references = browseResults[0].references || [];
const promises = [];
for (const reference of browseResults[0].references) {
conditionEventTypes[reference.nodeId.toString()] = reference.browseName.toString();
promises.push(findAllNodeOfType(tree1[browseName], reference.nodeId, reference.browseName.toString()));
}
await Promise.all(promises);
}
const typeNodeId = resolveNodeId("ConditionType");
await findAllNodeOfType(tree, typeNodeId, "ConditionType");
return tree;
}
function findAllNodeOfType(tree,typeNodeId,browseName,callback) {
const browseDesc1 = {
nodeId: typeNodeId,
referenceTypeId: opcua.resolveNodeId("HasSubtype"),
browseDirection: BrowseDirection.Forward,
includeSubtypes: true,
resultMask: 63
};
const browseDesc2 = {
nodeId: typeNodeId,
referenceTypeId: opcua.resolveNodeId("HasTypeDefinition"),
browseDirection: BrowseDirection.Inverse,
includeSubtypes: true,
resultMask: 63
};
const browseDesc3 = {
nodeId: typeNodeId,
referenceTypeId: opcua.resolveNodeId("HasTypeDefinition"),
browseDirection: BrowseDirection.Forward,
includeSubtypes: true,
resultMask: 63
};
const nodesToBrowse = [
browseDesc1,
};
found.push(alarm);
} else {
await worker(ref.nodeId);
}
}
}
await worker(nodeId);
}
await enumerateAllConditionTypes(session);
await exploreForObjectOfType(session, resolveNodeId("RootFolder"));
return Object.values(conditions);
}