OPC-UA controller gateway

Allows to communicate with OPC-UA servers.

Setup

Use the template EVA_DIR/share/svc-tpl/svc-tpl-controller-opcua.yml:

# OPC-UA controller gateway service
command: svc/eva-controller-opcua
bus:
  path: var/bus.ipc
config:
  opcua: 
    url: opc.tcp://localhost:4855
    # PKI directory, the default is /opt/eva4/runtime/svc_data/SVCID/pki
    #pki_dir: path/to/dir 
    # uncomment to trust server certs
    #trust_server_certs: true
    # uncomment to trust any server X509 name
    #trust_server_x509: true
    # valid values: None, Aes128Sha256RsaOaep, Basic256Sha256, Aes256Sha256RsaPss, Basic128Rsa15, Basic256
    #security_policy: None
    # valid values: None, Sign, SignAndEncrypt
    #message_security_mode: None
    # automatically create keys if missing
    create_keys: true
    # user/password authentication
    #auth:
      #user: user1
      #password: SECRET
    # x509 authentication, absolute paths or relative to pki_dir
    #auth:
      #cert_file: own/cert.der
      #key_file: private/private.pem
  # panic on critical errors in X seconds after happened (0 - panic immediately)
  panic_in: 0
  # default retry attempts for all operations (0 - no retries, give up if the
  # first attempt fails)
  retries: 1
  # event queue size, pull events ARE DROPPED on overflow. consider ALWAYS
  # having queue size > max possible symbols pulled
  queue_size: 32768
  # ping block must be present if there is no pull block, optional if pull
  # interval is less than timeout. contains any small node to ping
  # periodically, with interval = timeout/2
  #ping:
  #  node: ns=2;s=varbool
  # ttl cache for pull events (sec, skip non-modified)
  pull_cache_sec: 3600
  # PLC pull interval, in seconds
  pull_interval: 1
  # pull nodes and parse maps
  #
  #pull:
     #pull an array
    #- node: ns=2;g=c8a2e6f8-accf-4442-a8d0-7dbf3e384b81
      # an optional array range
      #range: "1:5"
      #map:
        #- idx: 0 # payload index, starting from zero (from pulled)
        #  oid: sensor:tests/test0
        #- idx: 4
          #oid: sensor:tests/test1
          #value_delta: 0.5 # report event only if the new value difference is >=
          #transform:
            #- func: multiply # multiply the value by N
              #params: [ 1000 ]
            #- func: divide # divide the value by N
              #params: [ 1000 ]
            #- func: round # round the value to N digits after comma
              #params: [ 2 ]
            #- func: calc_speed # use the value as calc-speed gauge (with N seconds delta)
              #params: [ 1 ]
            #- func: invert # invert the value between 0/1
            # #params: []
    # pull a node value
    #- node: ns=2;s=varf64
      #map:
         #- oid: sensor:tests/test2
    # pull a node value
    #- node: ns=2;s=varf64
      #map:
         #- oid: sensor:tests/test2
  # action queue size, per item, actions on overflow are not dropped but wait
  # their attempt to enter the queue. The core marks an action as failed if it
  # does not enter the queue for <action timeout> seconds
  action_queue_size: 32
  # OID map for actions
  #action_map:
    #unit:tests/u1:
      #node: ns=2;s=varf64
      # allowed types: real (REAL), real32, real64 (LREAL), uint8 (USINT),
      # int8, sint8 (SINT), byte, uint16 (UINT), word, uint32 (UDINT), dword,
      # sint16 (INT), int16, sint32 (DINT), int32, sint64
      # (LINT), int64, uint64 (ULINT), qword, boolean (BOOLEAN)
      #type: LREAL
      # an optional array range
      #range: "1:5"
      # an optional array dimensions
      #dimensions: [2,2]
user: nobody
react_to_fail: true

Create the service using eva-shell:

eva svc create eva.controller.opcua1 /opt/eva4/share/svc-tpl/svc-tpl-controller-opcua.yml

or using the bus CLI client:

cd /opt/eva4
cat DEPLOY.yml | ./bin/yml2mp | \
    ./sbin/bus ./var/bus.ipc rpc call eva.core svc.deploy -

(see eva.core::svc.deploy for more info)

EAPI methods

See EAPI commons for the common information about the bus, types, errors and RPC calls.

action

Description

Executes a mapped unit action

Parameters

See Unit actions

Returns

See Unit actions

kill

Description

Attempts to terinate/cancel all actions for a unit

Parameters

See Unit actions

Returns

See Unit actions

terminate

Description

Attempts to terminate/cancel a unit action

Parameters

See Unit actions

Returns

See Unit actions

var.get

Description

Get node value from OPC-UA

Parameters

required

Returns

Node value, single or list

Parameters

Name

Type

Description

Required

i

String

node id

yes

range

String

array range

no

timeout

f64

Max operation timeout

no

retries

u8

Retry attempts

no

var.set

Description

Set node value on OPC-UA

Parameters

required

Returns

nothing

Parameters

Name

Type

Description

Required

i

String

node id

yes

value

Any

value to set

yes

type

String

Data type (e.g. DINT)

yes

range

String

array range

no

dimensions

Vec<u32>

array dimensions

no

timeout

f64

Max operation timeout

no

retries

u8

Retry attempts

no

var.set_bulk

Description

Set symbols on OPC-UA in bulk

Parameters

required

Returns

Operation status: failed-to-set node list or an empty dict

Parameters

Name

Type

Description

Required

i

Vec<String>

node ids

yes

values

Vec<Any>

values to set

yes

types

Vec<String>

Data types (e.g. DINT)

yes

ranges

Vec<Option<String>>

array ranges

no

dimensions

Vec<Option<u32>>

array dimensions

no

timeout

f64

Max operation timeout

no

retries

u8

Retry attempts

no

Return payload example:

{
  "failed": [ "ns=2;s=vari32" ]
}