Using SparkplugCmd Utility as Sparkplug host application: Difference between revisions

From OPC Labs Knowledge Base
Line 59: Line 59:
<pre>consumer mqtt://test.mosquitto.org
<pre>consumer mqtt://test.mosquitto.org
subscribePayload</pre>
subscribePayload</pre>
* Subscribe to payload notifications from Sparkplug edge node "easyEdgeNode" in group "easyGroup" (and all its devices):
* Subscribe to payload notifications from Sparkplug edge node "easyEdgeNode" in group "easyGroup" on "mqtt://localhost" (and all its devices):
<pre>consumer  
<pre>consumer  
subscribePayload easyGroup easyEdgeNode</pre>
subscribePayload easyGroup easyEdgeNode</pre>

Revision as of 13:31, 23 August 2025

For general information about the SparkplugCmd tool, see Category:SparkplugCmd Utility.

Commands, Arguments and Options

The commands described here can be entered at the SparkplugCmd> prompt, or directly on the command-line invoking the SparkplugCmd utility.

Command: consumer

The consumer command (shortened: c) contains sub-commands that allow you to consume Sparkplug data, i.e. act as a Sparkplug host application component in the Sparkplug system.

The argument that follows the consumer command is the resource descriptor for the Sparkplug broker that should be used. If omitted, it defaults to mqtt://localhost, i.e. it connects to the MQTT broker on your local machine, using unauthenticated TCP connection on port 1883.

If you simply enter the consumer command (optionally with a broker URL), the SparkplugCmd enters an interactive mode for this command, and you can continue by issuing one or more sub-commands, each on a separate line. Alternatively, you can include the sub-command directly following the consumer command (with its optional broker URL), in which case the sub-command will be performed immediately.

Examples:

  • consumer, or shortened c
This command will simply show the consumer> prompt, and allow you to enter further sub-commands. The sub-commands will all connect to "mqtt://localhost".
  • consumer mqtt://test.mosquitto.org, or shortened c //test.mosquitto.org
This command will show the consumer> prompt, and allow you to enter further sub-commands. The sub-commands will all connect to the specified MQTT broker.
  • consumer subscribePayload easyGroup, or shortened c sp easyGroup
This command will connect to "mqtt://localhost" and subscribe to all payloads from the Sparkplug group with ID "easyGroup". Details of the sub-command are explained further below.

Command: consumer subscribePayload

Use the subscribePayload command (shortened: sp) to subscribe to payload notifications from an edge node or device. The received payloads are displayed in a table form. The command has following arguments:

groupId Group ID (default #)
edgeNodeId Edge Node ID (default #)
deviceId Device ID (default #)
metricName Metric Name (default #)

The arguments act as filters. They can be exact IDs or names, or you can use "#" (the default) to specify "don't care".

The subscribePayload command has following specific options:

--allowUnknownMetrics <bool> Allow Unknown Metrics (default True)
--componentTypes <sparkplugComponentTypes> Component Types (default Any)
--deliverCompleteDataset <bool> Deliver Complete Dataset (default False)

Examples:

  • Subscribe to all payload notifications from Sparkplug edge nodes and devices on "mqtt://test.mosquitto.org":
consumer mqtt://test.mosquitto.org
subscribePayload
  • Subscribe to payload notifications from Sparkplug edge node "easyEdgeNode" in group "easyGroup" on "mqtt://localhost" (and all its devices):
consumer 
subscribePayload easyGroup easyEdgeNode

Command: consumer subscribeMetric

Use the subscribeMetric command (shortened: sm) to subscribe to metric notifications from an edge node or device. Each received metric notification is displayed separately (the payloads are "unpacked").

Command: consumer publishMetric

Use the publishMetric (shortened: pm) command to publish a command metric to an edge node or device. The command has following arguments:

metricName Metric Name
typedValue Value to be written
groupId Group ID
edgeNodeId Edge Node ID
deviceId Device ID

The typedValue consists of a Sparkplug data type identifier, enclosed in square brackets, followed immediately by the actual value. Possible Sparkplug data types are: Unknown|Int8|Int16|Int32|Int64|UInt8|UInt16|UInt32|UInt64|Float|Double|Boolean|String|DateTime|Text|Uuid|DataSet|Bytes|File|Template|PropertySet|PropertySetList|Int8Array|Int16Array|Int32Array|Int64Array|UInt8Array|UInt16Array|UInt32Array|UInt64Array|FloatArray|DoubleArray|BooleanArray|StringArray|DateTimeArray.

Omit the deviceId argument if you are publishing to an edge node metric. Include non-empty deviceId if you are publishing to a device metric.

Example: consumer publishMetric Static/Int32Value [Int32]3141 easyGroup easySparkplugDemo data

Command: consumer edgeNodeRebirth

Use the edgeNodeRebirth command (shortened: enr) to publish a command to rebirth an edge node. This is a shortcut for publishing a 'true' boolean value to the metric named "Node Control/Rebirth" on the given edge node. This metric is used to request a new NBIRTH and DBIRTH(s) from the edge node.

Example: consumer edgeNodeRebirth easyGroup easySparkplugDemo