Using SparkplugCmd Utility as Sparkplug host application: Difference between revisions

From OPC Labs Knowledge Base
Line 73: Line 73:
<pre>consumer  
<pre>consumer  
subscribePayload easyGroup easyEdgeNode</pre>
subscribePayload easyGroup easyEdgeNode</pre>
=== Sub-commands ===
By default, the subscriptions last one minute, or until the you press {{Style=keyboard|X}} on the keyboard. Use the '''!wait''' sub-command to specify a different duration, or 'Infinite'.


== Command: '''consumer subscribeMetric''' ==
== Command: '''consumer subscribeMetric''' ==

Revision as of 14:54, 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.

Arguments

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.

With this command, each metric can be included no more than once within the displayed payload. For this reason, this command is not suitable for historical data. Use the consumer subscribeMetric command for historical data instead.

Arguments

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".

Options

The subscribePayload command has following specific options:

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

The allowUnknownMetrics determines whether the payloads can contain unknown metrics (i.e. metrics without a Birth). When set to False, unknown metrics will be dropped from the payload notifications.

The componentTypes option allows you to specify whether you want to see notification from edge node(s), device(s), or both. Possible values are: None|EdgeNode|Device|Any.

The deliverCompleteDataset option determines whether the notifications will always contain the complete dataset (set of metrics) in the payload. When set to True, metrics not included in the Data message will be automatically filled in with their latest known values.

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

Sub-commands

By default, the subscriptions last one minute, or until the you press X on the keyboard. Use the !wait sub-command to specify a different duration, or 'Infinite'.

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.

Arguments

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.

Examples

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