Skip to content

an implementation of a OPC UA stack fully written in javascript and nodejs

License

Notifications You must be signed in to change notification settings

johnyesberg/node-opcua

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-opcua

an implementation of a OPC UA stack fully written in javascript and nodejs

NPM version Build Status Dependency Status Coverage Status Code Climate

OPC UA

node-opcua is an experimental OPC-UA stack written in NodeJS.

Why NodeJS ?

Because nodeJs is a great framework to design asynchronous application.

Getting started

installing node-opcua

$ npm install node-opcua

first example

install pre-requisite:

$ npm install async node-opcua

create a file myfirstclient.js and add the following code :

var opcua = require("node-opcua");
var async = require("async");

var client = new opcua.OPCUAClient();

var endpointUrl = "opc.tcp://" + require("os").hostname() + ":4841";

var the_session = null;
async.series([


    // step 1 : connect to
    function(callback)  {
      client.connect(endpointUrl,function (err) {
         if(err) {
           console.log(" cannot connect to endpoint :" , endpointUrl );
         } else {
          console.log("connected !");
         }
         callback(err);
      });
   },


   // step 2 : createSession
   function(callback) {
     client.createSession( function(err,session) {
         if(!err) {
           the_session = session;
         }
         callback(err);
     });

   },


   // step 3 : browse
   function(callback) {

     the_session.browse("RootFolder", function(err,browse_result,diagnostics){
        if(!err) {
          browse_result[0].references.forEach(function(reference) {
            console.log( reference.browseName);
          });
        }
        callback(err);
     });
   },


   // step 4 : read a variable
   function(callback) {
     the_session.readVariableValue("ns=2;s=Furnace_1.Temperature", function(err,dataValues,diagnostics) {
       if (!err) {
         console.log(" temperature = " , dataValues[0].value.value);
       }
       callback(err);
     })
   },


], function(err) {
  if (err) {
    console.log(" failure ",err);
  } else {
    console.log("done!")
  }
  // disconnect regardless
  client.disconnect(function(){});
}) ;

now run it

$ node myfirstclient.js

Contributing

$ git clone git://github.com/erossignon/node-opcua.git node-opcua
$ cd node-opcua
$ npm install
$ npm test

Flattr this git repo

NPM

Project Stats

Bitdeli Badge

About

an implementation of a OPC UA stack fully written in javascript and nodejs

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%