Command Handler Block

The OPC-UA Command Handler adapter block is capable of receiving requests from a topic on the Predix Edge Broker, sending those requests to an OPC-UA server, and returning the results from those requests back to a topic on the Predix Edge Broker.

This block’s “type” field is “opcuacommandhandler”, and an example configuration file that includes the block is shown later in this document.

The following diagrams display the steps of operation for a single request to the OPC-UA Command Handler block in the OPC-UA Protocol Adapter.
Figure 1. OPC-UA Command Handler Operation Steps
Figure 2. OPC-UA Command Handler Operation Steps

First, a request is sent to the Predix Edge Broker on the request topic to which the OPC-UA Command Handler block is subscribed. In the above diagram, the sender of this request is the “Custom Client Edge App”. The request is then translated to the OPC-UA-specific request that is sent to the OPC-UA server. The result is processed and published to the Predix Edge Broker on the corresponding response topic. Any application subscribed to the response topic will then receive the result of the request. The response topic is based off of the request topic and is described in more detail below.

Request and Response Topics

Request and response topics are of the following format respectively:
  • /edgeAgent/predix-edge-opc-ua-browser/<request_id>/request
  • /edgeAgent/predix-edge-opc-ua-browser/<request_id>/response

Where <request_id> is a unique identifier for the request that is set by whichever application is sending the request. The application that sends the request should first subscribe to the response topic with the same <request_id> in order to ensure it receives the response successfully.

Base Input Request

The following is the format of a JSON input request to the OPC-UA Command Handler block.
{
	"command": "<command type>",
	"params": {
		<command-specific parameters>
	}
}
  • Command is a string that determines the type of request the block will execute.
  • Params is an object that contains specific arguments for the given command.

Example Configuration

The OPC-UA Command Handler block’s type field is opcuacommandhandler. An example of its configuration is:
{
	"blocks": {
		"opcua-command-handler": {
			"type": "opcuacommandhandler",
			"config": {
				"broker_address": "mqtt-tcp://predix-edge-broker",
				"log_name": "opcua-handler",
				"log_level": "debug"
			}
		}
	},
	"mappings": {}
}
The config object for a block of type opcuacommandhandler contains the following fields.
FieldTypeRequiredDefault
log_nameStringNo<block name>
log_levelStringNo'off'
broker_addressStringNo‘mqtt-tcp://predix-edge-broker’
The log_name and log_level fields are consistent with other blocks and configure how log messages will be printed The broker_address field specifies the address of the MQTT broker from which it will receive requests.
Note: As no fields of the config object are required, the config field itself is not required. However, the block and its type field still must be included in the configuration file.

OPC-UA Browse Requests

The OPC-UA specification allows you to browse the child nodes of a given starting node on an OPC-UA server. The OPC-UA Command Handler adapter block allows you to do this using the BrowseServer command.

Browse Input Request

The following is an example JSON input request.
{
	"command": "BrowseServer",
	"params": {
		"endpoint": "opc-tcp://your-opcua-server"
		"nodeid": "ns=0;i=84",
		"depth": 1
	}
}
  • command is a string that determines what type of request the block will execute. In this example, BrowseServer corresponds to a browse request.
  • params is an object that contains the arguments for the command.
  • endpoint is a string that determines which server to connect to for the request.
  • nodeid is a string that specifies at which OPC-UA node to start the browse.
  • depth is an integer that specifies how many levels deep to browse nodes. If the request’s depth field is 2, the result will contain the starting node, its children, and its children’s children.

Browse Output Response

The following is an example JSON output response.
{
	"nodeClass": "Object",
	"identifier": "i=84",
	"displayName": "Root",
	"children": [
		{
			"nodeClass": "Object",
			"identifier": "i=85",
			"displayName": "Objects",
			"children": []
		},
		{
			"nodeClass": "Object",
			"identifier": "i=86",
			"displayName": "Types",
			"children": []
		},
		{
			"nodeClass": "Object",
			"identifier": "i=87",
			"displayName": "Views",
			"children": []
		}
	]
}
For each node, the result will contain four fields: “
  • nodeClass: corresponds to the OPC-UA spec’s NodeClass attribute. This essentially specifies the type of the node.
  • identifier: corresponds to the Node ID
  • displayName: provides a name for the node to be displayed in a more readable format.
  • children: a list of the child nodes of the current node. This list can be empty either if the node has no children, or if the depth field in the input request has been reached.

OPC-UA Node Attributes Requests

All nodes in an OPC-UA server contain some list of attributes, and this list varies with the type of node – i.e., the NodeClass of the node. The OPC-UA Command Handler adapter block allows you to query for the values of this list of attributes using the GetNodeAttributes command.

Node Attributes Input Request

The following is an example JSON input request.
{
	"command": "GetNodeAttributes",
	"params": {
		"endpoint": "opc-tcp://your-opcua-server"
		"nodeid": "ns=2;s=Counter1",
	}
}
  • command is a string that determines what type of request the block will execute. In this example, GetNodeAttributes corresponds to a node attributes request.
  • params is an object that contains the arguments for the command.
  • endpoint is a string that determines which server to connect to for the request.
  • nodeid is a string that specifies from which OPC-UA node to retrieve the attributes.

Node Attributes Output Response

The following is an example JSON output response.
{
	"NodeId": "ns=2;s=Counter1",
	"NodeClass": "Variable",
	"BrowseName": "Counter1",
	"DisplayName": "Counter1",
	"WriteMask": 0,
	"UserWriteMask": 0,
	"Value": 42,
	"DataType": "i=6",
	"ValueRank": -1,
	"AccessLevel": 3,
	"UserAccessLevel": 3,
	"MinimumSamplingInterval": 0,
	"Historizing": false
}

The fields of the response will differ depending on the type of node being queried and the attributes set on that node. A list of possible attributes an OPC-UA node can have is available here. The names of the fields in the response will directly correspond to the names of the attributes in that link.