# Read/Write/Update Dataset Tag using Sparkplug B

**URL:** <https://forum.inductiveautomation.com/t/read-write-update-dataset-tag-using-sparkplug-b/78022>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [August 17, 2023, 6:35pm UTC](https://forum.inductiveautomation.com/t/read-write-update-dataset-tag-using-sparkplug-b/78022 "2023-08-17T18:35:18Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chad\_Gregory](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chad_gregory/32/51192_2.png) [@Chad\_Gregory](https://forum.inductiveautomation.com/u/Chad_Gregory)\
**Post date:** [August 17, 2023, 6:35pm UTC](https://forum.inductiveautomation.com/t/read-write-update-dataset-tag-using-sparkplug-b/78022/1 "2023-08-17T18:35:18Z")

</div>

I am looking to read and write a dataset via sparkplug B. I think I have parsed the spec correctly to generate a sparkplug b payload. Using MQTTX, I am able to parse sparkplug b payload and when I capture the dataset payload it is being fully represented but the dataset does not update in ignition.

I hope someone with experience with this can assist me figuring out what I am doing wrong. I know that I can update other tags via sparkplug b, but with datasets I have hit a wall.

I am publishing to this topic which works for other tags

> spBv1.0/Injection-H1/DCMD/MES/Zima

I am testing this from node-red, I have an inject node with msg.payload set to the following

```auto
{
    "metrics": [
        {
            "name": "Job/BOM",
            "datatype": 16,
            "dataset_value": {
                "num_of_columns": 5,
                "columns": [
                    "Item",
                    "Quantity",
                    "Unit of Measure",
                    "Operation",
                    "Type"
                ],
                "types": [
                    12,
                    9,
                    12,
                    2,
                    12
                ],
                "rows": [
                    {
                        "elements": [
                            {
                                "string_value": "Item Code"
                            },
                            {
                                "float_value": 1.588
                            },
                            {
                                "string_value": "LB"
                            },
                            {
                                "int_value": 10
                            },
                            {
                                "string_value": "RESN"
                            }
                        ]
                    }
                ]
            }
        }
    ]
}

```

Any assistance would be appreciated.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [August 17, 2023, 6:46pm UTC](https://forum.inductiveautomation.com/t/read-write-update-dataset-tag-using-sparkplug-b/78022/2 "2023-08-17T18:46:24Z")

</div>

The `DCMD` topic is meant for publishing commands _to_ devices.

Ignition is acting as the primary application, and I'd expect it's receiving updates _from_ devices on the `DDATA` topic.

---

<div class="post-metadata">

**Author:** ![justin.brzozoski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justin.brzozoski/32/13452_2.png) [@justin.brzozoski](https://forum.inductiveautomation.com/u/justin.brzozoski)\
**Post date:** [August 17, 2023, 6:48pm UTC](https://forum.inductiveautomation.com/t/read-write-update-dataset-tag-using-sparkplug-b/78022/3 "2023-08-17T18:48:49Z")

</div>

You've gone a bit deeper into nuts and bolts of Sparkplug than most people who use Ignition can talk to. For Sparkplug technical questions like this, you're likely to get a better response from the mailing list or slack workspace mentioned on [this Sparkplug page](https://sparkplug.eclipse.org/join-us/).

On top of what Kevin said, I also suspect you aren't sending NBIRTH/DBIRTH messages first to inform Ignition of which tags to expect from your edge node. Sparkplug is a stateful system and you can't just throw one random data point in without setting up a sort of schema and announcing your device is online first.

---

<div class="post-metadata">

**Author:** ![Chad\_Gregory](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chad_gregory/32/51192_2.png) [@Chad\_Gregory](https://forum.inductiveautomation.com/u/Chad_Gregory)\
**Post date:** [August 17, 2023, 7:12pm UTC](https://forum.inductiveautomation.com/t/read-write-update-dataset-tag-using-sparkplug-b/78022/4 "2023-08-17T19:12:18Z")

</div>

In my case "Ignition" refers to an Ignition Edge instance which is acting as a device. It consumes tags from a PLC via OPC UA and has a few of it's own tags that are being broadcasted to our local ignition gateway via the MQTT Transmission plugin.

Like I said, the methodology I can using to set tags is working for every other tag I have tried and datasets are the only ones not working for me.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [August 17, 2023, 7:14pm UTC](https://forum.inductiveautomation.com/t/read-write-update-dataset-tag-using-sparkplug-b/78022/5 "2023-08-17T19:14:22Z")

</div>

I don't know then. Maybe check on the Cirrus Link forum like @justin.brzozoski suggested.

I assume there's something with node red going on here that I don't know about. It must have some knowledge of Sparkplug so that it can encode that JSON object into the binary protobuf format that is actually used by Sparkplug. Could be an issue there when it comes to datasets?

---

<div class="post-metadata">

**Author:** ![Chad\_Gregory](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chad_gregory/32/51192_2.png) [@Chad\_Gregory](https://forum.inductiveautomation.com/u/Chad_Gregory)\
**Post date:** [August 17, 2023, 7:18pm UTC](https://forum.inductiveautomation.com/t/read-write-update-dataset-tag-using-sparkplug-b/78022/6 "2023-08-17T19:18:03Z")

</div>

To send a Sparkplug B message via Node-RED there are two ways to do so.

1. Use the Sparkplug B nodes that can be added to the pallete
2. Install the protobuf nodes, upload thesparkplug\_b.proto file to the device, and use the encode/decode nodes to encode/decode a sparkplug B payload.

---

<div class="post-metadata">

**Author:** ![justin.brzozoski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justin.brzozoski/32/13452_2.png) [@justin.brzozoski](https://forum.inductiveautomation.com/u/justin.brzozoski)\
**Post date:** [August 17, 2023, 8:46pm UTC](https://forum.inductiveautomation.com/t/read-write-update-dataset-tag-using-sparkplug-b/78022/7 "2023-08-17T20:46:00Z")

</div>

From your description, it sound like you have an Ignition edge running MQTT Transmission talking to an Ignition gateway running MQTT Engine. Write to the tag once from the gateway system and capture what the payload looks like to see what how it encodes it. Writing to tags from the MQTT Engine side of things generates NCMD/DCMD messages back to the edge.

---

<div class="post-metadata">

**Author:** ![Chad\_Gregory](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chad_gregory/32/51192_2.png) [@Chad\_Gregory](https://forum.inductiveautomation.com/u/Chad_Gregory)\
**Post date:** [August 18, 2023, 12:24pm UTC](https://forum.inductiveautomation.com/t/read-write-update-dataset-tag-using-sparkplug-b/78022/8 "2023-08-18T12:24:34Z")

</div>

Ok I'm not 100% sure what I did differently today from yesterday but I have figured it out. For one, in Ignition you can look at the raw data for a tag, which can give you an idea of what the payload should look like though it's not a one for one translation to Sparkplug B.

With 1 row of data in the dataset this is what the raw data looks like specifically looking at the value property.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/a/5ae3627b193569fcc79e63b7d099f40a48de8ebf.png)

Values Property

```auto
{
    "columns": [
        {
            "name": "Item",
            "type": "java.lang.String"
        },
        {
            "name": "Quantity",
            "type": "java.lang.Float"
        },
        {
            "name": "Unit of Measure",
            "type": "java.lang.String"
        },
        {
            "name": "Operation",
            "type": "java.lang.Short"
        },
        {
            "name": "Type",
            "type": "java.lang.String"
        }
    ],
    "rows": [
        [
            "Some Item",
            1.588,
            "LB",
            10,
            "RESN"
        ]
    ]
}

```

From Node-RED this is the payload I sent to get it to update.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/d/1dbdee18fdb6ee7934a773888448fd79872dd3f1.png)

```auto
{
    "metrics": [
        {
            "name": "Job/BOM",
            "datatype": 16,
            "dataset_value": {
                "num_of_columns": 5,
                "columns": [
                    "Item",
                    "Quantity",
                    "Unit of Measure",
                    "Operation",
                    "Type"
                ],
                "types": [
                    12,
                    9,
                    12,
                    2,
                    12
                ],
                "rows": [
                    {
                        "elements": [
                            {
                                "string_value": "Some Item"
                            },
                            {
                                "float_value": 1.588
                            },
                            {
                                "string_value": "LB"
                            },
                            {
                                "int_value": 10
                            },
                            {
                                "string_value": "RESN"
                            }
                        ]
                    }
                ]
            }
        }
    ]
}

```

Hope this can help someone else in the future

---

<div class="post-metadata">

**Author:** ![hfj](https://avatars.discourse-cdn.com/v4/letter/h/c4cdca/32.png) [@hfj](https://forum.inductiveautomation.com/u/hfj)\
**Post date:** [August 21, 2023, 8:30am UTC](https://forum.inductiveautomation.com/t/read-write-update-dataset-tag-using-sparkplug-b/78022/9 "2023-08-21T08:30:28Z")

</div>

FWIW. I use this palette i NodeRed "node-red-contrib-mqtt-sparkplug-plus" then I don't have to worry about BIRTH/DEATH and encoding/decoding

---

<div class="post-metadata">

**Author:** ![Chad\_Gregory](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chad_gregory/32/51192_2.png) [@Chad\_Gregory](https://forum.inductiveautomation.com/u/Chad_Gregory)\
**Post date:** [August 21, 2023, 11:35am UTC](https://forum.inductiveautomation.com/t/read-write-update-dataset-tag-using-sparkplug-b/78022/10 "2023-08-21T11:35:56Z")

</div>

Yes I know about those I was using node-RED as a scratch pad to figure out payloads for my android application.

If you just need node-red then those nodes are the way to go.
