Overview of the MQTT Sparkplug B Collector

The MQTT Sparkplug B collector enables you to connect as a Primary Host application and collect data based on the MQTT Sparkplug B specification (Sparkplug 3.0.0). Specifically, you can subscribe to a topic that was published using the Sparkplug B payload and collect time-series data in a structured and understandable format.

In general, a topic will be published in the following format:

Namespace/Groupname/<Message Type>/NodeID/<DeviceID>

For example,

spBv1.0/MyAdminGroup/NBIRTH/AdminNode1/ABC-12345
The table below lists the message types that are sent as a topic:
Message type Description
NBIRTH Message to notify the client (MQTT Sparkplug B Collector) that data is sent from a node. This message includes information such as tag information, data types, names, and alias if any.
NDEATH Message to notify the client (MQTT Sparkplug B Collector) that there is no data to be sent from the node.
DBIRTH Message to notify the client (MQTT Sparkplug B Collector) that data is sent from a device. This message includes information such as tag information, data types, names, and alias if any.
DDEATH Message to notify the client (MQTT Sparkplug B Collector) that there are no data to be sent from the device.
NDATA Message to notify the client (MQTT Sparkplug B Collector) that the actual data (metric) from the node is available to be collected.
DDATA Message to notify the client (MQTT Sparkplug B Collector) that the actual data (metric) from the device is available to be collected.
NCMD Message to notify the Publisher that the client (MQTT Sparkplug B Collector) is receiving NDATA without receiving the NBIRTH payload.
DCMD Message to notify the Publisher that the client (MQTT Sparkplug B Collector) is receiving DDATA without receiving the DBIRTH payload.
STATE The collector's state message. This message is sent by the client (MQTT Sparkplug B Collector) to the Publisher through a Broker stating the status of the Collector. If the cient is active, the Publisher will send the needed data through the MQTT Broker.

Example message format:

Topic- spBv1.0/STATE/<hostname>

Payload-
{ online : true,
              timestamp : 1702879923}
#The payload is in JSON format.

Supported MQTT Versions:

  • MQTT V5
  • MQTT V3.1.1

Supported data format:

  • Sparkplug B V1.0

Topology: The MQTT Sparkplug B collector supports a distributed model, that is, the MQTT broker, the collector, and the Historian server can be installed on the same machine or on different machines.

Features:

  • You can subscribe to multiple-level topics based on Sparkplug B paylod using a wildcard.
  • You can collect time-series data.
  • You can specify a device or node from which you need to collect data from.
  • You can collect the data more specifically by providing device ID, node ID, and group ID.
  • You can configure tag mask as needed by selecting the interfacename, groupid, edge nodeid, deviceid along with delimiter.
  • You can select what tags you want to be added in Historian by using Tags to Add mask.
  • You can select what tags you do not want to be added in Historian by using Tags to Exclude mask.
  • Only the unsolicited data collection is supported; polled collection is not supported.
  • The timestamp resolution is seconds, milliseconds, and microseconds.
  • Boolean, floating point, integer, and string data types are supported.
    Note: Although the Recalculate button in Historian Administrator is enabled, the functionality is not available because the MQTT collector is a non-historic collector (the source broker does not store the historical data).

How it works:

  1. The Publisher connects to the MQTT Broker and subscribes to topics. The topics include STATE, NCMD, and DCMD.
  2. The MQTT Sparkplug B collector connects to the MQTT broker and subscribes to a topic based on the Device ID and Node Id that you provide while creating an instance. The topics include STATE, NBIRTH, DBIRTH, NDATA, DDATA, NDEATH, and DDEATH.
    You can use username/password-based authentication or certificate-based authentication. Transport Layer Security (TLS) authentication is used for subscribing the data from message broker to avoid middleware attacks so that the data is securely transferred from message broker to the MQTT Sparkplug B collector.
    Note: It is recommended to use a certificate based authentication for a secured data transfer.
  3. The MQTT Sparkplug B collector publishes the STATE message topic to the MQTT Broker.
  4. The MQTT Broker then publishes this topic to the Publisher.
  5. When there is data in the Device or Node, the publisher publishes a DBIRTH or NBIRTH message topic to the MQTT Broker.
  6. The MQTT Broker then publishes this topic to the MQTT Sparkplug B collector.
  7. The Publisher then publishes the DDATA or NDATA to the MQTT Broker.
  8. The MQTT Broker publishes the data (metrics) to the MQTT Sparkplug B collector.
  9. The collector converts the data from the Sparkplug B v1.0 format to a Historian-understandable format. It verifies tag availability in the Historian and, if not present, adds the tag, then adds the data samples, streaming the data to the Historian server or a cloud destination.

    The process explains how the topics and data are published among the Publisher, MQTT Sparkplug B collector, and MQTT Broker. Similarly, when there is no data or a Device or Node is inactive, the Publisher publishes DDEATH or NDEATH message topics to the MQTT Spakplug B collector through the MQTT Broker.

    Note: Sometimes, the publisher might send DDATA or NDATA without sending the corresponding BIRTH message, in such cases, the MQTT Sparkplug B collect sends the DCMD or NCMD message to the MQTT Broker. The the Broker sends the message to the publisher.

    Sparkplug B Message format:

    {
            "timestamp": <timestamp>,
            "metrics": [{
                "name": "<metric>",
                "alias": <alias>,
                "timestamp": <timestamp>,
                "dataType": "<data Type>",
                "value": "<value>"
            }],
            "seq": <sequence_number>
    }
JSON Parameter Description
timestamp The time at which the message was published. For example, 1642496400000 (time in milliseconds). Generally, the timestamp format is a 64-bit integer in milliseconds or microseconds since the Unix epoch.
metrics The metrics or the data that was published. For example,
  • name: BoilerTag1
  • alias: BT1Temp
  • timestamp: 1642496400000
  • dataType: Float
  • value: 80.5
seq The unique sequence number of the message. The first message will have the seq as 0. This will increment by one for every other messages.

Supported Data Types:

Source Data Type Historian Data Type
DoubleFloat, DoubleInteger, FixedByte, QuadInteger, SingleFloat ihDoubleFloat
ByteString, String ihVariableString
Boolean ihBool