What is MQTT Sparkplug B?

In short: MQTT moves messages efficiently, but says nothing about what the messages contain. Sparkplug B is an open specification that defines the topic structure, the payload format and how the system knows whether a device is online. The result is that equipment and SCADA can be connected without custom mapping for every device.

MQTT: publish and subscribe

In MQTT, clients do not talk directly to each other. A broker receives messages published on a topic and forwards them to everyone subscribing to it. The connection is always initiated by the client, so a station out in the field does not need open inbound ports. The protocol is lightweight, tolerates unstable connections and suits many sites over mobile networks.

The problem is that MQTT does not define any content. Two vendors can publish the same temperature as site1/temp with text, or plant/a/tt101 with JSON. Without a common convention, every integration has to be built by hand.

What Sparkplug B adds

Sparkplug was developed under the Eclipse Foundation and is standardised as ISO/IEC 20237. The specification defines three things:

  • Topic structure: all messages follow the same pattern.
  • Payload: a compact binary format (Protocol Buffers) with name, data type, value and timestamp for each metric.
  • State: birth and death messages that let the receiver always know what is online, and whether the data is fresh.

The topic structure

spBv1.0/<group_id>/<message_type>/<edge_node_id>/[<device_id>]

spBv1.0/Waterworks/NBIRTH/Station-014
spBv1.0/Waterworks/DDATA/Station-014/Pump-1

group_id groups nodes logically, edge_node_id is the gateway in the field (for example Ignition Edge), and device_id is the equipment behind it, typically a PLC. The most important message types:

TypeMeaning
NBIRTH / DBIRTHThe node or device is online. Contains all metrics with data type and initial value.
NDATA / DDATAChanged values – only what has changed is sent.
NDEATH / DDEATHThe node or device is offline. NDEATH is registered with the broker as a "Last Will" and is sent automatically if the connection is lost.
NCMD / DCMDCommand from the central system, for example a new setpoint.
STATEStatus of the central application (Primary Host). Edge nodes can buffer data while the central system is down.

Example payload

The payload itself is binary. Decoded, a DDATA message looks roughly like this:

{
  "timestamp": 1763112000000,
  "seq": 42,
  "metrics": [
    { "name": "Pump/Running",      "alias": 11, "datatype": "Boolean", "value": true },
    { "name": "Pump/Current_A",    "alias": 12, "datatype": "Float",   "value": 18.4 },
    { "name": "Sump/Level_m",      "alias": 20, "datatype": "Float",   "value": 1.72 }
  ]
}

In the birth message, each metric name is tied to a numeric alias. Later messages can send only the alias, which reduces data traffic further. The sequence number seq lets the receiver detect lost messages and request a new birth.

Why state matters

In an ordinary MQTT setup, a value that does not change looks the same as a value from a station that has lost its connection. With Sparkplug, the central system receives an NDEATH when the connection is lost, and all values from the node are marked with bad quality. The operator sees that the data is old, instead of relying on a value that is no longer true.

Sparkplug B in Ignition

Ignition uses the modules from Cirrus Link:

  • MQTT Transmission on Ignition Edge or a local gateway publishes tags as Sparkplug metrics.
  • MQTT Engine on the central gateway subscribes and creates tags automatically from the birth messages.
  • MQTT Distributor or an external broker passes the messages on.

Because the tag structure is built automatically, a new station becomes visible centrally as soon as it connects. Combined with UDTs and parameterised screens in Perspective, new sites can be added through configuration instead of new development.

When is Sparkplug B a good fit – and when not?

Sparkplug B is a good fit when many sites are to be brought together over mobile networks or unstable lines, when data is to be shared with several systems at once, and when the plant will grow. For a single machine on a fixed network, a direct OPC UA connection may be simpler.

Some practical advice:

  • Decide the naming of group_id, nodes and metrics before the first station is commissioned. It is hard to change later.
  • Use TLS and authentication towards the broker, and restrict which topics each client can publish and subscribe to.
  • Plan the broker for high availability if the whole plant depends on it.

We use MQTT and Sparkplug B in distributed Ignition solutions, often together with Ignition Edge out at the stations. Wondering whether it fits your plant? Get in touch for a conversation.

Back to Latest news

Sverre A. Blindheim

Get in touch

Want to know how we can help you? Call, e-mail me or write a message here, and we will talk about your needs.

Sverre A. Blindheim

Sr. Automation engineer / CEO

+47 97 05 80 66

sverre.blindheim@elio.no

Send a message

We only use the information to reply to you. Privacy