How to use the node-opcua.AttributeIds function in node-opcua

To help you get started, we’ve selected a few node-opcua examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PacktPublishing / Industrial-Internet-Application-Development / Chapter03 / opcua / hub / index.js View on Github external
requestedPublishingInterval: 500,
      });

      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",
github locka99 / opcua / 3rd-party / node-opcua / client.js View on Github external
the_subscription.on("started", () => {
                console.log("subscription started for 2 seconds - subscriptionId=", the_subscription.subscriptionId);
            }).on("keepalive", () => {
                console.log("keepalive");
            }).on("terminated", () => {
                callback();
            });

            setTimeout(() => {
                the_subscription.terminate();
            }, 10000);

            // install monitored item
            var monitoredItem = the_subscription.monitor({
                    nodeId: opcua.resolveNodeId(node_id),
                    attributeId: opcua.AttributeIds.Value
                },
                {
                    samplingInterval: 100,
                    discardOldest: true,
                    queueSize: 10
                },
                opcua.read_service.TimestampsToReturn.Both
            );
            console.log("-------------------------------------");

            monitoredItem.on("changed", dataValue => {
                console.log(" % free mem = ", dataValue.value.value);
            });
        },
github node-opcua / node-opcua / documentation / sample_client.js View on Github external
function(callback) {
       // install monitored item
       const itemToMonitor = {
         nodeId: opcua.resolveNodeId("ns=1;s=free_memory"),
         attributeId: opcua.AttributeIds.Value
       };
       const monitoringParamaters = {
         samplingInterval: 100,
         discardOldest: true,
         queueSize: 10
       };
       
       the_subscription.monitor(
         itemToMonitor,
         monitoringParamaters,
         opcua.TimestampsToReturn.Both,
         (err, monitoredItem) => {
           monitoredItem.on("changed", function(dataValue) {
             console.log(
               "monitored item changed:  % free mem = ",
               dataValue.value.value
github frangoteam / FUXA / server / runtime / devices / opcua / index.js View on Github external
function OpcUAclient(_data, _logger, _events) {

    var data = _data;                   // Current Device data { id, name, tags, enabled, ... }
    var logger = _logger;               // Logger
    var working = false;                // Working flag to manage overloading polling and connection
    var connected = false;              // Connected flag
    var monitored = false;              // Monitored flag
    var lastStatus = '';                // Last Device status
    var events = _events;               // Events to commit change to runtime
    var the_session;
    var the_subscription = null;
    var options = { connectionStrategy: { maxRetry: 1 }, keepSessionAlive: true };  // Connections options
    var client = new opcua.OPCUAClient(options);
    const attributeKeys = Object.keys(opcua.AttributeIds).filter((x) => x === 'DataType' || x === 'AccessLevel' || x === 'UserAccessLevel');//x !== "INVALID" && x[0].match(/[a-zA-Z]/));

    var varsValue = [];                 // Signale to send to frontend { id, type, value }
    var daqInterval = 0;                // To manage minimum interval to save a DAQ value
    var lastDaqInterval = 0;            // To manage minimum interval to save a DAQ value
    var getProperty = null;             // Function to ask property (security)

    /**
     * Connect the client to OPC UA server
     * Open Session, Create Subscription, Emit connection status, Clear the memory Tags value
     */
    this.connect = function () {
        return new Promise(function (resolve, reject) {
            if (!_checkWorking(true)) {
                reject();
            } else {
                var property = null;
github frangoteam / FUXA / server / runtime / devices / opcua / index.js View on Github external
// case opcua.AttributeIds.UserWriteMask:
            //     return " (" + dataValue.value.value + ")";
            // case opcua.AttributeIds.NodeId:
            // case opcua.AttributeIds.BrowseName:
            // case opcua.AttributeIds.DisplayName:
            // case opcua.AttributeIds.Description:
            // case opcua.AttributeIds.ValueRank:
            // case opcua.AttributeIds.ArrayDimensions:
            // case opcua.AttributeIds.Executable:
            // case opcua.AttributeIds.UserExecutable:
            // case opcua.AttributeIds.MinimumSamplingInterval:
            //     if (!dataValue.value.value) {
            //         return "null";
            //     }
            //     return dataValue.value.value.toString();
            case opcua.AttributeIds.UserAccessLevel:
            case opcua.AttributeIds.AccessLevel:
                if (!dataValue.value.value) {
                    return null;
                }
                let rlev = opcua.AccessLevelFlag[dataValue.value.value & 1];
                let wlev = opcua.AccessLevelFlag[dataValue.value.value & 2];
                let lev = '';
                if (rlev) {
                    lev += 'R';
                }
                if (wlev) {
                    if (rlev) {
                        lev += '/';
                    }
                    lev += 'W';
                }
github node-opcua / node-opcua / packages / node-opcua-samples / bin / simple_client.js View on Github external
console.log(chalk.cyan("securityPolicy      = "), securityPolicy.toString());
console.log(chalk.cyan("timeout             = "), timeout ? timeout : " Infinity ");
console.log(" monitoring node id = ", monitored_node);
let client = null;

const endpointUrl = argv.endpoint;


if (!endpointUrl) {
    require("yargs").showHelp();
    process.exit(0);
}
let the_session = null;
let the_subscription = null;

const AttributeIds = opcua.AttributeIds;
const DataType = opcua.DataType;

const NodeCrawler = opcua.NodeCrawler;
const doCrawling = !!argv.crawl;
const doHistory = !!argv.history;

let serverCertificate = null;

const path = require("path");
const crypto_utils = opcua.crypto_utils;


async function getBrowseName(session, nodeId) {
    const dataValue = await session.read({ nodeId: nodeId, attributeId: AttributeIds.BrowseName });
    if (dataValue.statusCode === opcua.StatusCodes.Good) {
        return dataValue.value.value.name;
github node-opcua / node-opcua / packages / node-opcua-samples / bin / simple_client.js View on Github external
console.log(" monitoring node id = ", monitored_node);
let client = null;

const endpointUrl = argv.endpoint;


if (!endpointUrl) {
    require("yargs").showHelp();
    process.exit(0);
}

let the_session = null;
let the_subscription = null;
let serverCertificate = null;

const AttributeIds = opcua.AttributeIds;
const DataType = opcua.DataType;

const NodeCrawler = opcua.NodeCrawler;
const doCrawling = !!argv.crawl;
const doHistory = !!argv.history;




function getBrowseName(session,nodeId,callback) {
    session.read({ nodeId: nodeId, attributeId: AttributeIds.BrowseName},function(err, dataValue) {
        if (!err) {
            if (dataValue.statusCode === opcua.StatusCodes.Good) {
                assert(dataValue.statusCode === opcua.StatusCodes.Good);
                const browseName = dataValue.value.value.name;
                return callback(null,browseName);
github coussej / node-opcua-logger / readpump.js View on Github external
self.measurements.forEach(function(m) {
        if (m.hasOwnProperty("collectionType")) {
            switch (m.collectionType) {
                case "monitored":
                    if (m.hasOwnProperty("monitorResolution")) {
                        self.monitoredMeasurements.push({
                            name: m.name,
                            dataType: m.dataType,
                            nodeId: m.nodeId,
                            attributeId: opcua.AttributeIds.Value,
                            tags: m.tags,
                            monitorResolution: m.monitorResolution,
                            deadbandAbsolute: m.deadbandAbsolute || 0,
                            deadbandRelative: m.deadbandRelative || 0,
                            lastValue: null,
                            lastOpcstatus: null
                        });
                    } else {
                        console.log("Measurement was specified as monitored but has no monitorResolution", m);
                    }
                    break;
                case "polled":
                    if (m.hasOwnProperty("pollRate") &&
                        m.pollRate >= 1 &&
                        m.pollRate <= 60) {
                        var pollInterval = Math.round(60 / m.pollRate);
github coussej / node-opcua-logger / src / opcua.js View on Github external
function _addMonitoredMetric (metric) {
  let samplingInterval = metric.interval
    ? Math.max(metric.interval, 1) : 1000

  let uaMonitoredItem = opcua.ClientMonitoredItem.create(
    UASUBSCRIPTION,
    {
      nodeId: metric.nodeId,
      attributeId: opcua.AttributeIds.Value
    }, {
      clienthandle: 13,
      samplingInterval: samplingInterval,
      discardOldest: true,
      queueSize: 100
    }, opcua.TimestampsToReturn.Both)

  uaMonitoredItem
    .on('changed', (datavalue) => {
      let p = _datavalueToPoint(metric, datavalue)
      if (p.shouldRecord()) _producePoints([p])
    })
    .on('err', (err) => {
      log.error('MonitoredItem returned error.', { nodeId: metric.nodeId, error: err })
      setTimeout(() => _addMonitoredMetric(metric), 5000)
    })