before(done => { port += 1; const options = { port }; server = new OPCUAServer(options); server.on("post_initialize", () => { const addressSpace = server.engine.addressSpace!; const group = addressSpace.getOwnNamespace().addObject({ browseName: "Group", organizedBy: addressSpace.rootFolder.objects }); for (let i = 0; i < 27; i++) { addressSpace.getOwnNamespace().addObject({ browseName: "Object" + i, organizedBy: group }); } groupNodeId = group.nodeId; }); server.start((err?: Error) => { if (err) { return done(err); } endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl; if (err) { return done(err); } done(); }); });
async function main() { try { const server = new OPCUAServer({ nodeset_filename: [ nodesets.standard_nodeset_file ] }); await server.initialize(); // post-initialize const addressSpace = server.engine.addressSpace!; const object = installObjectWithMethod(addressSpace); console.log("object = ", object.toString()); await callMethodFromServer(addressSpace, object.nodeId); await server.start(); console.log(" Server started ", server.endpoints[0].endpointDescriptions()[0].endpointUrl); } catch (err) { console.log(" Error: ", err.message); console.log(err.stack); } }
// openssl req -x509 -newkey rsa:4096 -sha256 -nodes -keyout example.pem \ // -outform der -out example.der -subj "/CN=example.com" -days 3650 async function startServer(): Promise<OPCUAServer> { server = new OPCUAServer({ maxAllowedSessionNumber: 10, nodeset_filename: empty_nodeset_filename, port, }); await server.start(); endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl!; return server; }
async function main() { const server = new OPCUAServer(server_options); server.on("post_initialize", () => { /* empty */ }); console.log(chalk.yellow(" server PID :"), process.pid); console.log(chalk.yellow(" silent :"), argv.silent); await server.start(); const endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl!; console.log(chalk.yellow(" server on port :"), chalk.cyan(server.endpoints[0].port.toString())); console.log(chalk.yellow(" endpointUrl :"), chalk.cyan(endpointUrl)); console.log(chalk.yellow("\n server now waiting for connections. CTRL+C to stop")); if (argv.silent) { console.log("silent"); console.log = (...args: [any?, ... any[]]) => { /* silent */ }; } server.on("create_session", (session: ServerSession) => { console.log(" SESSION CREATED"); console.log(chalk.cyan(" client application URI: "), session.clientDescription!.applicationUri); console.log(chalk.cyan(" client product URI: "), session.clientDescription!.productUri); console.log(chalk.cyan(" client application name: "), session.clientDescription!.applicationName.toString()); console.log(chalk.cyan(" client application type: "), session.clientDescription!.applicationType.toString()); console.log(chalk.cyan(" session name: "), session.sessionName ? session.sessionName.toString() : "<null>"); console.log(chalk.cyan(" session timeout: "), session.sessionTimeout); console.log(chalk.cyan(" session id: "), session.nodeId); }); server.on("session_closed", (session: ServerSession, reason: string) => { console.log(" SESSION CLOSED :", reason); console.log(chalk.cyan(" session name: "), session.sessionName ? session.sessionName.toString() : "<null>"); }); process.on("SIGINT", async () => { // only work on linux apparently console.error(chalk.red.bold(" Received server interruption from user ")); console.error(chalk.red.bold(" shutting down ...")); await server.shutdown(1000); console.error(chalk.red.bold(" shot down ...")); process.exit(1); }); }
async function main() { const server = new OPCUAServer(server_options); console.log(chalk.yellow(" server PID :"), process.pid); server.on("post_initialize", () => { const addressSpace = server.engine.addressSpace!; // to do: expose new nodeid here const ns = addressSpace.getNamespaceIndex("http://yourorganisation.org/my_data_type/"); const myStructureType = addressSpace.findVariableType("MyStructureType", ns); if (!myStructureType) { console.log(" ns = ", ns, "cannot find MyStructureDataType "); return; } const namespace = addressSpace.getOwnNamespace(); const someObject = namespace.addObject({ browseName: "SomeObject", organizedBy: addressSpace.rootFolder.objects }); myStructureType.instantiate({ browseName: "MyVar", componentOf: someObject }); }); try { await server.start(); } catch (err) { console.log(" Server failed to start ... exiting"); process.exit(-3); } const endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl!; console.log(chalk.yellow(" server on port :"), chalk.cyan(server.endpoints[0].port.toString())); console.log(chalk.yellow(" endpointUrl :"), chalk.cyan(endpointUrl)); console.log(chalk.yellow("\n server now waiting for connections. CTRL+C to stop")); process.on("SIGINT", async () => { // only work on linux apparently await server.shutdown(1000); console.log(chalk.red.bold(" shutting down completed ")); process.exit(-1); }); }
async function main() { const tmpFolder = path.join(__dirname, "../certificates/myApp"); const applicationGroup = new CertificateManager({ location: tmpFolder }); await applicationGroup.initialize(); const server = new OPCUAServer(server_options); console.log(" Configuration rootdir = ", server.serverCertificateManager.rootDir); console.log(chalk.yellow(" server PID :"), process.pid); server.on("post_initialize", () => { const addressSpace = server.engine.addressSpace!; // to do: expose new nodeid here const ns = addressSpace.getNamespaceIndex("http://yourorganisation.org/my_data_type/"); installPushCertificateManagement(addressSpace, { applicationGroup: server.serverCertificateManager, userTokenGroup: server.userCertificateManager }); console.log("Certificate rejected folder ", server.serverCertificateManager.rejectedFolder); }); try { await server.start(); } catch (err) { console.log(" Server failed to start ... exiting"); process.exit(-3); } const endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl!; console.log(chalk.yellow(" server on port :"), chalk.cyan(server.endpoints[0].port.toString())); console.log(chalk.yellow(" endpointUrl :"), chalk.cyan(endpointUrl)); console.log(chalk.yellow("\n server now waiting for connections. CTRL+C to stop")); process.on("SIGINT", async () => { // only work on linux apparently await server.shutdown(1000); console.log(chalk.red.bold(" shutting down completed ")); process.exit(-1); }); }
async function startMultiHeadServer() { const server_options: OPCUAServerOptions = { isAuditing: false, nodeset_filename: [ nodesets.standard ], serverInfo: { applicationName: { text: "Mini NodeOPCUA Server", locale: "en" }, applicationUri: makeApplicationUrn("%FQDN%", "MiniNodeOPCUA-Server"), productUri: "Mini NodeOPCUA-Server" }, // default endpoint allowAnonymous: false, alternateHostname: ["MyHostname1"], port: port1, securityModes: [MessageSecurityMode.None], securityPolicies: [SecurityPolicy.None], // alternate endpoint alternateEndpoints: [ { allowAnonymous: false, alternateHostname: ["1.2.3.4"], port: port2, securityModes: [MessageSecurityMode.SignAndEncrypt], securityPolicies: [SecurityPolicy.Basic256Sha256] } ] }; server = new OPCUAServer(server_options); server.on("post_initialize", () => {/**/ }); console.log(chalk.yellow(" server PID :"), process.pid); try { await server.start(); } catch (err) { console.log(" Server failed to start ... exiting => err:", err.message); return; } }
async function startServer() { const server_options: OPCUAServerOptions = { port: port1, nodeset_filename: [ nodesets.standard ], serverInfo: { applicationUri: makeApplicationUrn("%FQDN%", "MiniNodeOPCUA-Server"), productUri: "Mini NodeOPCUA-Server", applicationName: { text: "Mini NodeOPCUA Server", locale: "en" } }, alternateHostname: ["MyHostname1", "MyHostname2"], isAuditing: false }; server = new OPCUAServer(server_options); server.on("post_initialize", () => {/**/ }); console.log(chalk.yellow(" server PID :"), process.pid); try { await server.start(); } catch (err) { console.log(" Server failed to start ... exiting => err:", err.message); return; } for (const endpoint of server.endpoints) { const endpointUrl = endpoint.endpointDescriptions()[0].endpointUrl!; console.log(chalk.yellow(" server on port1 :"), endpoint.port.toString()); console.log(chalk.yellow(" endpointUrl1 :"), chalk.cyan(endpointUrl)); } }
async function main() { process.title = "Node OPCUA Server on port : " + server_options.port; const server = new OPCUAServer(server_options); server.on("post_initialize", () => {/**/ }); console.log(chalk.yellow(" server PID :"), process.pid); try { await server.start(); } catch (err) { console.log(" Server failed to start ... exiting"); process.exit(-3); } const endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl!; console.log(chalk.yellow(" server on port :"), server.endpoints[0].port.toString()); console.log(chalk.yellow(" endpointUrl :"), chalk.cyan(endpointUrl)); console.log(chalk.yellow("\n server now waiting for connections. CTRL+C to stop")); server.on("create_session", (session: ServerSession) => { console.log(" SESSION CREATED"); console.log(chalk.cyan(" client application URI: "), session.clientDescription!.applicationUri); console.log(chalk.cyan(" client product URI: "), session.clientDescription!.productUri); console.log(chalk.cyan(" client application name: "), session.clientDescription!.applicationName.toString()); console.log(chalk.cyan(" client application type: "), session.clientDescription!.applicationType.toString()); console.log(chalk.cyan(" session name: "), session.sessionName ? session.sessionName.toString() : "<null>"); console.log(chalk.cyan(" session timeout: "), session.sessionTimeout); console.log(chalk.cyan(" session id: "), session.nodeId); }); server.on("session_closed", (session: ServerSession, reason: string) => { console.log(" SESSION CLOSED :", reason); console.log(chalk.cyan(" session name: "), session.sessionName ? session.sessionName.toString() : "<null>"); }); }
async function stopServer() { await server.shutdown(); }