Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
securityPolicy,
serverCertificate,
defaultSecureTokenLifetime: 40000,
endpoint_must_exist: false,
connectionStrategy: {
initialDelay: 2000,
maxDelay: 10 * 1000,
maxRetry: 10
}
};
console.log("Options = ", options.securityMode.toString(), options.securityPolicy.toString());
client = OPCUAClient.create(options);
console.log(" reconnecting to ", chalk.cyan.bold(endpointUrl));
await client.connect(endpointUrl);
let userIdentity: any; // anonymous
if (argv.userName && argv.password) {
userIdentity = {
password: argv.password,
userName: argv.userName
};
}
the_session = await client.createSession(userIdentity);
client.on("connection_reestablished", () => {
async function main() {
const client = OPCUAClient.create({
endpoint_must_exist: false
});
client.on("backoff", (retry: number, delay: number) => {
console.log(" cannot connect to endpoint retry = ", retry,
" next attempt in ", delay / 1000, "seconds");
});
// put the endpoint to your OPCUA Server here
const endpointUrl = "opc.tcp://localhost:48020";
try {
await client.connect(endpointUrl);
} from "node-opcua";
const connectionStrategy = {
initialDelay: 1000,
maxRetry: 1
};
const options = {
applicationName: "MyClient",
connectionStrategy: connectionStrategy,
securityMode: MessageSecurityMode.None,
securityPolicy: SecurityPolicy.None,
endpoint_must_exist: false
};
const client = OPCUAClient.create(options);
const endpointUrl = "opc.tcp://opcuademo.sterfive.com:26543";
async function main() {
try {
// step 1 : connect to
await client.connect(endpointUrl);
console.log("connected !");
// step 2 : createSession
const session = await client.createSession();
console.log("session created !");
// step 3 : browse
const browseResult = await session.browse("RootFolder");
console.log("references of RootFolder :");
for (const reference of browseResult.references) {
(async () => {
try {
const client = OPCUAClient.create({
applicationName: "ClientBrowseNextDemo",
connectionStrategy: { maxRetry: -1 },
endpoint_must_exist: false,
keepSessionAlive: true,
requestedSessionTimeout: 60 * 1000,
// securityMode: MessageSecurityMode.SignAndEncrypt,
// securityPolicy: SecurityPolicy.Basic256,
connectionStrategy: {
maxRetry: -1,
maxDelay: 500,
initialDelay: 100,
},
requestedSessionTimeout: 10000,
certificateFile: "./certificates/client_certificate.pem",
securityMode,
securityPolicy,
endpoint_must_exist: false,
keepSessionAlive: true,
connectionStrategy: {
initialDelay: 2000,
maxDelay: 10 * 1000,
maxRetry: 10
},
discoveryUrl
};
client = OPCUAClient.create(optionsInitial);
client.on("backoff", (retry: number, delay: number) => {
console.log(chalk.bgWhite.yellow("backoff attempt #"), retry, " retrying in ", delay / 1000.0, " seconds");
});
console.log(" connecting to ", chalk.cyan.bold(endpointUrl));
console.log(" strategy", client.connectionStrategy);
try {
await client.connect(endpointUrl);
} catch (err) {
console.log(chalk.red(" Cannot connect to ") + endpointUrl);
console.log(" Error = ", err.message);
return;
}
(async () => {
try {
const client = OPCUAClient.create({
endpoint_must_exist: false
});
client.on("backoff", (retry, delay) => {
console.log("Retrying to connect to ", endpointUrl, " attempt ", retry);
});
console.log(" connecting to ", chalk.cyan(endpointUrl));
await client.connect(endpointUrl);
console.log(" connected to ", chalk.cyan(endpointUrl));
const session = await client.createSession();
console.log(" session created".yellow);
const subscription = await session.createSubscription2({
requestedPublishingInterval: 2000,
requestedMaxKeepAliveCount: 20,
requestedLifetimeCount: 6000,