I am trying to build an opcua client using the node-opcua library and I am testing it by trying to get it to connect to the Prosys OPC UA Simulation Server. I used the basic client example to attempt a connection but it doesn't seem to work and I can't make sense of the error message.
The code:-
import {
OPCUAClient,
MessageSecurityMode,
SecurityPolicy,
AttributeIds,
makeBrowsePath,
ClientSubscription,
TimestampsToReturn,
MonitoringParametersOptions,
ReadValueIdOptions,
ClientMonitoredItem,
DataValue,
} from "node-opcua";
const connectionStrategy = {
initialDelay: 1000,
maxRetry: 1
};
const client = OPCUAClient.create({
applicationName: "MyClient",
connectionStrategy: connectionStrategy,
securityMode: MessageSecurityMode.None,
securityPolicy: SecurityPolicy.None,
endpointMustExist: false
});
const endpointUrl = "opc.tcp://localhost:53530/OPCUA/SimulationServer"
async function main() {
try {
console.log("attempting to connect...");
// 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
// step 4 : read a variable with readVariableValue
// step 4' : read a variable with read
// step 5: install a subscription and install a monitored item for 10 seconds
// step 6: finding the nodeId of a node by Browse name
// close session
// disconnecting
} catch (err) {
console.log("An error has occurred : ", err);
}
}
main();
The error message:-
attempting to connect...
An error has occurred : AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
(0, assert_1.default)(s.length <= maxLength)
at parseBitString (C:\Users\binahmad\Documents\SWE\code\1 - Projects\20230717_opcua_Interface_testing_tool\sample-node-opcua-client\node_modules\node-opcua-crypto\source\asn1.ts:91:15)
at _readBitString (C:\Users\binahmad\Documents\SWE\code\1 - Projects\20230717_opcua_Interface_testing_tool\sample-node-opcua-client\node_modules\node-opcua-crypto\source\asn1.ts:113:16)
at _readSubjectPublicKeyInfo (C:\Users\binahmad\Documents\SWE\code\1 - Projects\20230717_opcua_Interface_testing_tool\sample-node-opcua-client\node_modules\node-opcua-crypto\source\crypto_explore_certificate.ts:552:44)
at readTbsCertificate (C:\Users\binahmad\Documents\SWE\code\1 - Projects\20230717_opcua_Interface_testing_tool\sample-node-opcua-client\node_modules\node-opcua-crypto\source\crypto_explore_certificate.ts:665:40)
at exploreCertificate (C:\Users\binahmad\Documents\SWE\code\1 - Projects\20230717_opcua_Interface_testing_tool\sample-node-opcua-client\node_modules\node-opcua-crypto\source\crypto_explore_certificate.ts:714:29)
at publicKeyAndPrivateKeyMatches (C:\Users\binahmad\Documents\SWE\code\1 - Projects\20230717_opcua_Interface_testing_tool\sample-node-opcua-client\node_modules\node-opcua-crypto\source\public_private_match.ts:30:33)
at C:\Users\binahmad\Documents\SWE\code\1 - Projects\20230717_opcua_Interface_testing_tool\sample-node-opcua-client\node_modules\node-opcua-client\source\verify.ts:131:39
at Generator.next (<anonymous>)
at C:\Users\binahmad\Documents\SWE\code\1 - Projects\20230717_opcua_Interface_testing_tool\sample-node-opcua-client\node_modules\node-opcua-client\dist\verify.js:8:71
at new Promise (<anonymous>) {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: false,
expected: true,
operator: '=='
}
I feel like it should be working but something might be wrong with my system or my node instead of the code.
I tried connecting to the server with UaExpert and that worked, I also tried connecting with a python script and it worked. Its just node that seems affected.
Node version: v16.15.0
node-opcua version: ^2.108.0
If anyone could help me figure out how to simply connect, that would be very helpful