node-opcua-samples 2.83.0 → 2.84.0
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.
- package/bin/di_server.js +40 -60
- package/package.json +6 -6
package/bin/di_server.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const os = require("os");
|
|
5
|
-
const { hostname} = require("os");
|
|
6
5
|
const chalk = require("chalk");
|
|
7
|
-
const
|
|
6
|
+
const { OPCUAServer, Variant, DataType, makeApplicationUrn, nodesets, RegisterServerMethod } = require("node-opcua");
|
|
7
|
+
const { makeBoiler, createBoilerType } = require("node-opcua-address-space/testHelpers");
|
|
8
|
+
|
|
8
9
|
Error.stackTraceLimit = Infinity;
|
|
9
10
|
|
|
10
11
|
function constructFilename(filename) {
|
|
@@ -31,21 +32,12 @@ const argv = require("yargs")
|
|
|
31
32
|
.string("discoveryServerEndpointUrl")
|
|
32
33
|
.describe("discoveryServerEndpointUrl", " end point of the discovery server to regiser to")
|
|
33
34
|
.default("discoveryServerEndpointUrl", "opc.tcp://localhost:4840")
|
|
34
|
-
.alias("d", "discoveryServerEndpointUrl")
|
|
35
|
-
.argv;
|
|
36
|
-
|
|
37
|
-
const OPCUAServer = opcua.OPCUAServer;
|
|
38
|
-
const Variant = opcua.Variant;
|
|
39
|
-
const DataType = opcua.DataType;
|
|
40
|
-
|
|
41
|
-
const makeApplicationUrn = opcua.makeApplicationUrn;
|
|
42
|
-
const nodesets = opcua.nodesets;
|
|
35
|
+
.alias("d", "discoveryServerEndpointUrl").argv;
|
|
43
36
|
|
|
44
37
|
const port = parseInt(argv.port) || 26543;
|
|
45
38
|
|
|
46
39
|
const userManager = {
|
|
47
|
-
isValidUser: function(userName, password) {
|
|
48
|
-
|
|
40
|
+
isValidUser: function (userName, password) {
|
|
49
41
|
if (userName === "user1" && password === "password1") {
|
|
50
42
|
return true;
|
|
51
43
|
}
|
|
@@ -56,15 +48,11 @@ const userManager = {
|
|
|
56
48
|
}
|
|
57
49
|
};
|
|
58
50
|
|
|
59
|
-
|
|
60
51
|
const keySize = argv.keySize;
|
|
61
52
|
const server_certificate_file = constructFilename("certificates/server_selfsigned_cert_" + keySize + ".pem");
|
|
62
53
|
const server_certificate_privatekey_file = constructFilename("certificates/server_key_" + keySize + ".pem");
|
|
63
54
|
|
|
64
|
-
|
|
65
|
-
|
|
66
55
|
const server = new OPCUAServer({
|
|
67
|
-
|
|
68
56
|
alternateHostname: argv.alternateHostname,
|
|
69
57
|
|
|
70
58
|
certificateFile: server_certificate_file,
|
|
@@ -73,11 +61,7 @@ const server = new OPCUAServer({
|
|
|
73
61
|
port,
|
|
74
62
|
resourcePath: "/UA/Server",
|
|
75
63
|
|
|
76
|
-
nodeset_filename: [
|
|
77
|
-
nodesets.standard,
|
|
78
|
-
nodesets.di,
|
|
79
|
-
nodesets.adi
|
|
80
|
-
],
|
|
64
|
+
nodeset_filename: [nodesets.standard, nodesets.di, nodesets.adi],
|
|
81
65
|
|
|
82
66
|
serverInfo: {
|
|
83
67
|
applicationUri: makeApplicationUrn(os.hostname(), "NodeOPCUA-SimpleADIDemoServer"),
|
|
@@ -98,22 +82,17 @@ const server = new OPCUAServer({
|
|
|
98
82
|
}
|
|
99
83
|
},
|
|
100
84
|
maxConnectionsPerEndpoint: 1500,
|
|
101
|
-
|
|
85
|
+
|
|
102
86
|
userManager: userManager,
|
|
103
|
-
registerServerMethod:
|
|
87
|
+
registerServerMethod: RegisterServerMethod.LDS,
|
|
104
88
|
discoveryServerEndpointUrl: argv.discoveryServerEndpointUrl || "opc.tcp://" + hostname() + ":4840"
|
|
105
89
|
});
|
|
106
90
|
|
|
107
91
|
process.title = "Node OPCUA Server on port : " + port;
|
|
108
92
|
|
|
109
|
-
|
|
110
93
|
const hostname = os.hostname();
|
|
111
94
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
server.on("post_initialize", function() {
|
|
115
|
-
|
|
116
|
-
|
|
95
|
+
server.on("post_initialize", function () {
|
|
117
96
|
const addressSpace = server.engine.addressSpace;
|
|
118
97
|
|
|
119
98
|
const namespace = addressSpace.getOwnNamespace();
|
|
@@ -169,7 +148,6 @@ server.on("post_initialize", function() {
|
|
|
169
148
|
typeDefinition: "DataItemType",
|
|
170
149
|
dataType: DataType.Double,
|
|
171
150
|
value: new Variant({ dataType: DataType.Double, value: 10.0 })
|
|
172
|
-
|
|
173
151
|
});
|
|
174
152
|
|
|
175
153
|
return channel;
|
|
@@ -194,32 +172,24 @@ server.on("post_initialize", function() {
|
|
|
194
172
|
browseName: "MyView"
|
|
195
173
|
});
|
|
196
174
|
|
|
197
|
-
const createBoilerType = opcua.createBoilerType;
|
|
198
|
-
const makeBoiler = opcua.makeBoiler;
|
|
199
|
-
|
|
200
175
|
createBoilerType(namespace);
|
|
201
176
|
makeBoiler(addressSpace, {
|
|
202
177
|
browseName: "Boiler#1"
|
|
203
178
|
});
|
|
204
|
-
|
|
205
|
-
|
|
206
179
|
});
|
|
207
180
|
|
|
208
|
-
|
|
209
|
-
|
|
210
181
|
function dumpNode(node) {
|
|
211
182
|
function w(str, width) {
|
|
212
183
|
return str.padEnd(width).substring(0, width);
|
|
213
184
|
}
|
|
214
|
-
return Object.entries(node)
|
|
215
|
-
|
|
216
|
-
|
|
185
|
+
return Object.entries(node)
|
|
186
|
+
.map((key, value) => " " + w(key, 30) + " : " + (value === null ? null : value.toString()))
|
|
187
|
+
.join("\n");
|
|
217
188
|
}
|
|
218
189
|
|
|
219
|
-
|
|
220
190
|
console.log(chalk.yellow(" server PID :"), process.pid);
|
|
221
191
|
|
|
222
|
-
server.start(function(err) {
|
|
192
|
+
server.start(function (err) {
|
|
223
193
|
if (err) {
|
|
224
194
|
console.log(" Server failed to start ... exiting");
|
|
225
195
|
process.exit(-3);
|
|
@@ -239,11 +209,9 @@ server.start(function(err) {
|
|
|
239
209
|
console.log(chalk.yellow("\n server now waiting for connections. CTRL+C to stop"));
|
|
240
210
|
|
|
241
211
|
console.log(server.buildInfo.toString());
|
|
242
|
-
|
|
243
212
|
});
|
|
244
213
|
|
|
245
|
-
server.on("create_session", function(session) {
|
|
246
|
-
|
|
214
|
+
server.on("create_session", function (session) {
|
|
247
215
|
console.log(" SESSION CREATED");
|
|
248
216
|
console.log(chalk.cyan(" client application URI: "), session.clientDescription.applicationUri);
|
|
249
217
|
console.log(chalk.cyan(" client product URI: "), session.clientDescription.productUri);
|
|
@@ -254,21 +222,26 @@ server.on("create_session", function(session) {
|
|
|
254
222
|
console.log(chalk.cyan(" session id: "), session.sessionId);
|
|
255
223
|
});
|
|
256
224
|
|
|
257
|
-
server.on("session_closed", function(session, reason) {
|
|
225
|
+
server.on("session_closed", function (session, reason) {
|
|
258
226
|
console.log(" SESSION CLOSED :", reason);
|
|
259
227
|
console.log(chalk.cyan(" session name: "), session.sessionName ? session.sessionName.toString() : "<null>");
|
|
260
228
|
});
|
|
261
229
|
|
|
262
230
|
function w(s, w) {
|
|
263
|
-
return s.toString().padStart(w,"0");
|
|
231
|
+
return s.toString().padStart(w, "0");
|
|
264
232
|
}
|
|
265
233
|
function t(d) {
|
|
266
234
|
return w(d.getHours(), 2) + ":" + w(d.getMinutes(), 2) + ":" + w(d.getSeconds(), 2) + ":" + w(d.getMilliseconds(), 3);
|
|
267
235
|
}
|
|
268
236
|
|
|
269
|
-
server.on("response", function(response) {
|
|
270
|
-
console.log(
|
|
271
|
-
response.
|
|
237
|
+
server.on("response", function (response) {
|
|
238
|
+
console.log(
|
|
239
|
+
t(response.responseHeader.timestamp),
|
|
240
|
+
response.responseHeader.requestHandle,
|
|
241
|
+
response.schema.name,
|
|
242
|
+
" status = ",
|
|
243
|
+
response.responseHeader.serviceResult.toString()
|
|
244
|
+
);
|
|
272
245
|
switch (response.schema.name) {
|
|
273
246
|
case "ModifySubscriptionResponse":
|
|
274
247
|
case "CreateMonitoredItemsResponse":
|
|
@@ -277,16 +250,25 @@ server.on("response", function(response) {
|
|
|
277
250
|
//xx console.log(response.toString());
|
|
278
251
|
break;
|
|
279
252
|
}
|
|
280
|
-
|
|
281
253
|
});
|
|
282
254
|
|
|
283
255
|
function indent(str, nb) {
|
|
284
256
|
const spacer = " ".slice(0, nb);
|
|
285
|
-
return str
|
|
257
|
+
return str
|
|
258
|
+
.split("\n")
|
|
259
|
+
.map(function (s) {
|
|
260
|
+
return spacer + s;
|
|
261
|
+
})
|
|
262
|
+
.join("\n");
|
|
286
263
|
}
|
|
287
|
-
server.on("request", function(request, channel) {
|
|
288
|
-
console.log(
|
|
289
|
-
request.
|
|
264
|
+
server.on("request", function (request, channel) {
|
|
265
|
+
console.log(
|
|
266
|
+
t(request.requestHeader.timestamp),
|
|
267
|
+
request.requestHeader.requestHandle,
|
|
268
|
+
request.schema.name,
|
|
269
|
+
" ID =",
|
|
270
|
+
channel.channelId.toString()
|
|
271
|
+
);
|
|
290
272
|
switch (request.schema.name) {
|
|
291
273
|
case "ModifySubscriptionRequest":
|
|
292
274
|
case "CreateMonitoredItemsRequest":
|
|
@@ -302,16 +284,14 @@ server.on("request", function(request, channel) {
|
|
|
302
284
|
}
|
|
303
285
|
});
|
|
304
286
|
|
|
305
|
-
process.on("SIGINT", function() {
|
|
287
|
+
process.on("SIGINT", function () {
|
|
306
288
|
// only work on linux apparently
|
|
307
289
|
console.log(chalk.red.bold(" Received server interruption from user "));
|
|
308
290
|
console.log(chalk.red.bold(" shutting down ..."));
|
|
309
|
-
server.shutdown(1000, function() {
|
|
291
|
+
server.shutdown(1000, function () {
|
|
310
292
|
console.log(chalk.red.bold(" shutting down completed "));
|
|
311
293
|
console.log(chalk.red.bold(" done "));
|
|
312
294
|
console.log("");
|
|
313
295
|
process.exit(-1);
|
|
314
296
|
});
|
|
315
297
|
});
|
|
316
|
-
|
|
317
|
-
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-opcua-samples",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.84.0",
|
|
4
4
|
"description": "pure nodejs OPCUA SDK - module -samples",
|
|
5
5
|
"bin": {
|
|
6
6
|
"simple_client": "./dist/simple_client_ts.js",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
"easy-table": "^1.2.0",
|
|
23
23
|
"env-paths": "2.2.1",
|
|
24
24
|
"exit": "^0.1.2",
|
|
25
|
-
"node-opcua": "2.
|
|
26
|
-
"node-opcua-address-space": "2.
|
|
25
|
+
"node-opcua": "2.84.0",
|
|
26
|
+
"node-opcua-address-space": "2.84.0",
|
|
27
27
|
"node-opcua-assert": "2.77.0",
|
|
28
|
-
"node-opcua-client-crawler": "2.
|
|
28
|
+
"node-opcua-client-crawler": "2.84.0",
|
|
29
29
|
"node-opcua-crypto": "^1.12.0",
|
|
30
30
|
"node-opcua-pki": "^2.18.3",
|
|
31
|
-
"node-opcua-server-configuration": "2.
|
|
31
|
+
"node-opcua-server-configuration": "2.84.0",
|
|
32
32
|
"node-opcua-utils": "2.83.0",
|
|
33
33
|
"sprintf-js": "^1.1.2",
|
|
34
34
|
"treeify": "^1.1.0",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"internet of things"
|
|
51
51
|
],
|
|
52
52
|
"homepage": "http://node-opcua.github.io/",
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "47af3803b75cecd9da509053e89c023b981a34de"
|
|
54
54
|
}
|