Skip to content

Instantly share code, notes, and snippets.

@erossignon
Created October 13, 2020 09:21
Show Gist options
  • Save erossignon/88d73c43bba876012800e0f1c07163ea to your computer and use it in GitHub Desktop.
Save erossignon/88d73c43bba876012800e0f1c07163ea to your computer and use it in GitHub Desktop.
simple script to get OPCUA server endpoint
### how to use
node getEndpointBasic.js opc.tcp://opcuademo.sterfive.com:26543
const { OPCUAClient, SecurityPolicy, MessageSecurityMode } = require("node-opcua");
const endpointUri = process.argv[2] || "opc.tcp://opcuademo.sterfive.com:26543";
(async () => {
try {
console.log("connecting to ", endpointUri);
const client = OPCUAClient.create({ endpoint_must_exist: false });
client.on("backoff", () => {
console.log("still connecting ", endpointUri);
})
await client.connect(endpointUri);
const endpoints = await client.getEndpoints();
for (const endpoint of endpoints) {
console.log(
endpoint.endpointUrl.padEnd(40),
endpoint.securityPolicyUri.padEnd(60),
MessageSecurityMode[endpoint.securityMode]
);
}
await client.disconnect();
}
catch (err) {
console.log(err.message);
process.exit();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment