opcua

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

README

OPC-UA Adapter

Adapter between Mainflux IoT system and an OPC-UA Server.

This adapter sits between Mainflux and an OPC-UA server and just forwards the messages from one system to another.

OPC-UA Server is used for connectivity layer and the data is pushed via this adapter service to Mainflux, where it is persisted and routed to other protocols via Mainflux multi-protocol message broker. Mainflux adds user accounts, application management and security in order to obtain the overall end-to-end OPC-UA solution.

Configuration

The service is configured using the environment variables presented in the following table. Note that any unset variables will be replaced with their default values.

Variable Description Default
MF_OPCUA_ADAPTER_HTTP_PORT Service HTTP port 8180
MF_OPCUA_ADAPTER_LOG_LEVEL Service Log level error
MF_NATS_URL NATS instance URL nats://localhost:4222
MF_OPCUA_ADAPTER_INTERVAL_MS OPC-UA Server Interval in milliseconds 1000
MF_OPCUA_ADAPTER_POLICY OPC-UA Server Policy
MF_OPCUA_ADAPTER_MODE OPC-UA Server Mode
MF_OPCUA_ADAPTER_CERT_FILE OPC-UA Server Certificate file
MF_OPCUA_ADAPTER_KEY_FILE OPC-UA Server Key file
MF_OPCUA_ADAPTER_ROUTE_MAP_URL Route-map database URL localhost:6379
MF_OPCUA_ADAPTER_ROUTE_MAP_PASS Route-map database password
MF_OPCUA_ADAPTER_ROUTE_MAP_DB Route-map instance name 0
MF_THINGS_ES_URL Things service event source URL localhost:6379
MF_THINGS_ES_PASS Things service event source password
MF_THINGS_ES_DB Things service event source DB 0
MF_OPCUA_ADAPTER_EVENT_CONSUMER Service event consumer name opcua

Deployment

The service is distributed as Docker container. The following snippet provides a compose file template that can be used to deploy the service container locally:

version: "2"
services:
  adapter:
    image: mainflux/opcua:[version]
    container_name: [instance name]
    environment:
      MF_OPCUA_ADAPTER_HTTP_PORT: [Service HTTP port]
      MF_OPCUA_ADAPTER_LOG_LEVEL: [Service Log Level]
      MF_NATS_URL: [NATS instance URL]
      MF_OPCUA_ADAPTER_INTERVAL_MS: [OPC-UA Server Interval (milliseconds)]
      MF_OPCUA_ADAPTER_POLICY: [OPC-UA Server Policy]
      MF_OPCUA_ADAPTER_MODE: [OPC-UA Server Mode]
      MF_OPCUA_ADAPTER_CERT_FILE: [OPC-UA Server Certificate file]
      MF_OPCUA_ADAPTER_KEY_FILE: [OPC-UA Server Key file]
      MF_OPCUA_ADAPTER_ROUTE_MAP_URL: [Route-map database URL]
      MF_OPCUA_ADAPTER_ROUTE_MAP_PASS: [Route-map database password]
      MF_OPCUA_ADAPTER_ROUTE_MAP_DB: [Route-map instance name]
      MF_THINGS_ES_URL: [Things event source URL]
      MF_THINGS_ES_PASS: [Things event source password]
      MF_THINGS_ES_DB: [Things event source DB instance]
      MF_OPCUA_ADAPTER_EVENT_CONSUMER: [Service event consumer name]

To start the service outside of the container, execute the following shell script:

# download the latest version of the service
git clone https://gitee.com/shtemmi/iotflux

cd mainflux

# compile the opcua-adapter
make opcua

# copy binary to bin
make install

# set the environment variables and run the service
MF_OPCUA_ADAPTER_HTTP_PORT=[Service HTTP port] \
MF_OPCUA_ADAPTER_LOG_LEVEL=[OPC-UA Adapter Log Level] \
MF_NATS_URL=[NATS instance URL] \
MF_OPCUA_ADAPTER_INTERVAL_MS: [OPC-UA Server Interval (milliseconds)] \
MF_OPCUA_ADAPTER_POLICY=[OPC-UA Server Policy] \
MF_OPCUA_ADAPTER_MODE=[OPC-UA Server Mode] \
MF_OPCUA_ADAPTER_CERT_FILE=[OPC-UA Server Certificate file] \
MF_OPCUA_ADAPTER_KEY_FILE=[OPC-UA Server Key file] \
MF_OPCUA_ADAPTER_ROUTE_MAP_URL=[Route-map database URL] \
MF_OPCUA_ADAPTER_ROUTE_MAP_PASS=[Route-map database password] \
MF_OPCUA_ADAPTER_ROUTE_MAP_DB=[Route-map instance name] \
MF_THINGS_ES_URL=[Things service event source URL] \
MF_THINGS_ES_PASS=[Things service event source password] \
MF_THINGS_ES_DB=[Things service event source password] \
MF_OPCUA_ADAPTER_EVENT_CONSUMER=[OPC-UA adapter instance name] \
$GOBIN/mainflux-opcua
Using docker-compose

This service can be deployed using docker containers. Docker compose file is available in <project_root>/docker/addons/opcua-adapter/docker-compose.yml. In order to run Mainflux opcua-adapter, execute the following command:

docker-compose -f docker/addons/opcua-adapter/docker-compose.yml up -d

Usage

For more information about service capabilities and its usage, please check out the Mainflux documentation.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMalformedEntity indicates malformed entity specification.
	ErrMalformedEntity = errors.New("malformed entity specification")
)

Functions

This section is empty.

Types

type BrowsedNode

type BrowsedNode struct {
	NodeID      string
	DataType    string
	Description string
	Unit        string
	Scale       string
	BrowseName  string
}

BrowsedNode represents the details of a browsed OPC-UA node.

type Browser

type Browser interface {
	// Browse availlable Nodes for a given URI.
	Browse(string, string) ([]BrowsedNode, error)
}

Browser represents the OPC-UA Server Nodes browser.

type Config

type Config struct {
	ServerURI string
	NodeID    string
	Interval  string
	Policy    string
	Mode      string
	CertFile  string
	KeyFile   string
}

Config OPC-UA Server

type EventStore

type EventStore interface {
	// Subscribes to a given subject and receives events.
	Subscribe(string) error
}

EventStore represents event source for things and channels provisioning.

type RouteMapRepository

type RouteMapRepository interface {
	// Save stores/routes pair OPC-UA Server & Mainflux.
	Save(string, string) error

	// Get returns the stored Mainflux route-map for a given OPC-UA pair.
	Get(string) (string, error)

	// Remove Remove route-map from cache.
	Remove(string) error
}

RouteMapRepository store route-map between the OPC-UA Server and Mainflux

type Service

type Service interface {
	// CreateThing creates thingID:OPC-UA-nodeID route-map
	CreateThing(thingID, nodeID string) error

	// UpdateThing updates thingID:OPC-UA-nodeID route-map
	UpdateThing(thingID, nodeID string) error

	// RemoveThing removes thingID:OPC-UA-nodeID route-map
	RemoveThing(thingID string) error

	// CreateChannel creates channelID:OPC-UA-serverURI route-map
	CreateChannel(chanID, serverURI string) error

	// UpdateChannel updates channelID:OPC-UA-serverURI route-map
	UpdateChannel(chanID, serverURI string) error

	// RemoveChannel removes channelID:OPC-UA-serverURI route-map
	RemoveChannel(chanID string) error

	// ConnectThing creates thingID:channelID route-map
	ConnectThing(chanID, thingID string) error

	// DisconnectThing removes thingID:channelID route-map
	DisconnectThing(chanID, thingID string) error

	// Browse browses available nodes for a given OPC-UA Server URI and NodeID
	Browse(serverURI, namespace, identifier string) ([]BrowsedNode, error)
}

Service specifies an API that must be fullfiled by the domain service implementation, and all of its decorators (e.g. logging & metrics).

func New

func New(sub Subscriber, brow Browser, thingsRM, channelsRM, connectRM RouteMapRepository, cfg Config, log logger.Logger) Service

New instantiates the OPC-UA adapter implementation.

type Subscriber

type Subscriber interface {
	// Subscribes to given NodeID and receives events.
	Subscribe(Config) error
}

Subscriber represents the OPC-UA Server client.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL