learn/mqtt

Sparkplug B explained: topics, message types and state

Short answer

Sparkplug B is an open Eclipse Foundation specification that defines how industrial devices use MQTT: a fixed topic namespace, Protobuf-encoded payloads and birth and death certificates that tell every consumer whether an edge node and its devices are online. It adds the interoperability and state management that plain MQTT leaves open.

Updated:

What is Sparkplug B?

Sparkplug B is an open specification that defines how industrial devices and applications exchange data over MQTT. MQTT itself only moves bytes between clients: it does not say how topics should be named, what a payload looks like or how to tell whether a device is online. Sparkplug answers those three questions.

Sparkplug was originally developed by Cirrus Link and is now maintained by the Eclipse Foundation as the Eclipse Sparkplug specification. Version 3.0 is the current major version. It defines:

  • a topic namespace that every Sparkplug client uses,
  • a payload format encoded with Google Protocol Buffers (Protobuf),
  • state management with birth and death certificates and sequence numbers.

The specification names three roles. An Edge Node connects to the MQTT broker, often a gateway in front of PLCs. A Device is attached to an edge node, such as a PLC or sensor, and does not connect to MQTT itself. A Host Application consumes data and sends commands, for example SCADA or an analytics platform.

The Sparkplug topic namespace

Every Sparkplug message uses one fixed topic structure:

spBv1.0/<group_id>/<message_type>/<edge_node_id>[/<device_id>]
  • spBv1.0 identifies the Sparkplug B namespace and version.
  • group_id groups edge nodes logically, for example by site or line.
  • message_type is one of the message types below.
  • edge_node_id identifies the edge node within the group.
  • device_id is present only for device-level messages.

Examples:

spBv1.0/frankfurt-line3/NBIRTH/gateway-01
spBv1.0/frankfurt-line3/NDATA/gateway-01
spBv1.0/frankfurt-line3/DDATA/gateway-01/press-07
spBv1.0/frankfurt-line3/DCMD/gateway-01/press-07

The structure is fixed, so the tag hierarchy of a machine lives in the metric names inside the payload, not in the topic.

Sparkplug message types

Sparkplug defines nine message types. The first letter shows the level: N for edge node, D for device.

Message type Sent by Purpose
NBIRTH Edge node Announces the node is online and lists all its metrics with current values
NDEATH Broker as Last Will, or edge node before a clean disconnect Signals the node is offline
DBIRTH Edge node Announces a device is online and lists all its metrics
DDEATH Edge node Signals a device is offline
NDATA Edge node Reports changed node-level metrics
DDATA Edge node Reports changed device-level metrics
NCMD Host application Sends a command to an edge node, for example a rebirth request
DCMD Host application Sends a command to a device, for example a new setpoint
STATE Host application Announces whether a host application is online

In Sparkplug 3.0, the STATE message uses its own topic, spBv1.0/STATE/<sparkplug_host_id>, with a small JSON payload, and it is published as a retained message.

Birth and death certificates

Birth and death certificates give every consumer a reliable view of what is online. This is the main reason teams choose Sparkplug.

How a session starts

When an edge node connects, it registers its NDEATH message as the MQTT Last Will in the CONNECT packet. It then publishes NBIRTH, followed by one DBIRTH for each attached device. A birth certificate contains the full list of metrics with their names, data types and current values. A host application that receives the births has a complete model of the node.

How a session ends

If the edge node disconnects without a clean shutdown, for example on a network failure, the broker publishes the NDEATH as its Last Will. Every host application learns that the node and all its devices are offline, and it can mark their values as stale. A bdSeq metric in both NBIRTH and NDEATH lets the host match a death to the correct birth.

Report by exception

After the births, the edge node publishes NDATA and DDATA only when values change. This keeps traffic low. Because the birth already holds every metric, the host still knows the full state.

Payloads and sequence numbers

Sparkplug B payloads are binary Protobuf messages that carry a timestamp, a sequence number and a list of metrics. Each metric has a name, a data type, a value and optional properties. A birth can assign each metric a numeric alias, and later data messages can send only the alias instead of the full name to save bandwidth.

The sequence number seq counts from 0 to 255 and then wraps to 0. It increases with each birth, data and device death message an edge node publishes. If a host application sees a gap, it knows a message was lost and can send an NCMD rebirth request (metric Node Control/Rebirth). The edge node then publishes fresh births, and the host is back in sync.

The Primary Host Application and STATE

A Primary Host Application is the main consumer whose availability the edge nodes track. It publishes a retained STATE message that says whether it is online, and it sets an offline STATE message as its own Last Will.

Edge nodes configured for a primary host subscribe to its STATE topic. If the host goes offline, they publish their NDEATH and disconnect. When the host is online again, they reconnect and publish new births. Some edge nodes also buffer data locally in the meantime and forward it later. This prevents data from being published while the system that should record it is down.

Sparkplug B and the Unified Namespace

Sparkplug B and the Unified Namespace solve related but different problems. Sparkplug standardises payloads and state, but its topic namespace is flat by design: group_id and edge_node_id do not model an ISA-95 hierarchy. A Unified Namespace is usually organised by enterprise, site, area, line and cell.

Common approaches are to use Sparkplug between edge nodes and SCADA, and to publish an ISA-95-structured copy of the data for other consumers, or to encode the hierarchy in group and node IDs and metric names. Choose based on which consumers need Sparkplug state handling and which need a readable topic tree.

01ultramq/learn/faq

Frequently asked questions

What is the difference between MQTT and Sparkplug B?

MQTT is the transport protocol and does not define topic names or payload formats. Sparkplug B is a specification on top of MQTT that defines the topic structure, a Protobuf payload and rules for online/offline state, so devices and applications from different vendors can work together.

What does the B in Sparkplug B mean?

It refers to the second payload definition of Sparkplug, encoded with Google Protocol Buffers. The earlier Sparkplug A payload is deprecated, and the topic namespace for Sparkplug B starts with spBv1.0.

Does Sparkplug B need a special MQTT broker?

No. Sparkplug runs over standard MQTT 3.1.1 or MQTT 5 brokers. The broker must support QoS 0 and 1, retained messages and Last Will, which any compliant MQTT broker does.

What is a Primary Host Application in Sparkplug?

It is the main consuming application, often a SCADA or IIoT platform, whose online state the edge nodes watch. Edge nodes can wait for the Primary Host to be online before they publish, so no data is sent while no one is listening.

03ultramq/start

Talk to an engineer about your project.

Tell us what you want to connect, where it has to run and what the data should feed. We reply by email.

SUBultramq/#