How to use the node-opcua.OPCUAClient 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
var opcua = require("node-opcua");
var async = require("async");
var request = require("request");

var session, subscription;
var client = new opcua.OPCUAClient();
var sensor = "opc.tcp://REMOTE-SENSOR-ADDRESS:4334/UA/resourcePath";
var receiver = "http://REMOTE-SERVER-ADDRESS.com:8080";

async.series(
  [
    // establishing connection
    function (cb) {
      client.connect(sensor, function (err) {
        if (err) {
          console.log("Connection to " + sensor + "failed");
        } else {
          console.log("Connection successful");
        }
        cb(err);
      });
    },
github locka99 / opcua / 3rd-party / node-opcua / client.js View on Github external
// Adapted from node-opcua sample client
// https://github.com/node-opcua/node-opcua/blob/master/documentation/sample_client.js

var opcua = require("node-opcua");
var async = require("async");

var client = new opcua.OPCUAClient();
var endpointUrl = "opc.tcp://127.0.0.1:4855/";

var the_session, the_subscription;

var node_id = "ns=2;s=v1";

async.series([
        // step 1 : connect to
        callback => {
            client.connect(endpointUrl, err => {
                if (err) {
                    console.log(" cannot connect to endpoint :", endpointUrl);
                } else {
                    console.log("connected !");
                }
                callback(err);
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 {
github node-opcua / node-opcua / packages / node-opcua-samples / bin / simple_client.js View on Github external
const options = {
            
            endpoint_must_exist: false,
            keepSessionAlive: true,
            connectionStrategy: {
                maxRetry: 10,
                initialDelay: 2000,
                maxDelay: 10*1000
            },
            certificateFile: certificate_file,
            privateKeyFile: certificate_privatekey_file

        };

        client = new opcua.OPCUAClient(options);

        console.log(" connecting to      = ".cyan, endpointUrl.cyan.bold);
        console.log("    strategy        = ".cyan, client.connectionStrategy);
        console.log("client certificate  = ".cyan, client.certificateFile);
        console.log("client private key  = ".cyan, client.privateKeyFile);
        
        client.connect(endpointUrl, callback);

        client.on("backoff", function (number, delay) {
            console.log("backoff  attempt #".bgWhite.yellow,number, " retrying in ",delay/1000.0," seconds");
        });

    },
github node-opcua / node-opcua / packages / node-opcua-samples / bin / simple_client.js View on Github external
defaultSecureTokenLifetime: 40000,

            endpoint_must_exist:false,

            connectionStrategy: {
                maxRetry: 10,
                initialDelay: 2000,
                maxDelay: 10*1000
            },
            certificateFile: certificate_file,
            privateKeyFile: certificate_privatekey_file

        };
        console.log("Options = ", options.securityMode.toString(), options.securityPolicy.toString());

        client = new opcua.OPCUAClient(options);

        console.log(" reconnecting to ", endpointUrl.cyan.bold);
        client.connect(endpointUrl, callback);
    },
github frangoteam / FUXA / server / runtime / devices / opcua / index.js View on Github external
var opts = { 
                                        endpoint_must_exist: false, 
                                        keepSessionAlive: true,
                                        connectionStrategy: { maxRetry: 1 } };
                                    if (property.mode) {
                                        if (property.mode.securityMode) {
                                            opts['securityMode'] = property.mode.securityMode;
                                        }
                                        if (property.mode.securityPolicy) {
                                            opts['securityPolicy'] = property.mode.securityPolicy;
                                        }
                                        if (property.mode.securityPolicy) {
                                            opts['securityPolicy'] = property.mode.securityPolicy;
                                        }
                                    }
                                    client = new opcua.OPCUAClient(opts);  
                                }
                                callback();
                            }).catch(function (err) {
                                callback(err);
github coussej / node-opcua-logger / readpump.js View on Github external
function ReadPump(config, measurements, writepump) {
    this.uaServerUrl = config.url;
    this.uaClient = new opcua.OPCUAClient();
    this.uaSession;
    this.uaSubscription;
    this.measurements = measurements;
    this.polledMeasurements = [];
    this.monitoredMeasurements = [];
    this.writepump = writepump;
    this.poller;
}
github frangoteam / FUXA / server / runtime / devices / opcua / index.js View on Github external
return new Promise(function (resolve, reject) {
        let opts = { connectionStrategy: { maxRetry: 1 } };
        let client = new opcua.OPCUAClient(opts);
        try {
            client.connect(endpointUrl, function (err) {
                if (err) {
                    reject('getendpoints-connect-error: ' + err.message);
                } else {
                    const endpoints = client.getEndpoints().then(endpoints => {
                        const reducedEndpoints = endpoints.map(endpoint => ({ 
                            endpointUrl: endpoint.endpointUrl, 
                            securityMode: endpoint.securityMode.toString(), 
                            securityPolicy: endpoint.securityPolicyUri.toString(),
                        }));
                        resolve( reducedEndpoints);
                        client.disconnect();
                    }, reason => {
                        reject('getendpoints-error: ' + reason);
                        client.disconnect();