MQTT Sparkplug provides an open and freely available specification for how
Edge of Network (EoN) gateways or native MQTT
enabled end devices and MQTT Applications communicate bi-directionally
within an MQTT Infrastructure. One of the unique aspects of
MQTT protocol
is that it was originally
designed
for real time SCADA
systems
to help reduce data latency over bandwidth limited and often unreliable network infrastructure.
Similarly the intent of the Sparkplug specification is to take full advantage of MQTT’s native
Continuous Session Awareness capability as it applies to real time SCADA/IIoT solutions.
This article helps you to simulate the Sparkplug B encoding in IoT Simulator. It is crucial to learn about the
MQTT Sparkplug Topic Namespace Elements and
Sparkplug MQTT Message Types for simulating the data.
Sparkplug MQTT Topics and Messages
Sparkplug Topic Namespace Elements:
All Clients which use the Sparkplug spec will use this default UTF-8 Format Topic namespace.
namespace: It is the root element that will define both the structure of
the
remaining namespace elements as well as the encoding
used for the associated payload data.
Format for namespace is UTF-8 string constant should be used. Similarly the
current
Sparkplug specification defines two namespaces:
Sparkplug payload definition A
namespace element should be “spAv1.0”
Sparkplug payload definition B
namespace element should be “spBv1.0”
group_id: This provides unique logical group ID of MQTT EoN nodes. For
group_id the format should be
UTF-8 alphanumeric string, except for the reserved characters of ‘+’ (plus), ‘/’ (forward slash), and
‘#’
(number sign).
Examples of where the [group_id] might be used include Cement industry where MQTT EoN nodes on different
department have
the different [group_id].
message_type Element: It provide the indication as to, how to handle the
MQTT
payload of the message.
The following message_type elements are defined for the Sparkplug Topic Namespace:
NBIRTH – Birth certificate for MQTT EoN nodes.
NDEATH – Death certificate for MQTT EoN nodes.
DBIRTH – Birth certificate for Devices.
DDEATH – Death certificate for Devices.
NDATA – Node data message.
DDATA – Device data message.
NCMD – Node command message.
DCMD – Device command message.
STATE – Critical application state message.
edge_node_id: Unquie identification for the MQTT EoN nodes within the
infrastructure.
For edge_node_id the format should be UTF-8 alphanumeric string, except for the reserved characters of
‘+’
(plus), ‘/’ (forward slash),
and ‘#’ (number sign).
The edge_node_id travels with every message published, so it should be as short as possible
device_id: Unquie ID which used to identify the device attached to the
MQTT
EoN node. device_id is an optional element
since some messages will be either originating or destined to the edge_node_id, in that place device_id
would not be
required. The format of the device_id is a valid UTF-8 alphanumeric String except for the reserved
characters of ‘+’ (plus),
‘/’ (forward slash), and ‘#’ (number sign). The device_id travels with every message published, so it
should
be as short
as possible.
Simulate Sparkplug MQTT Device & Network
Download MQTT Simulator and it is a simulation tool which help users to test and develop the MQTT/IoT
Applications.
For installation and setup of Bevywise IoT Simulator, please refer our
help doc
and video tutorial.
In new network, create three MQTT EoN nodes by via MQTT Device
creation :
spBv1.0, Node2, Node3.
Sparkplug MQTT Message Types
Sparkplug defines the Topic Namespace for set of MQTT messages that are used to manage connection state
as
well as bidirectional
metric information exchange that would apply to many typical real-time SCADA/IIoT, monitoring, and data
collection system use
cases. The defined message types include:
NBIRTH – Birth certificate for MQTT EoN nodes.
NDEATH – Death certificate for MQTT EoN nodes.
DBIRTH – Birth certificate for Devices.
DDEATH – Death certificate for Devices.
NDATA – Node data message.
DDATA – Device data message.
NCMD – Node command message.
DCMD – Device command message.
STATE – Critical application state message.
Advantage of using these defined messages:
Using these defined messages the SCADA/IIOT Application can:
Initially Discover all metadata and monitor state of any EoN/Device connected to the MQTT
infrastructure.
Then Discover all metrics which include all diagnostics, properties, metadata, and current state
values.
Issue write/command messages to any EoN/Device metric.
Creating Sparkplug MQTT Message types in IoT Simulator
MQTT EoN NBIRTH and NDeath Certificate: The first MQTT message that an EoN
node
MUST publish upon the successful
establishment of an MQTT Session is an EoN BIRTH Certificate.
Once an MQTT EoN node is online with a proper NBIRTH, the NDATA will published.
This enables the advantages of the native Continuous Session Awareness of MQTT to monitor the
STATE of
all connected MQTT EoN node and to rely on Report by Exception (RBE) messages for
metric state changes over the MQTT session connection.
The payload of NDATA messages will contain any RBE or time based
metric EoN node values that need to be reported to any subscribing
MQTT clients.
In that, give command topic as “NBIRTH topic namespace”
and command “NBIRTH”.
Next give the NDATA topic namespace in Event and give Event Data as current time and click save.
spBv1.0/Kiln/NDATA/1
Now NDATA will published to subscriber once they subscribe the NDATA topic namespace.
Device Birth Certificate[DBRITH]
The MQTT EoN node is responsible for the management of all attached physical and/or logical devices.
Once the EoN node has published its NBIRTH, the customers application ensure that EoN Node is ONLINE
But each physical and/or logical device connected to this node will still need to provide this
DBIRTH
before
consumer applications create/update the metric structure (if this is the first time this device has
been
seen)
and set any associated metrics in the application to a “GOOD” state.
Creating the DBRITH:[namespace/group_id/DBIRTH/edge_node_id]
In that, give command topic as “NBIRTH topic namespace” and command “NBIRTH”.
Next give the DBIRTH topic namespace in Event and give Event Data as DBIRTH and click save.
spBv1.0/Kiln/DBIRTH/1
Now DBIRTH will published to subscriber once they subscribe the DBIRTH topic namespace.
Device Data Messages (DDATA):
Once an MQTT EoN node and associated devices are all online with proper Birth Certificates it is
in a mode
of quiescent
Report by Exception (RBE) reporting of any metric that changes.
It take advantage to monitor the STATE of all connected devices and can rely on Report by
Exception (RBE)
messages for
any metric value change over the MQTT session connection.
Click event with “Specific Duration” for 20 min duration with 10 sec interval.
In that give the topic as
spBv1.0/kiln/DDATA/1/LSM213
Select QoS as 1 and retain as 1
Give Random message as “ON|OFF” and click save.
Device Death Certificate[DDEATH]
If the device becomes unavailable for any reason
(no response, CRC error, etc.) it is the responsibility of the EoN node to publish a DDEATH on behalf
of the
end device.
Once the DDEATH certificate published, any MQTT client subscribed to this
device should set the data quality of all metrics to “STALE”.
In that, give command topic as “DDATA topic namespace” and command “OFF”.
Next give the DBIRTH topic namespace in Event and give Event Data as DDEATH and click save.
spBv1.0/Kiln/DDEATH/1
Now DDEATH will published to subscriber once they subscribe the DBIRTH topic namespace based on the
DDATA.
SCADA/IIoT Host Birth and Death Certificates
The SCADA/IIoT Host Node is any MQTT Client application that subscribes to and publishes messages.
In an infrastructure, mulitple MQTT Servers provide redundancy and scalability, for that MQTT EoN
nodes
need to be aware
of the “state” of the primary SCADA/IIoT Host application(s).
The “state” can be acheived by the unique set of Birth/Death Certificates that the SCADA/IIoT Host
MQTT
Client MUST
publish when a new MQTT session is established.
Topic namespace for SCADA/IIOT Host : STATE/scada_host_id
It uses an aspect of the MQTT transport called a “RETAINED” publish to
maintain the current state of the Primary
Host MQTT Client session state to all available
MQTT Servers.
The format of the scada_host_id can be valid String with the exception of the reserved characters of
‘+’
(plus),
‘/’ (forward slash), and ‘#’ (number sign).
In that give topic as SCADA/IIOT Host topic namespace/scada_host_id]:
STATE/SCADABIRTH
Set WILL Retain flag as “1” and QoS as “1”
Select message type as “Text” and variant as “Constant”.
Give Payload or message as “ONLINE".
SCADA/IIoT Host Death Certificate Payload (STATE):
When the SCADA/IIoT Host MQTT client establishes an MQTT session to the MQTT Server(s),
the Death Certificate will be part of the Will Topic
and Will Payload registered in the
MQTT CONNECT transaction.
Give the Key as ONLINE_STATE, select “constant”, give value as TRUE and click ADD
Next click + button and
Give Key as ONLINE_TIME, select “System variable” and select “$Current_time from list
next click ADD and save the JSON.
Once the DBIRTH occurred, publish the DCMD by clicking the action icon
on the left side, now the NCMD will send commands to connected EoN nodes.
Next the
subscribe
the DCMD topic in SCADA/IIOT to get the Update metric from spBv1.0.
These are the Sparkplug set of MQTT Message Types that are used to manage connection state.
Next
connect
the Bevywise IoT Simulator to
built-in MQTT Broker or connect to any
other MQTTBroker
to start the Spatkplug Simulation. Likewise create Sparkplug message type for other Nodes.
Specifications of MQTT Sparkplug
Currently there are two Sparkplug defined encoding schemes that this specification supports.
Firstly the Sparkplug A
encoding scheme
based on the very popular Kura open source Google Protocol Buffer definition.
Secondly the Sparkplug B
encoding
scheme that provides a richer data model developed with the feedback of many system integrators and end
user
customers using MQTT.
Get your Environment Validated
Generate Data with No Code
simplifies simulation of the EoN Node and Devices with a easy user Interface