Skip to main content

Give industrial MQTT data a shared structure

The SPARKPLUG_B route connects Coreflux to a Sparkplug B namespace. It can decode binary Sparkplug payloads into readable JSON, publish local MQTT topics as a Sparkplug edge node, or run both directions in one route.
Sparkplug is a shared vocabulary for industrial MQTT. MQTT carries the messages; Sparkplug defines how devices announce themselves, report values, and signal whether they are online.

When to use it

Use this route when you need to:
  • consume spBv1.0/# traffic in LoT Actions, dashboards, or storage Routes;
  • publish Coreflux topics as NBIRTH, NDATA, and NDEATH;
  • group edge-node metrics into Sparkplug devices;
  • accept NCMD or DCMD writes for selected metrics; or
  • gate edge-node publishing on an external Primary Host.
Use the separate Sparkplug Host Route when Coreflux must be the Primary Host Application.
Start by choosing the direction in which Coreflux participates.

Quick Start

Decode every Sparkplug B publisher on the local broker into readable MQTT topics:
This mode listens to all spBv1.0/# traffic. You do not need a Group ID or Edge Node ID.

Choose the Coreflux role

MODE is the canonical setting. DIRECTION remains accepted as a deprecated alias with the same values.
Only one namespace consumer can run per broker. Deploy either one SPARKPLUG_B route in DECODE or BOTH mode, or one SPARKPLUG_HOST route. Multiple ENCODE-only routes are allowed.

Configure the Sparkplug connection

The SPARKPLUG_CONFIG block controls the route mode, edge-node identity, target MQTT broker, and optional Primary Host gating.
GROUP_ID and EDGE_NODE_ID do not filter decoded traffic. The decode path always consumes the complete spBv1.0/# namespace.

Declare edge-node metrics

In ENCODE or BOTH mode, add node-level metrics directly to the route and device-level metrics inside ADD DEVICE. This complete route publishes a node metric and a writable device metric to a remote broker:
Supported scalar and array datatypes include signed and unsigned integers, Float, Double, Boolean, String, Text, UUID, DateTime, and Bytes. DataSet and Template values can be decoded but not encoded.

Understand the message lifecycle

When the encode path connects, Coreflux:
  1. publishes NBIRTH, including bdSeq and Node Control/Rebirth;
  2. publishes one DBIRTH for each declared device;
  3. publishes NDATA or DDATA when a source topic changes;
  4. republishes births after a Node Control/Rebirth command; and
  5. publishes death messages on a graceful stop or delivers NDEATH through the MQTT Will after a crash.
Writable node and device metrics accept inbound NCMD and DCMD values. Coreflux republishes each accepted value to its local write topic.

Gate publishing on a Primary Host

Set PRIMARY_HOST_ID when an external Primary Host must be online before the edge node publishes:
The route watches the retained spBv1.0/STATE/PlantHost topic. It defers births and suppresses data until the host reports online:true, then publishes fresh births and resumes data.
Primary Host gating does not buffer values. Data produced while the host is offline is dropped, and multi-server Primary Host failover is not supported.

Consume decoded topics

The decode path converts the fixed Sparkplug wire namespace into a JSON topic tree:
Each decoded metric contains its canonical name, value, datatype, timestamp, and quality:
The route also publishes: Metric names containing / create deeper topic levels. The name field in the JSON payload remains authoritative.

Verify the route

1

Check route health

Publish the connection check command to $SYS/Coreflux/Command:
Confirm $SYS/Coreflux/Routes/PlantDecoder/status reports the route as connected or active.
2

Observe Sparkplug traffic

Use any MQTT client to confirm messages arrive under spBv1.0/#.
3

Subscribe to decoded output

Subscribe to sparkplug/decoded/#. After a BIRTH message, named metric topics and retained $status topics appear.

Troubleshooting

Confirm the route is active and that a Sparkplug B publisher is sending valid protobuf payloads under spBv1.0/#. Decoded output appears under sparkplug/decoded/#.
Alias-only DATA arrived before its matching BIRTH. Wait for or request a rebirth and monitor $error for alias_map_unavailable.
If PRIMARY_HOST_ID is configured, confirm the matching host publishes retained {"online":true} state on the same target broker configured by SERVER and PORT.
Confirm the metric has WRITABLE "true" and a WRITE_TOPIC or DESTINATION_TOPIC. Read-only metrics reject inbound commands.

Best Practices

  • Give every edge node a unique GROUP_ID and EDGE_NODE_ID pair.
  • Build automations on sparkplug/decoded/#, not on opaque protobuf topics.
  • Use retained $status topics for availability checks.
  • Load broker credentials with GET ENV and GET SECRET.
  • Monitor $error and route status for repeated alias or decode failures.

Next Steps

Configure Sparkplug Host

Make Coreflux the Primary Host and issue commands to edge nodes.

Store decoded data

Persist readable Sparkplug metrics in a database.
Last modified on August 28, 2026