opcua
opcua
npm i opcua
opcua

opcua

TypeScript / JavaScript OPC UA client for the browser

by HBM

1.0.0 (see all)License:MITTypeScript:Not Found
npm i opcua
Readme

opcua

TypeScript / JavaScript OPC UA client for the browser.

github actions seriesci coverage

... work in progress ...

Features

Usage

npm i opcua
import Client from 'opcua'

const client = new Client()

// wait for an active session
client.addEventListener('session:activate', async event => {

  // browse the root folder
  const req = new BrowseRequest({
    NodesToBrowse: [
      new BrowseDescription({
        NodeId: NewTwoByteNodeId(IdRootFolder)
      })
    ]
  })

  // all requests use async / await
  const res = await client.browse(req)
  console.log(res)
})

Development

The source code is written in TypeScript. We use the TypeScript compiler to create the JavaScript files for the browser.

Some source code files are autogenerated.

  • src/ua/generated.ts by cmd/service/main.go
  • src/id/id.ts by cmd/id/main.go

Do not edit them by hand. You need Go on your machine to execute those generators. The schema definition files are located at ./schema.

We rely on reflection and decorators to get types (e.g. uint32, CreateSessionRequest or arrays of certain types string[]) during runtime. In JavaScript a number is always double-precision 64-bit. OPC UA has much more number types like int8, uint8, int16, uint16 and so on. In order to get the binary encoding / decoding right we must know exactly how many bits represent a number.

The client architecture consists of multiple layers. They closely follow the official OPC UA specification. Read the following diagram from bottom to top. On the right side you find the responsibilities for each layer.

layers

The OPC UA handshake is quite complex and several steps are necessary to get an active session. Those steps are

  1. Hello / Acknowledge
  2. Open Secure Channel
  3. Create Session
  4. Activate Session

The following diagram shows this sequence and highlights response parameters that the client has to store internally (e.g. channel id, token id, authentication token, sequence number, request id).

handshake

You need an OPC UA server implementation that supports WebSockets to test the client. Two options exist:

  1. Use open62541 with WebSockets enabled
  2. Use websockify for servers that do not support WebSockets (that only support TCP connections)

Downloads/wk

21

GitHub Stars

28

LAST COMMIT

1yr ago

MAINTAINERS

1

CONTRIBUTORS

2

OPEN ISSUES

1

OPEN PRs

25
VersionTagPublished
1.0.0
latest
3yrs ago
No alternatives found
No tutorials found
Add a tutorial

Rate & Review

100
No reviews found
Be the first to rate