How to use node-opcua - 10 common examples

To help you get started, we’ve selected a few node-opcua examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-opcua / node-opcua / packages / node-opcua-end2end-test / test_helpers / bin / simple_server_that_terminate_session_too_early.js View on Github external
// Add a mechanism to dismiss session early
    const obj = namespace.addObject({ 
        nodeId: "ns=1;s=MyObject",
        browseName: "MyObject" ,
        organizedBy: myDevices,
    });

    const simulateNetworkOutage = namespace.addMethod(obj, {
        browseName: "SimulateNetworkOutage",
        executable: true,
        inputArguments: [
            {
                name: "outageDuration",
                description: {text: "specifies the number of miliseconds the Outage should be"},
                dataType: opcua.DataType.UInt32
            }
        ],
        nodeId: "ns=1;s=SimulateNetworkOutage",
        outputArguments: [],
        userExecutable: true,
    });

    async function simulateNetworkOutageFunc(
        /*this: UAMethod,*/ inputArguments/*: Variant[]*/, context/*: SessionContext*/, callback/*: MethodFunctorCallback*/
    ){
        const outageDuration = inputArguments[0].value;
        console.log("Simulating Server Outage for ", outageDuration, "ms");
        await server.suspendEndPoints();
        setTimeout(async () => {
            await server.resumeEndPoints();
            console.log("Server Outage is now resolved ");
github node-opcua / node-opcua / packages / playground / test_server.ts View on Github external
async function main() {
    try {

        const server = new OPCUAServer({
            registerServerMethod: RegisterServerMethod.LDS
        });

        await server.initialize();

        server.on("request", (request: Request) => {

            console.log(request.constructor.name, request.requestHeader.requestHandle);

            // you can either check the instance of the request object directl
            if (request instanceof BrowseRequest) {
                console.log("BrowseRequest.requestedMaxReferencesPerNode=", request.requestedMaxReferencesPerNode);
            } else if (request instanceof ActivateSessionRequest) {
                console.log(request.toString());
            }
github node-opcua / node-opcua / packages / playground / test_server_with_method.ts View on Github external
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();
github node-opcua / node-opcua / packages / node-opcua-end2end-test / test_helpers / build_server_with_temperature_device.js View on Github external
function build_server_with_temperature_device(options, done) {

    assert(_.isFunction(done, "expecting a callback function"));
    assert(typeof opcua.nodesets.standard_nodeset_file === "string");

    //xx console.log("xxx building server with temperature device");

    // use mini_nodeset_filename for speed up if not otherwise specified
    options.nodeset_filename = options.nodeset_filename ||
        [
            opcua.nodesets.standard_nodeset_file
        ];

    options.userManager = userManager;

    const server = new OPCUAServer(options);
    // we will connect to first server end point

    server.on("session_closed", function (session, reason) {
        //xx console.log(" server_with_temperature_device has closed a session :",reason);
        //xx console.log(chalk.cyan("              session name: "),session.sessionName.toString());
    });

    server.on("post_initialize", function () {

        const addressSpace = server.engine.addressSpace;
github node-opcua / node-opcua / packages / node-opcua-end2end-test / test_helpers / build_server_with_temperature_device.js View on Github external
function build_server_with_temperature_device(options, done) {

    assert(_.isFunction(done, "expecting a callback function"));
    assert(typeof opcua.nodesets.standard_nodeset_file === "string");

    //xx console.log("xxx building server with temperature device");

    // use mini_nodeset_filename for speed up if not otherwise specified
    options.nodeset_filename = options.nodeset_filename ||
        [
            opcua.nodesets.standard_nodeset_file
        ];

    options.userManager = userManager;

    const server = new OPCUAServer(options);
    // we will connect to first server end point

    server.on("session_closed", function (session, reason) {
        //xx console.log(" server_with_temperature_device has closed a session :",reason);
github node-opcua / node-opcua / packages / node-opcua-end2end-test / test_helpers / bin / simple_server_with_no_transferSubscription.js View on Github external
server._on_TransferSubscriptionsRequest =(message /* :Message*/, channel/*: ServerSecureChannelLayer*/) => {
        const response = new opcua.TransferSubscriptionsResponse({
            responseHeader: { serviceResult: opcua.StatusCodes.BadNotImplemented }
        });
        return channel.send_response("MSG", response, message);
    }
github node-opcua / node-opcua / packages / node-opcua-end2end-test / test_helpers / bin / simple_server_with_no_transferSubscription.js View on Github external
server.on("post_initialize", function () {

    const addressSpace = server.engine.addressSpace;

    const rootFolder = addressSpace.findNode("RootFolder");

    const namespace = addressSpace.getOwnNamespace();

    const myDevices = namespace.addFolder(rootFolder.objects, {browseName: "MyDevices"});

    const variable0 = namespace.addVariable({
        organizedBy: myDevices,
        browseName: "Counter",
        nodeId: "ns=1;s=MyCounter",
        dataType: "Int32",
        value: new opcua.Variant({dataType: opcua.DataType.Int32, value: 1000.0})
    });

    server._on_TransferSubscriptionsRequest =(message /* :Message*/, channel/*: ServerSecureChannelLayer*/) => {
        const response = new opcua.TransferSubscriptionsResponse({
            responseHeader: { serviceResult: opcua.StatusCodes.BadNotImplemented }
        });
        return channel.send_response("MSG", response, message);
    }

});
github node-opcua / node-opcua / packages / node-opcua-end2end-test / test_helpers / bin / simple_server_that_terminate_session_too_early.js View on Github external
server.on("post_initialize", function () {

    const addressSpace = server.engine.addressSpace;

    const rootFolder = addressSpace.findNode("RootFolder");

    const namespace = addressSpace.getOwnNamespace();

    const myDevices = namespace.addFolder(rootFolder.objects, {browseName: "MyDevices"});

    const variable0 = namespace.addVariable({
        organizedBy: myDevices,
        browseName: "Counter",
        nodeId: "ns=1;s=MyCounter",
        dataType: "Int32",
        value: new opcua.Variant({dataType: opcua.DataType.Int32, value: 1000.0})
    });

    // Add a mechanism to dismiss session early
    const obj = namespace.addObject({ 
        nodeId: "ns=1;s=MyObject",
        browseName: "MyObject" ,
        organizedBy: myDevices,
    });

    const simulateNetworkOutage = namespace.addMethod(obj, {
        browseName: "SimulateNetworkOutage",
        executable: true,
        inputArguments: [
            {
                name: "outageDuration",
                description: {text: "specifies the number of miliseconds the Outage should be"},
github node-opcua / node-opcua / packages / node-opcua-end2end-test / test_helpers / build_server_with_temperature_device.js View on Github external
//xx    assert(parentNode instanceof opcua.BaseNode);

    const addressSpace = parentNode.addressSpace;
    const namespace = addressSpace.getOwnNamespace();

    // add a UAAnalogItem
    namespace.addAnalogDataItem({
        componentOf: parentNode,
        nodeId: "s=TemperatureAnalogItem",
        browseName: "TemperatureAnalogItem",
        definition: "(tempA -25) + tempB",
        valuePrecision: 0.5,
        engineeringUnitsRange: {low: 100, high: 200},
        instrumentRange: {low: -100, high: +200},
        engineeringUnits: opcua.standardUnits.degree_celsius,
        dataType: "Double",
        value: {
            get: function () {
                return new Variant({dataType: DataType.Double, value: Math.random() + 19.0});
            }
        }
    });

}
github node-opcua / node-opcua-htmlpanel / app.js View on Github external
});
    
        app.use(express.static(__dirname + '/'));
    
        const io =socketIO.listen(app.listen(port));
    
        io.sockets.on('connection', function (socket) {
        });
    
        console.log("Listening on port " + port);
        console.log("visit http://localhost:" + port);
        // --------------------------------------------------------
    
        const itemToMonitor = {
            nodeId: nodeIdToMonitor,
            attributeId: AttributeIds.Value
        };
        const parameters = {
            samplingInterval: 100,
            discardOldest: true,
            queueSize: 100
        };
        const monitoredItem = await subscription.monitor(itemToMonitor, parameters, TimestampsToReturn.Both);

        monitoredItem.on("changed", (dataValue) => {
            console.log(dataValue.value.toString());
            io.sockets.emit('message', {
                value: dataValue.value.value,
                timestamp: dataValue.serverTimestamp,
                nodeId: nodeIdToMonitor,
                browseName: "Temperature"
            });