Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* fix: initial

* fix: readme and metaSet

* fix: error
  • Loading branch information
JeremyTheocharis authored Aug 12, 2024
1 parent cb9449c commit a8dc4a8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,19 @@ In benthos-umh, we design security and authentication to be as robust as possibl

The plugin provides metadata for each message, that can be used to create a topic for the output, as shown in the example above. The metadata can also be used to create a unique identifier for each message, which is useful for deduplication.

| Metadata | Description |
|-------------------|-----------------------------------------------------------------------------------------|
| `opcua_tag_name` | The sanitized ID of the Node that sent the message. This is always unique between nodes |
| `opcua_tag_group` | A dot-separated path to the tag, created by joining the BrowseNames. |
| Metadata | Description |
|--------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|
| `opcua_tag_name` | The sanitized ID of the Node that sent the message. This is always unique between nodes |
| `opcua_tag_group` | A dot-separated path to the tag, created by joining the BrowseNames. |
| `opcua_tag_type` | The data type of the node optimized for benthos, which can be either a number, string or bool. For the original one, check out `opcua_attr_datatype` |
| `opcua_source_timestamp` | The SourceTimestamp of the OPC UA node |
| `opcua_server_timestamp` | The ServerTimestamp of the OPC UA node |
| `opcua_attr_nodeid` | The NodeID attribute of the Node as a string |
| `opcua_attr_nodeclass` | The NodeClass attribute of the Node as a string |
| `opcua_attr_browsename` | The BrowseName attribute of the Node as a string |
| `opcua_attr_description` | The Description attribute of the Node as a string |
| `opcua_attr_accesslevel` | The AccessLevel attribute of the Node as a string |
| `opcua_attr_datatype` | The DataType attribute of the Node as a string |

Taking as example the following OPC-UA structure:

Expand Down
23 changes: 11 additions & 12 deletions opcua_plugin/opcua.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,9 @@ type NodeDef struct {
BrowseName string
Description string
AccessLevel ua.AccessLevelType
ParentNodeID string
Path string
DataType string
Writable bool
Unit string
Scale string
Min string
Max string
}

func (n NodeDef) Records() []string {
return []string{n.BrowseName, n.DataType, n.NodeID.String(), n.Unit, n.Scale, n.Min, n.Max, strconv.FormatBool(n.Writable), n.Description}
ParentNodeID string // custom, not an official opcua attribute
Path string // custom, not an official opcua attribute
}

func join(a, b string) string {
Expand Down Expand Up @@ -131,7 +122,6 @@ func browse(ctx context.Context, n *opcua.Node, path string, level int, logger *
switch err := attrs[3].Status; {
case errors.Is(err, ua.StatusOK):
def.AccessLevel = ua.AccessLevelType(attrs[3].Value.Int())
def.Writable = def.AccessLevel&ua.AccessLevelTypeCurrentWrite == ua.AccessLevelTypeCurrentWrite
case errors.Is(err, ua.StatusBadAttributeIDInvalid):
// ignore
case errors.Is(err, ua.StatusBadSecurityModeInsufficient):
Expand Down Expand Up @@ -504,11 +494,20 @@ func (g *OPCUAInput) createMessageFromValue(dataValue *ua.DataValue, nodeDef Nod

message := service.NewMessage(b)

// Deprecated
message.MetaSet("opcua_path", sanitize(nodeDef.NodeID.String()))
message.MetaSet("opcua_tag_path", sanitize(nodeDef.BrowseName))
message.MetaSet("opcua_parent_path", sanitize(nodeDef.ParentNodeID))

// New ones
message.MetaSet("opcua_source_timestamp", dataValue.SourceTimestamp.Format("2006-01-02T15:04:05.000000Z07:00"))
message.MetaSet("opcua_server_timestamp", dataValue.ServerTimestamp.Format("2006-01-02T15:04:05.000000Z07:00"))
message.MetaSet("opcua_attr_nodeid", nodeDef.NodeID.String())
message.MetaSet("opcua_attr_nodeclass", nodeDef.NodeClass.String())
message.MetaSet("opcua_attr_browsename", nodeDef.BrowseName)
message.MetaSet("opcua_attr_description", nodeDef.Description)
message.MetaSet("opcua_attr_accesslevel", nodeDef.AccessLevel.String())
message.MetaSet("opcua_attr_datatype", nodeDef.DataType)

tagName := sanitize(nodeDef.BrowseName)

Expand Down

0 comments on commit a8dc4a8

Please sign in to comment.