Skip to main content

Sparkplug B

info

Sparkplug B ingestion decodes node, device, and metric data over MQTT according to the protocol, then writes it to TDengine. Ordinary MQTT JSON samples cannot replace source information. Without Birth, do not guess business names from aliases.

Navigation: taosExplorer → Data In → SparkplugB.

Sparkplug B runs over MQTT, but encodes payloads in a protocol-defined format containing node, device, and metric information. It belongs to message-queue ingestion; industrial use cases can start here. An ordinary MQTT JSON tutorial does not replace this page's Birth and alias checks.

1. Prepare one device​

Obtain the Broker, authentication, Group ID, one node and device ID, message types, and an observable metric from the source administrator. Confirm that the taosX or taosX-Agent host can connect to the Broker and has the required subscription permissions. Have an authorized TDengine TSDB administrator prepare a separate test database and record its name.

ItemPrerequisite
Source systemAn existing node/device publishing according to Sparkplug B, with known actual Group, node, and device IDs. An ordinary MQTT JSON producer cannot replace it directly.
Execution hosttaosX or the selected taosX-Agent can access the actual Broker. The execution identity can read certificates and private keys.
PermissionsSubscription permission for selected message types. Only when REBIRTH is enabled are the corresponding publishing permission and source-operation authorization also required.
ModelDefine time, metric names, data types, device granularity, and the target table-creation scope. Automatic template-based table creation requires target schema permissions.
VerificationA test metric that can be changed safely. The source administrator can provide Birth and subsequent data messages for comparison.

2. Configure and start​

  1. Add a SparkplugB data source and select the test target database and actual Agent. Enter Brokers, protocol, a unique client ID, Keep Alive, and authentication/TLS materials, then check connectivity.
  2. Enter the actual source group as Group ID. Enter node IDs directly for node entries and use 节点ID/设备ID for device entries. Select only one object initially.
  3. Select message types matching the test object, for example NBIRTH/NDATA for a node or DBIRTH/DDATA for a device. Do not subscribe only to data changes while ignoring initialization information.
  4. Retrieve a real sample from the server. Check metric names, types, and values. Use the preview to configure the target supertable, child table, time column, value column, and tags. Record the actual names, then submit and start.

Enter a recognizable Task Name, such as sparkplug_demo, and select SparkplugB as the Data Source Type. Select an Agent only when collecting through taosX-Agent; otherwise, the taosX host connects to the source. Have an authorized TDengine TSDB administrator prepare the target database, or use Create Database. Do not enter Group ID in the database field.

The image below uses task name sparkplug_demo and existing test database taosx_quickstart for this page's offline configuration demonstration; the task has not been submitted. For real collection, select the separate target database prepared for the task.

Sparkplug B task name, type, Agent, and target database

Retrieved samples are protocol-decoded data, not raw protobuf bytes. JSON parsing applies to fields such as metadata/properties; it does not mean an ordinary JSON parser can process the entire raw MQTT payload directly.

Sparkplug B Broker, protocol, client, and TLS configuration

After configuring the connection, expand Subscription Configuration and enter Group, nodes/devices, and message types. Keep the REBIRTH command setting consistent with source authorization. Do not enable it just to obtain retrieval samples.

Sparkplug B group, nodes/devices, message types, and REBIRTH option

2.1 Connection and subscription fields​

FieldConfiguration
BrokersActual addresses and ports, separated by commas. localhost is the collection host, not the browser. Also prevent duplicate subscriptions to the same business stream across Brokers.
MQTT protocolInitially 5.0 in a new form. Select and record it according to Broker and device configuration. A direct DSN must explicitly specify a protocol version.
Client IDKeep it unique on the same Broker so another instance does not displace the original connection.
Keep AliveConnection keepalive interval in seconds, initially 60 in a new form. A direct DSN defaults to 5, with a minimum of 5. It is neither a point sampling interval nor a historical backfill range.
Username and passwordBroker identity, not a TDengine login account.
TLS verificationFor server-only authentication, provide the server CA. Mutual authentication also requires a client certificate and matching private key. Check actual ports and trust configuration; do not disable certificate verification during troubleshooting.
Group IDSource Sparkplug group identifier, not an MQTT client ID or database consumer group.
Node/device listComma-separated. Use node1 for a node and node1/device1 for a device. Check actual letter case for each.
Message typesComma-separated. Supports NBIRTH, NDEATH, NDATA, NCMD, DBIRTH, DDEATH, DDATA, DCMD, and STATE.

NBIRTH, NDEATH, NDATA, and NCMD match node entries; device messages match device entries. Subscribing to NCMD/DCMD differs from actively sending commands to nodes. Permission to read command messages does not imply device-control authorization.

For an initial subscription check, use this small-scope example: Group factory_a, node edge_01, device device_01, Node/Device List edge_01,edge_01/device_01, and Message Types NBIRTH,DBIRTH,NDATA,DDATA. These names only demonstrate the relationships. Replace them with actual IDs from the source administrator.

Message typeSource topic to check
NBIRTHspBv1.0/factory_a/NBIRTH/edge_01
DBIRTHspBv1.0/factory_a/DBIRTH/edge_01/device_01
NDATAspBv1.0/factory_a/NDATA/edge_01
DDATAspBv1.0/factory_a/DDATA/edge_01/device_01

Entering only edge_01 with only DDATA selected does not generate the corresponding device subscription. If the node/device list is unset or entirely whitespace, it expands to the group's # scope for selected message types. This may exceed the initial verification scope, so limit it explicitly. A list containing only commas or other input without valid entries also produces no subscriptions; it is not equivalent to leaving the field unset. Avoid extra spaces around IDs between commas. Missing or entirely empty message types cause an error, and types must be uppercase. Connection success does not replace subscription-scope checks.

For full types, defaults, empty-value behavior, and file rules, see Sparkplug B read parameters. This entry point fixes Clean Session / Clean Start and subscription QoS 1. Adding ordinary MQTT's clean_session=false cannot enable persistent sessions. Multiple Brokers are parallel connections, not an automatic primary/standby failover list.

With TLS Verification set to Disabled, the client first tries TCP, then TLS without server-certificate verification if TCP fails. Explicitly configure a trusted CA for production connections; this option does not provide strict identity verification. Prepare server-only or mutual authentication materials as listed above.

2.2 Retrieve and inspect samples​

  1. Expand Payload Transformation. With an authorized test node, click Retrieve from Server. Alternatively, paste an obtained decoded sample into the message body field, or click Upload File to supply a sample file. Manual samples are only for configuration; they do not publish to the Broker or prove a real subscription succeeded.
  2. Maximum Sample Rows initially shows 5 and allows up to 100. This limits only configuration previews, not the production task's ingested rows. If new data has not arrived, have the source administrator send authorized Birth and test data. Do not repeatedly trigger REBIRTH on production nodes.
  3. Click the magnifying-glass icon at parsing and inspect Preview Parsing Results. First check group_id, message_type, edge_node_id, and device_id, then name, alias, timestamp, datatype_str, and value. Node messages have no device ID. Do not invent a device name merely to fill the field.

Retrieve from Server establishes a real subscription; it is not an offline preview. Connectivity checks and sampling use separate client IDs beginning with _taosx_validate_spb_ and _taosx_sample_spb_, respectively, containing the configured Client ID and a random suffix. Broker client-ID rules and ACLs must allow these test identities. A working production collection identity does not mean the retrieval identity has subscription permission.

When Send REBIRTH Command is enabled, sample retrieval may also send initial requests to specified nodes and request again when alias names cannot be resolved. Obtain source-control authorization before retrieval too. To check configuration only, keep it disabled and paste an obtained decoded sample. Repeated retrieval is not necessarily free of side effects.

Sparkplug B sample input, retrieval, parsing, rules, and mapping controls

The following parsing, transformation, filtering, and mapping images use the same fixed offline configuration samples organized as decoded DBIRTH fields: namespace=spBv1.0, group_id=factory_a, edge_node_id=edge_01, device_id=device_01, and payload_seq=1. They verify only configuration previews, not actual Broker subscriptions, raw protobuf decoding, or target ingestion.

Metric namealiasdatatype_strvalue
counter81Int8-8
counter162Int16-46
active3Booleantrue

The parsing preview spans two pages. Use the first image to check identities and types, then the second to check times and values in the same row order:

Identity and type for three rows of fixed Sparkplug B DBIRTH samples

Complete timestamps and values for the same three Sparkplug B sample rows

All three rows have timestamp 1795132800000 milliseconds, corresponding to 2026-11-20T08:00:00+08:00 in the images. In actual decoded results, payload_ts is payload time and timestamp is metric time. These images do not show payload_ts. Before choosing a primary timestamp, check actual value availability, time-zone display, and target retention. Do not treat sequence number payload_seq as time.

metadata and properties may contain JSON strings. Configure JSON extraction only when their properties are needed; otherwise, retain the original fields. For parsing parameters and adding/removing rules, see Parsing (JSON, Regex, UDT) and Extraction, splitting, filtering, and transformation.

2.3 Metric types and target templates​

For templates that create supertables by type, click Add Extraction/Splitting under Extract or Split from Columns. Select source column datatype_str, rule convert, and set output-field name to td_datatype. Enter this JSON as rule:

{
"Int8": "TINYINT",
"UInt8": "TINYINT UNSIGNED",
"Int16": "SMALLINT",
"UInt16": "SMALLINT UNSIGNED",
"Int32": "INT",
"UInt32": "INT UNSIGNED",
"Int64": "BIGINT",
"UInt64": "BIGINT UNSIGNED",
"Float": "FLOAT",
"Double": "DOUBLE",
"Boolean": "BOOL",
"String": "VARCHAR(128)",
"DateTime": "TIMESTAMP"
}

Type names are case-sensitive. The source value for double-precision floating point is Double, not target-type spelling DOUBLE. This is an example mapping for common scalars, not all protocol arrays or complex types. Model unmatched types separately rather than hiding differences with one default numeric type. The target length for String, 128, is also only an example; determine it from actual data.

Click the rule's magnifying-glass icon. Expect the original datatype_str to remain and a new td_datatype field to appear. In these samples, Int8, Int16, and Boolean map to TINYINT, SMALLINT, and BOOL, with values still -8, -46, and true. Other types are not covered by the image. Check every actual type against source values. If no mapping exists, correct the rule or restrict collection before creating tables. After adding or removing rules, recheck downstream templates for correct field references.

Values, source types, and target types after transforming the same three Sparkplug B sample rows

2.4 Optional filtering​

Add a filter only if the business scope requires excluding a metric type. For example, click Add Filter and enter datatype_str != "Int8" to exclude Int8 data. This does not convert it to another type. Click the magnifying glass and confirm that Int8 no longer appears while other required types remain.

Sparkplug B filter excluding Int8 by type

After filtering these samples, only counter16 and active remain. payload_seq remains 1, timestamps are unchanged, and values remain -46 and true. Check both preview pages:

Identity and timestamps of counter16 and active retained after Sparkplug B filtering

Values and types retained after Sparkplug B filtering

Leave the filter empty if not needed, or delete the rule and preview again. The mapping example below does not exclude Int8. Decide filtering for the production task from the business scope rather than excluding data merely to match screenshots.

2.5 Configure dynamic table mapping​

For an existing fixed model, select the actual object under Target Supertable. To create separate tables by metric type, select Create Template from the dropdown beside Create Supertable. Confirm target table-creation and column-addition permissions first, then configure:

SettingExample and checks
Supertable namespb_${group_id}_${datatype_str}, separated by group and source type. Preview expanded names.
Data columnsts is TIMESTAMP; set the type of value to ${td_datatype}. Confirm every row yields a valid target type.
TagsUse string types large enough for actual edge_node_id and device_id. The image uses VARCHAR(20), which is not sufficient for every deployment.
Child-table namespb_${group_id}_${datatype_str}_${edge_node_id}_${device_id}_${name}. The node/device/metric combination must distinguish objects. Check empty device IDs, invalid characters, and length.
Time and valueMap ts to timestamp, value to value, and tags to corresponding ID fields. Handle missing metric times according to source conventions first; do not default to payload or system time.

Sparkplug B supertable template by group and type

Sparkplug B child-table template and time, value, and tag mappings

Click the mapping magnifying glass and check each group's SuperTableName, SubTableName, ts, value, and tags. The image below uses the same offline samples from section 2.2 after removing the optional filter above, so it includes Int8. The three child-table names end in counter8, counter16, and active, with values -8, -46, and true and the same timestamps as the parsing preview. If the production configuration keeps the filter excluding Int8, it must not appear in the current mapping preview.

Complete supertable names, child-table names, and mapping results for the same Sparkplug B sample set

Templates may automatically create missing tables or columns. Check generated schemas and permissions in a small scope before expanding to other devices. Default Values in mapping are for confirmed missing-value handling, not for merging distinct devices with fixed values or hiding names missing because Birth was not received. For full mapping, default-value, and error-action descriptions, see Target table modeling and field mapping and Write errors and exception data.

After previewing, check advanced and error settings below, click Submit, return to the task list, find the new name and ID, and confirm startup and runtime status. For task lists, viewing, editing, copying, and stopping, see Daily operations. A successful preview cannot replace a target query.

3. Birth and REBIRTH​

Devices may establish metric-name-to-alias mappings in Birth messages, then send only aliases in subsequent data messages. If only data messages are available without Birth, do not guess business names from aliases.

warning

Messages with only unknown aliases and no usable metric names may be skipped. Receiving Birth later does not automatically replay missed data. Obtain Birth for the corresponding node/device first, then have the source send authorized new values and check each target name and value. Target write-error archives cannot replace this step because the problem occurs during source-message decoding.

Even after Birth establishes an alias, subsequent NDATA or DDATA must still contain decodable datatype and value. DATA missing datatype does not inherit its type from Birth, and its value is not retained either. A successful Birth preview alone does not prove complete ingestion of later data. Verify at least one DATA message with a name and one with only an alias, including types, timestamps, and values. If a type is missing, correct the source message first rather than filling it with target defaults.

Send REBIRTH Command can request that nodes report information again, but sends control messages to the source. Obtain source-administrator approval before enabling it and confirm publishing permissions and operational impact. Do not repeatedly trigger it on production nodes just to obtain samples. If devices do not use aliases, still confirm that actual messages contain the required names.

4. Advanced options and write-error policies​

Check batches, write concurrency, and health settings under Advanced Options, then expand Error Handling Policy. Before allowing automatic table or column creation, check metric types in Birth, target templates, and permissions. Automatic column addition cannot hide type conflicts for metrics sharing a name. Target caching also cannot replace Birth/alias state or Broker-session recovery. After errors, still check whether subsequent data decodes correctly for each device.

Sparkplug B batching, write concurrency, and health-monitoring settings

SettingNew-form initial value
Maximum processing batches100 batches, minimum 1.
Batch size1000 messages.
Batch delay500 milliseconds.
Write concurrency and health monitoringRecord this task's form values. For existing tasks, use actual saved values.

For batch sending, concurrency, and tuning verification, see Message batching. For health fields, see Health monitoring configuration.

This entry point's advanced options do not provide the MQTT task's Message Waiting Queue Size, Cache Real-Time Data, or Save Raw Data switches. Their shared MQTT protocol does not mean the same controls or retention capabilities apply. Configure optional target write-error caching separately using Write errors and exception data.

For archive operations, see Logs and performance.

5. Verification​

Have the administrator change a metric approved for testing and record the time, value, Group, node, and device. Query the latest records in the actual generated child table using taosExplorer's Data Browser or the taos CLI. Check these identifiers and values, not only the total message count.

6. Troubleshooting​

SymptomChecks
Broker online, but no device dataCheck that Group, node/device list, and message types match.
Connectivity succeeds, but retrieval has no data or is deniedCheck ACLs for the sampling client ID, then the topics above and whether the source sent corresponding Birth/new values. Lists containing only commas or mismatched node/device types do not generate expected subscriptions.
Alias cannot be resolved to a nameCheck that Birth was received and mappings were rebuilt after reconnection. Decide whether to request REBIRTH according to authorization.
Incorrect type or table nameCheck decoded types, target mappings, and actual expanded table names. Do not use one type for every metric.

For other task, write, and runtime issues, see Troubleshooting by symptom.

7. Stop, recover, and limitations​

Preserve configuration after stopping the original task, and verify both Birth/alias and new values during recovery. MQTT reconnection does not prove complete metric mappings or recover all historical changes not retained at the source. Test multiple devices, multiple Brokers, state messages, and control messages separately before expanding scope. This page does not treat REBIRTH as a side-effect-free query.