const endpointUrl = "opc.tcp://192.168.249.31:4840"; const opcua = require("node-opcua"); const StatusCodes = opcua.StatusCodes; const AttributeIds = opcua.AttributeIds; const DataTypes = opcua.DataType; let client; let session; async function CreateConnection(){ const OPCUAClient = opcua.OPCUAClient; console.log('Trying to connect ...'); client = new OPCUAClient({}); await client.connect(endpointUrl); console.log('Connected!'); session = await client.createSession({userName: "Davide", password: "davide"}); let val = await session.read({nodeId: "ns=4;s=opctest1_Copy1"}) console.log(val.value.value); let nodeToWrite = { nodeId: "ns=4;s=opctest1_Copy1", attributeIds: opcua.AttributeIds.Value, value: { value: { dataType: opcua.DataType.UInt16, value: 1098 } }, statusCode: opcua.StatusCodes.Good // <==== } let risultato = await session.write(nodeToWrite); console.log(risultato); val = await session.read({nodeId: "ns=4;s=opctest1_Copy1"}) console.log(val.value.value) await client.closeSession(session,true); await client.disconnect(); }; CreateConnection();