node-opcua-samples 2.98.0 → 2.98.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/get_endpoints.d.ts +2 -0
  2. package/dist/get_endpoints.js +142 -0
  3. package/dist/get_endpoints.js.map +1 -0
  4. package/dist/mini_server.d.ts +1 -0
  5. package/dist/mini_server.js +89 -0
  6. package/dist/mini_server.js.map +1 -0
  7. package/dist/server_with_changing_password.d.ts +1 -0
  8. package/dist/server_with_changing_password.js +101 -0
  9. package/dist/server_with_changing_password.js.map +1 -0
  10. package/dist/server_with_push_certificate.d.ts +2 -0
  11. package/dist/server_with_push_certificate.js +112 -0
  12. package/dist/server_with_push_certificate.js.map +1 -0
  13. package/dist/simple_client_ts.d.ts +2 -0
  14. package/dist/simple_client_ts.js.map +1 -0
  15. package/dist/simple_findservers.d.ts +2 -0
  16. package/dist/simple_findservers.js +49 -0
  17. package/dist/simple_findservers.js.map +1 -0
  18. package/dist/simple_secure_server.d.ts +2 -0
  19. package/dist/simple_secure_server.js +126 -0
  20. package/dist/simple_secure_server.js.map +1 -0
  21. package/dist/simple_server_with_custom_extension_objects.d.ts +2 -0
  22. package/dist/simple_server_with_custom_extension_objects.js +82 -0
  23. package/dist/simple_server_with_custom_extension_objects.js.map +1 -0
  24. package/dist/stressing_client.d.ts +1 -0
  25. package/dist/stressing_client.js +37 -0
  26. package/dist/stressing_client.js.map +1 -0
  27. package/dist/tiny_client.d.ts +1 -0
  28. package/dist/tiny_client.js +33 -0
  29. package/dist/tiny_client.js.map +1 -0
  30. package/package.json +14 -11
  31. package/bin/createOPCUACertificate.cmd +0 -6
  32. package/bin/create_certificates.js +0 -2
  33. package/bin/crypto_create_CA.js +0 -2
  34. package/bin/demo_server_with_alarm.js +0 -51
  35. package/bin/findServersOnNetwork.js +0 -32
  36. package/bin/get_endpoints.ts +0 -166
  37. package/bin/machineryServer.js +0 -83
  38. package/bin/mini_server.ts +0 -106
  39. package/bin/more.js +0 -40
  40. package/bin/node-opcua.js +0 -2
  41. package/bin/opcua_interceptor.js +0 -122
  42. package/bin/server_with_changing_password.ts +0 -97
  43. package/bin/server_with_push_certificate.ts +0 -122
  44. package/bin/simple_client.js +0 -830
  45. package/bin/simple_client_ts.ts +0 -847
  46. package/bin/simple_findservers.ts +0 -45
  47. package/bin/simple_secure_server.ts +0 -152
  48. package/bin/simple_server_with_custom_extension_objects.ts +0 -89
  49. package/bin/stressing_client.ts +0 -28
  50. package/bin/tiny_client.ts +0 -24
@@ -1,45 +0,0 @@
1
- #!/usr/bin/env ts-node
2
- // tslint:disable:no-console
3
- // this script queries the discovery server and display the discovery urls
4
- import * as chalk from "chalk";
5
- import { MessageSecurityMode, ApplicationType, findServers } from "node-opcua";
6
-
7
- async function main() {
8
- const discovery_server_endpointUrl = "opc.tcp://localhost:4840/UADiscovery";
9
-
10
- console.log("Interrogating ", discovery_server_endpointUrl);
11
-
12
- try {
13
- const { servers, endpoints } = await findServers(discovery_server_endpointUrl);
14
- for (const server of servers) {
15
- console.log(" applicationUri:", chalk.cyan.bold(server.applicationUri!));
16
- console.log(" productUri:", chalk.cyan.bold(server.productUri!));
17
- console.log(" applicationName:", chalk.cyan.bold(server.applicationName!.text!));
18
- console.log(" type:", chalk.cyan.bold(ApplicationType[server.applicationType]));
19
- console.log(" gatewayServerUri:", server.gatewayServerUri ? chalk.cyan.bold(server.gatewayServerUri) : "");
20
- console.log("discoveryProfileUri:", server.discoveryProfileUri ? chalk.cyan.bold(server.discoveryProfileUri) : "");
21
- console.log(" discoveryUrls:");
22
-
23
- for (const discoveryUrl of server.discoveryUrls!) {
24
- console.log(" " + chalk.cyan.bold(discoveryUrl!));
25
- }
26
- console.log("-------------");
27
- }
28
-
29
- for (const endpoint of endpoints) {
30
- console.log(
31
- endpoint.endpointUrl!.toString(),
32
- endpoint.securityLevel,
33
- endpoint.securityPolicyUri,
34
- MessageSecurityMode[endpoint.securityMode]
35
- );
36
- }
37
- } catch (err) {
38
- if (err instanceof Error) {
39
- console.log("err ", err.message);
40
- }
41
- process.exit(-2);
42
- }
43
- }
44
-
45
- main();
@@ -1,152 +0,0 @@
1
- #!/usr/bin/env ts-node
2
- /* eslint no-process-exit: 0 */
3
- // tslint:disable:no-console
4
- import * as path from "path";
5
- import * as os from "os";
6
-
7
- import * as chalk from "chalk";
8
- import * as yargs from "yargs";
9
-
10
- import {
11
- makeApplicationUrn,
12
- MessageSecurityMode,
13
- nodesets,
14
- OPCUAServer,
15
- OPCUAServerOptions,
16
- SecurityPolicy,
17
- ServerSession
18
- } from "node-opcua";
19
-
20
- Error.stackTraceLimit = Infinity;
21
-
22
- function constructFilename(filename: string): string {
23
- return path.join(__dirname, "../", filename);
24
- }
25
-
26
- const userManager = {
27
- isValidUser: (userName: string, password: string) => {
28
- if (userName === "user1" && password === "password1") {
29
- return true;
30
- }
31
- if (userName === "user2" && password === "password2") {
32
- return true;
33
- }
34
- return false;
35
- }
36
- };
37
-
38
- async function main() {
39
- const argv = await yargs(process.argv)
40
- .wrap(132)
41
-
42
- .option("alternateHostname", {
43
- alias: "a",
44
- describe: "alternateHostname"
45
- })
46
-
47
- .option("port", {
48
- alias: "p",
49
- default: 26543
50
- })
51
-
52
- .option("silent", {
53
- alias: "s",
54
- default: false,
55
- describe: "silent - no trace"
56
- })
57
- .option("maxSessions", {
58
- alias: "m",
59
- default: 10
60
- })
61
- .help(true).argv;
62
-
63
- const port = argv.port || 26543;
64
- // server_options.alternateHostname = argv.alternateHostname;
65
-
66
- const server_options: OPCUAServerOptions = {
67
- securityPolicies: [SecurityPolicy.Basic128Rsa15, SecurityPolicy.Basic256],
68
-
69
- securityModes: [MessageSecurityMode.Sign, MessageSecurityMode.SignAndEncrypt],
70
-
71
- port,
72
-
73
- nodeset_filename: [nodesets.standard, nodesets.di],
74
-
75
- serverInfo: {
76
- applicationName: { text: "NodeOPCUA", locale: "en" },
77
- applicationUri: makeApplicationUrn(os.hostname(), "NodeOPCUA-SecureServer"),
78
- productUri: "NodeOPCUA-SecureServer",
79
-
80
- discoveryProfileUri: null,
81
- discoveryUrls: [],
82
- gatewayServerUri: null
83
- },
84
-
85
- buildInfo: {
86
- buildDate: new Date(),
87
- buildNumber: "1234"
88
- },
89
-
90
- serverCapabilities: {
91
- maxSessions: argv.maxSessions
92
- },
93
-
94
- maxConnectionsPerEndpoint: argv.maxSessions,
95
-
96
- userManager,
97
-
98
- isAuditing: false
99
- };
100
-
101
- process.title = "Node OPCUA Server on port : " + server_options.port;
102
-
103
- const server = new OPCUAServer(server_options);
104
-
105
- server.on("post_initialize", () => {
106
- /* empty */
107
- });
108
-
109
- console.log(chalk.yellow(" server PID :"), process.pid);
110
- console.log(chalk.yellow(" silent :"), argv.silent);
111
-
112
- await server.start();
113
-
114
- const endpointUrl = server.getEndpointUrl()!;
115
- console.log(chalk.yellow(" server on port :"), chalk.cyan(server.endpoints[0].port.toString()));
116
- console.log(chalk.yellow(" endpointUrl :"), chalk.cyan(endpointUrl));
117
-
118
- console.log(chalk.yellow("\n server now waiting for connections. CTRL+C to stop"));
119
-
120
- if (argv.silent) {
121
- console.log("silent");
122
- console.log = (...args: [any?, ...any[]]) => {
123
- /* silent */
124
- };
125
- }
126
-
127
- server.on("create_session", (session: ServerSession) => {
128
- console.log(" SESSION CREATED");
129
- console.log(chalk.cyan(" client application URI: "), session.clientDescription!.applicationUri);
130
- console.log(chalk.cyan(" client product URI: "), session.clientDescription!.productUri);
131
- console.log(chalk.cyan(" client application name: "), session.clientDescription!.applicationName.toString());
132
- console.log(chalk.cyan(" client application type: "), session.clientDescription!.applicationType.toString());
133
- console.log(chalk.cyan(" session name: "), session.sessionName ? session.sessionName.toString() : "<null>");
134
- console.log(chalk.cyan(" session timeout: "), session.sessionTimeout);
135
- console.log(chalk.cyan(" session id: "), session.nodeId);
136
- });
137
-
138
- server.on("session_closed", (session: ServerSession, reason: string) => {
139
- console.log(" SESSION CLOSED :", reason);
140
- console.log(chalk.cyan(" session name: "), session.sessionName ? session.sessionName.toString() : "<null>");
141
- });
142
-
143
- process.on("SIGINT", async () => {
144
- // only work on linux apparently
145
- console.error(chalk.red.bold(" Received server interruption from user "));
146
- console.error(chalk.red.bold(" shutting down ..."));
147
- await server.shutdown(1000);
148
- console.error(chalk.red.bold(" shot down ..."));
149
- process.exit(1);
150
- });
151
- }
152
- main();
@@ -1,89 +0,0 @@
1
- #!/usr/bin/env ts-node
2
- /* eslint no-process-exit: 0 */
3
- // tslint:disable:no-console
4
- import * as path from "path";
5
- import * as chalk from "chalk";
6
- import { nodesets, OPCUAServer } from "node-opcua";
7
- import * as yargs from "yargs";
8
- import { Argv } from "yargs";
9
-
10
- Error.stackTraceLimit = Infinity;
11
-
12
-
13
- function constructFilename(filename: string): string {
14
- return path.join(__dirname, "../", filename);
15
- }
16
-
17
- const rootFolder = path.join(__dirname, "../../..");
18
-
19
- async function main() {
20
-
21
- const argv = await yargs.wrap(132).option("port", {
22
- alias: "p",
23
- default: "26543",
24
- describe: "port to listen"
25
- }).argv;
26
- const port = parseInt(argv.port, 10) || 26555;
27
- const server_certificate_file = constructFilename("certificates/server_cert_2048.pem");
28
- const server_certificate_privatekey_file = constructFilename("certificates/server_key_2048.pem");
29
-
30
- const server_options = {
31
- certificateFile: server_certificate_file,
32
- privateKeyFile: server_certificate_privatekey_file,
33
-
34
- port,
35
-
36
- nodeset_filename: [nodesets.standard, path.join(rootFolder, "modeling/my_data_type.xml")]
37
- };
38
-
39
- process.title = "Node OPCUA Server on port : " + server_options.port;
40
-
41
-
42
- const server = new OPCUAServer(server_options);
43
-
44
- console.log(chalk.yellow(" server PID :"), process.pid);
45
-
46
- server.on("post_initialize", () => {
47
- const addressSpace = server.engine.addressSpace!;
48
-
49
- // to do: expose new nodeid here
50
- const ns = addressSpace.getNamespaceIndex("http://yourorganisation.org/my_data_type/");
51
- const myStructureType = addressSpace.findVariableType("MyStructureType", ns);
52
- if (!myStructureType) {
53
- console.log(" ns = ", ns, "cannot find MyStructureDataType ");
54
- return;
55
- }
56
-
57
- const namespace = addressSpace.getOwnNamespace();
58
- const someObject = namespace.addObject({
59
- browseName: "SomeObject",
60
- organizedBy: addressSpace.rootFolder.objects
61
- });
62
-
63
- myStructureType.instantiate({
64
- browseName: "MyVar",
65
- componentOf: someObject
66
- });
67
- });
68
-
69
- try {
70
- await server.start();
71
- } catch (err) {
72
- console.log(" Server failed to start ... exiting");
73
- process.exit(-3);
74
- }
75
-
76
- const endpointUrl = server.getEndpointUrl()!;
77
-
78
- console.log(chalk.yellow(" server on port :"), chalk.cyan(server.endpoints[0].port.toString()));
79
- console.log(chalk.yellow(" endpointUrl :"), chalk.cyan(endpointUrl));
80
- console.log(chalk.yellow("\n server now waiting for connections. CTRL+C to stop"));
81
-
82
- process.on("SIGINT", async () => {
83
- // only work on linux apparently
84
- await server.shutdown(1000);
85
- console.log(chalk.red.bold(" shutting down completed "));
86
- process.exit(-1);
87
- });
88
- }
89
- main();
@@ -1,28 +0,0 @@
1
- // tslint:disable:no-console
2
- import { OPCUAClient } from "node-opcua";
3
-
4
- const endpointUrl = "opc.tcp://localhost:26543";
5
-
6
- async function main() {
7
- let counter = 1;
8
-
9
- while (true) {
10
- const client = OPCUAClient.create({ endpointMustExist: false });
11
- client.on("backoff", (retryCount: number, delay: number) => console.log(" backoff", retryCount, delay));
12
-
13
- try {
14
- await client.connect(endpointUrl);
15
- const session = await client.createSession();
16
- await session.close();
17
- await client.disconnect();
18
- } catch (err) {
19
- if (err instanceof Error) {
20
- console.log("err", err.message);
21
- }
22
- }
23
-
24
- console.log(" Connected = ", counter++);
25
- }
26
- }
27
-
28
- main();
@@ -1,24 +0,0 @@
1
- process.env.NODEOPCUADEBUG = "CLIENT{TRACE};TRANSPORT{CHUNK-HELACK}";
2
- import { OPCUAClient } from "node-opcua";
3
-
4
- (async () => {
5
- const client = OPCUAClient.create({
6
- requestedSessionTimeout: 1000,
7
- transportSettings: {
8
- maxChunkCount: 1,
9
- maxMessageSize: 1 * 8192, // should be at least 8192
10
- receiveBufferSize: 8 * 1024,
11
- sendBufferSize: 8 * 1024
12
- },
13
- connectionStrategy: {
14
- initialDelay: 10,
15
- maxDelay: 100,
16
- maxRetry: 2
17
- }
18
- });
19
-
20
- await client.connect("opc.tcp://localhost:48010");
21
- // await client.connect("opc.tcp://localhost:53530");
22
-
23
- await client.disconnect();
24
- })();