# How to publish MQTT Sparkplug B message

**URL:** <https://discourse.nodered.org/t/how-to-publish-mqtt-sparkplug-b-message/87444>\
**Category:** General\
**Created:** [23 April 2024 22:02 UTC](https://discourse.nodered.org/t/how-to-publish-mqtt-sparkplug-b-message/87444 "2024-04-23T22:02:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Garrian](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@Garrian](https://discourse.nodered.org/u/Garrian)\
**Post date:** [23 April 2024 22:02 UTC](https://discourse.nodered.org/t/how-to-publish-mqtt-sparkplug-b-message/87444/1 "2024-04-23T22:02:54Z")

</div>

Hi there,

I'm trying to publish a Sparkplug B message from node-red, but I don't get how I'm supposed to do that. This is my flow:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/c/9c3a9f7782507434f47138e733f0e10a5899039d.png)

```auto
msg.topic = "spBv1.0/namespace/group/device/edgeNode/sensor1";
msg.payload = {
    "bn": "sensor1/",
    "n": "value",
    "t": 1,
    "v": Math.random() * 100
};
return msg;

```

But, the output I get in the debug is this:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/6/a62a7631de715f2e7c1d206119a80673cac9272d.png)

---

<div class="post-metadata">

**Author:** ![iiLaw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iilaw/32/14782_2.png) [@iiLaw](https://discourse.nodered.org/u/iiLaw)\
**Post date:** [7 May 2024 18:37 UTC](https://discourse.nodered.org/t/how-to-publish-mqtt-sparkplug-b-message/87444/2 "2024-05-07T18:37:00Z")

</div>

I'm very new to sparkplug but this works for me

```auto
let seq = flow.get('seq') || 1
msg.topic = "spBv1.0/FactoryA/DDATA/ProductionLine03/dev04a"
msg.payload = {}
msg.payload.timestamp = new Date().getTime()
msg.payload.seq = seq
msg.payload.metrics = [
        {
            "name": "externalTemperature",
            "value": 14.1,
            "type": "Float"
        },
        {
            "name": "humidity",
            "value": 88,
            "type": "UInt16"
        },
        {
            "name": "pressure",
            "value": 77,
            "type": "UInt16"
        },
        {
            "name": "temperature",
            "value": 22.2,
            "type": "Float"
        }
    ]
seq++
flow.set('seq',seq)
return msg

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 August 2024 18:37 UTC](https://discourse.nodered.org/t/how-to-publish-mqtt-sparkplug-b-message/87444/3 "2024-08-05T18:37:30Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
