Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports.node_managment_service = require("node-opcua-service-node-management");
module.exports.ServerState = require("node-opcua-common").ServerState;
module.exports.ServiceCounter = require("node-opcua-common").ServiceCounter;
module.exports.SecurityPolicy = require("node-opcua-secure-channel").SecurityPolicy;
module.exports.MessageSecurityMode = require("node-opcua-service-secure-channel").MessageSecurityMode;
module.exports.utils = require("node-opcua-utils");
module.exports.crypto_utils = require("node-opcua-crypto");
module.exports.hexDump = require("node-opcua-debug").hexDump;
//----------------------------------------------------------------------------------------------------------------------
// client services
//----------------------------------------------------------------------------------------------------------------------
module.exports.OPCUAClient = require("node-opcua-client").OPCUAClient;
module.exports.OPCUAClientBase = require("node-opcua-client").OPCUAClientBase;
module.exports.NodeCrawler = require("node-opcua-client-crawler").NodeCrawler;
module.exports.ClientSubscription = require("node-opcua-client").ClientSubscription;
module.exports.ClientSession = require("node-opcua-client").ClientSession;
module.exports.client_utils = require("node-opcua-client/src/client_utils");
module.exports.perform_findServers = require("node-opcua-client").perform_findServers;
module.exports.perform_findServersOnNetwork = require("node-opcua-client").perform_findServersOnNetwork;
module.exports.readHistoryServerCapabilities = require("node-opcua-client").readHistoryServerCapabilities;
module.exports.callConditionRefresh = require("node-opcua-client/src/alarms_and_conditions/client_tools").callConditionRefresh;
module.exports.parseEndpointUrl = require("node-opcua-transport").parseEndpointUrl;
//----------------------------------------------------------------------------------------------------------------------
function parse_opcua_server(endpoint, callback) {
const options = {
endpoint_must_exist: false,
keepSessionAlive: true,
connectionStrategy: {
maxRetry: 10,
initialDelay: 2000,
maxDelay: 10 * 1000
}
};
const client = opcua.OPCUAClient.create(options);
client.withSession(endpointUrl, function (session, callback) {
callbackify(parse_opcua_common)(session, callback);
}, function (err) {
callback(err);
});
}
const privateKeyFile = path.join(__dirname, "certificates", "PKI/own/private/private_key.pem");
const data = {
reconnectionCount: 0,
tokenRenewalCount: 0,
receivedBytes: 0,
sentBytes: 0,
sentChunks: 0,
receivedChunks: 0,
backoffCount: 0,
transactionCount: 0,
};
const client = opcua.OPCUAClient.create({
endpoint_must_exist: false,
securityMode: securityMode,
securityPolicy: securityPolicy,
//xx serverCertificate: serverCertificate,
defaultSecureTokenLifetime: 40000,
certificateFile: certificateFile,
privateKeyFile: privateKeyFile,
keepSessionAlive: true
});
client.on("send_request", function () {
data.transactionCount++;