opcua_plugin

package
v2.0.0-...-d4eaa7e Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const SESSION_TIMEOUT = 5 * time.Second

Variables

View Source
var OPCUAConfigSpec = service.NewConfigSpec().
	Summary("Creates an input that reads data from OPC-UA servers. Created & maintained by the United Manufacturing Hub. About us: www.umh.app").
	Field(service.NewStringField("endpoint").Description("Address of the OPC-UA server to connect with.")).
	Field(service.NewStringField("username").Description("Username for server access. If not set, no username is used.").Default("")).
	Field(service.NewStringField("password").Description("Password for server access. If not set, no password is used.").Default("")).
	Field(service.NewStringField("sessionTimeout").Description("The duration in milliseconds that a OPC UA session will last. Is used to ensure that older failed sessions will timeout and that we will not get a TooManySession error.").Default(10000)).
	Field(service.NewStringListField("nodeIDs").Description("List of OPC-UA node IDs to begin browsing.")).
	Field(service.NewStringField("securityMode").Description("Security mode to use. If not set, a reasonable security mode will be set depending on the discovered endpoints.").Default("")).
	Field(service.NewStringField("securityPolicy").Description("The security policy to use.  If not set, a reasonable security policy will be set depending on the discovered endpoints.").Default("")).
	Field(service.NewBoolField("insecure").Description("Set to true to bypass secure connections, useful in case of SSL or certificate issues. Default is secure (false).").Default(false)).
	Field(service.NewBoolField("subscribeEnabled").Description("Set to true to subscribe to OPC-UA nodes instead of fetching them every seconds. Default is pulling messages every second (false).").Default(false))

Functions

func GenerateCert

func GenerateCert(host string, rsaBits int, validFor time.Duration) (certPEM, keyPEM []byte, err error)

func ParseNodeIDs

func ParseNodeIDs(incomingNodes []string) []*ua.NodeID

func UpdateNodePaths

func UpdateNodePaths(nodes []NodeDef)

UpdateNodePaths updates the node paths to use the nodeID instead of the browseName if the browseName is not unique

Types

type NodeDef

type NodeDef struct {
	NodeID       *ua.NodeID
	NodeClass    ua.NodeClass
	BrowseName   string
	Description  string
	AccessLevel  ua.AccessLevelType
	ParentNodeID string
	Path         string
	DataType     string
	Writable     bool
	Unit         string
	Scale        string
	Min          string
	Max          string
}

func (NodeDef) Records

func (n NodeDef) Records() []string

type OPCUAInput

type OPCUAInput struct {
	Endpoint       string
	Username       string
	Password       string
	NodeIDs        []*ua.NodeID
	NodeList       []NodeDef
	SecurityMode   string
	SecurityPolicy string
	Insecure       bool
	Client         *opcua.Client
	Log            *service.Logger
	// this is required for subscription
	SubscribeEnabled bool
	SubNotifyChan    chan *opcua.PublishNotificationData
	SessionTimeout   int
}

func (*OPCUAInput) BrowseAndSubscribeIfNeeded

func (g *OPCUAInput) BrowseAndSubscribeIfNeeded(ctx context.Context) error

func (*OPCUAInput) Close

func (g *OPCUAInput) Close(ctx context.Context) error

func (*OPCUAInput) Connect

func (g *OPCUAInput) Connect(ctx context.Context) error

Connect connects to the OPC UA server Because there are a lot of methods, security policies, potential endpoints, etc., this function is using the following behaviour If the user selected a very concrete endpoint, security policy, and security mode, it will try to connect to this endpoint. Otherwise, it will iterate until it finds a working combination At the end, it will output the recommended connection details ala "We have iterated various combinations, and found this one here working. To speed it up, please speicfy in your configuration"

func (*OPCUAInput) FetchAllEndpoints

func (g *OPCUAInput) FetchAllEndpoints(ctx context.Context) ([]*ua.EndpointDescription, error)

FetchAllEndpoints retrieves all possible endpoints from an OPC UA server, handling cases where only a Discovery URL is provided and substituting server endpoints with user-specified ones if necessary. This is important for addressing issues with servers that return only their DNS name.

func (*OPCUAInput) GetOPCUAClientOptions

func (g *OPCUAInput) GetOPCUAClientOptions(selectedEndpoint *ua.EndpointDescription, selectedAuthentication ua.UserTokenType) (opts []opcua.Option, err error)

func (*OPCUAInput) LogEndpoints

func (g *OPCUAInput) LogEndpoints(endpoints []*ua.EndpointDescription)

func (*OPCUAInput) ReadBatch

func (*OPCUAInput) ReadBatchPull

func (g *OPCUAInput) ReadBatchPull(ctx context.Context) (service.MessageBatch, service.AckFunc, error)

func (*OPCUAInput) ReadBatchSubscribe

func (g *OPCUAInput) ReadBatchSubscribe(ctx context.Context) (service.MessageBatch, service.AckFunc, error)

func (*OPCUAInput) ReplaceHostInEndpointURL

func (g *OPCUAInput) ReplaceHostInEndpointURL(endpointURL, newHost string) (string, error)

replaceHostInEndpointURL constructs a new endpoint URL by replacing the existing host with a new host, preserving the original path and query parameters.

func (*OPCUAInput) ReplaceHostInEndpoints

func (g *OPCUAInput) ReplaceHostInEndpoints(endpoints []*ua.EndpointDescription, newHost string) ([]*ua.EndpointDescription, error)

ReplaceHostInEndpoints updates each endpoint's URL to use a specified host, aiming to mitigate potential connectivity issues due to DNS name discrepancies.

Jump to

Keyboard shortcuts

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