# MQTT Sparkplug B Issue

**URL:** https://discourse.nodered.org/t/mqtt-sparkplug-b-issue/67812
**Category:** General
**Created:** [16 September 2022 15:02 UTC](https://discourse.nodered.org/t/mqtt-sparkplug-b-issue/67812 "2022-09-16T15:02:02Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![JhonWayne](https://avatars.discourse-cdn.com/v4/letter/j/df705f/32.png) [@JhonWayne](https://discourse.nodered.org/u/JhonWayne)
#### Post date: [16 September 2022 15:02 UTC](https://discourse.nodered.org/t/mqtt-sparkplug-b-issue/67812/1 "2022-09-16T15:02:02Z")

</div>

Hi All, we appreciated that you can share all information about how we can use the node-red application. And following this, we have created a simple test for communicating through MQTT with two equipment but have the following issue.

 ![Node Red Issue](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/e/3e06888c23080c7ae9cf269c6ff1facb712ea8a0.jpeg)

We can send the Sparkplug message but when we want to check if the message is ok not come the last part of the message "Value" data.

We are using a Raspberry PI 4 with Mosquitto MQTT Broker and applying the Sparkplug codification into the node -red. To verify this we are using the same node-red application.

Could you please help us verify what is the error?

Many Thanks

```auto
[
    {
        "id": "e9a0d0f28d260b54",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "fb5b1839cdcb6c22",
        "type": "function",
        "z": "e9a0d0f28d260b54",
        "name": "Sparkplug B Message",
        "func": "msg.payload = {\n \"metrics\":\n [{\n \"name\":'Temp',\n \"alias\": 23,\n \"datatype\": 9,\n \"value\": msg.payload[0]\n }],\n \"seq\": 0\n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 680,
        "y": 240,
        "wires": [
            [
                "fb6e8fa3b2843b6c",
                "5a00beec7dfc8d25"
            ]
        ]
    },
    {
        "id": "5a00beec7dfc8d25",
        "type": "debug",
        "z": "e9a0d0f28d260b54",
        "name": "debug 1",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1020,
        "y": 240,
        "wires": []
    },
    {
        "id": "9b6e18d04c6d4d90",
        "type": "modbus-write",
        "z": "e9a0d0f28d260b54",
        "name": "TestWriteMDB",
        "showStatusActivities": true,
        "showErrors": false,
        "unitid": "1",
        "dataType": "MHoldingRegisters",
        "adr": "0",
        "quantity": "10",
        "server": "2ea27f71b146d1b4",
        "emptyMsgOnFail": false,
        "keepMsgProperties": true,
        "x": 820,
        "y": 380,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "46d1a911159a1260",
        "type": "random",
        "z": "e9a0d0f28d260b54",
        "name": "Random_Value",
        "low": "0",
        "high": "1000",
        "inte": "false",
        "property": "payload",
        "x": 320,
        "y": 340,
        "wires": [
            [
                "98ca7bcef0479bbc"
            ]
        ]
    },
    {
        "id": "45e41c801da5733e",
        "type": "inject",
        "z": "e9a0d0f28d260b54",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "1",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 150,
        "y": 340,
        "wires": [
            [
                "46d1a911159a1260"
            ]
        ]
    },
    {
        "id": "98ca7bcef0479bbc",
        "type": "function",
        "z": "e9a0d0f28d260b54",
        "name": "Holding_Register",
        "func": "var HR = msg.payload\nvar HRArray = []\n\nHRArray[0] = HR + 50 ;\nHRArray[1] = HR + 25 ; \nHRArray[2] = HR + 15;\nHRArray[3] = HR + 22;\nHRArray[4] = HR + 23;\nHRArray[5] = HR + 78;\nHRArray[6] = HR - 48;\nHRArray[7] = HR * 2 ;\nHRArray[8] = HR * 3;\nHRArray[9] = HR + 56;\n\nmsg.payload = HRArray\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 530,
        "y": 340,
        "wires": [
            [
                "9b6e18d04c6d4d90",
                "e75feb684135e32f",
                "fb5b1839cdcb6c22"
            ]
        ]
    },
    {
        "id": "e75feb684135e32f",
        "type": "debug",
        "z": "e9a0d0f28d260b54",
        "name": "debug 3",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 720,
        "y": 460,
        "wires": []
    },
    {
        "id": "6f2dc45a87d4ea68",
        "type": "debug",
        "z": "e9a0d0f28d260b54",
        "name": "debug 4",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 960,
        "y": 60,
        "wires": []
    },
    {
        "id": "faacc4911f97079f",
        "type": "mqtt in",
        "z": "e9a0d0f28d260b54",
        "name": "Receive_Data",
        "topic": "spBv1.0/Synertrex/DDATA/Test/#",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "cadb3065520d7ac4",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 210,
        "y": 580,
        "wires": [
            [
                "3107093fb3fa47c3",
                "351e433ca41eb930"
            ]
        ]
    },
    {
        "id": "3107093fb3fa47c3",
        "type": "debug",
        "z": "e9a0d0f28d260b54",
        "name": "debug 5",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 420,
        "y": 660,
        "wires": []
    },
    {
        "id": "2b18dfa09b6afe0e",
        "type": "debug",
        "z": "e9a0d0f28d260b54",
        "name": "debug 2",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 860,
        "y": 580,
        "wires": []
    },
    {
        "id": "351e433ca41eb930",
        "type": "decode",
        "z": "e9a0d0f28d260b54",
        "name": "sparkplug_b_decode",
        "protofile": "7a32d763db061211",
        "protoType": "Payload",
        "x": 460,
        "y": 580,
        "wires": [
            [
                "2b18dfa09b6afe0e"
            ]
        ]
    },
    {
        "id": "fb6e8fa3b2843b6c",
        "type": "encode",
        "z": "e9a0d0f28d260b54",
        "name": "sparkplug_b",
        "protofile": "a3eeaf7db6f73929",
        "protoType": "Payload",
        "x": 670,
        "y": 120,
        "wires": [
            [
                "6f2dc45a87d4ea68",
                "e2b912bfabb9e544"
            ]
        ]
    },
    {
        "id": "e2b912bfabb9e544",
        "type": "mqtt out",
        "z": "e9a0d0f28d260b54",
        "name": "Send_Data",
        "topic": "spBv1.0/Synertrex/DDATA/Test/4/",
        "qos": "2",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "cadb3065520d7ac4",
        "x": 1090,
        "y": 120,
        "wires": []
    },
    {
        "id": "2ea27f71b146d1b4",
        "type": "modbus-client",
        "name": "",
        "clienttype": "tcp",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "queueLogEnabled": false,
        "failureLogEnabled": true,
        "tcpHost": "192.168.28.101",
        "tcpPort": "502",
        "tcpType": "DEFAULT",
        "serialPort": "/dev/ttyUSB",
        "serialType": "RTU-BUFFERD",
        "serialBaudrate": "9600",
        "serialDatabits": "8",
        "serialStopbits": "1",
        "serialParity": "none",
        "serialConnectionDelay": "100",
        "serialAsciiResponseStartDelimiter": "0x3A",
        "unit_id": 1,
        "commandDelay": 1,
        "clientTimeout": 1000,
        "reconnectOnTimeout": true,
        "reconnectTimeout": 2000,
        "parallelUnitIdsAllowed": true
    },
    {
        "id": "cadb3065520d7ac4",
        "type": "mqtt-broker",
        "name": "MQTT_Server",
        "broker": "192.168.28.102",
        "port": "1883",
        "clientid": "Synertrex",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "spBv1.0/Synertrex/NBIRTH/",
        "birthQos": "1",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "spBv1.0/Synertrex/NDEATH/",
        "closeQos": "1",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    },
    {
        "id": "7a32d763db061211",
        "type": "protobuf-file",
        "protopath": "/home/synuser/sparkplugb/sparkplug_b.proto",
        "watchFile": true
    },
    {
        "id": "a3eeaf7db6f73929",
        "type": "protobuf-file",
        "protopath": "/home/synuser/sparkplugb/sparkplug_b.proto",
        "watchFile": true
    }
]

```

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [16 September 2022 15:48 UTC](https://discourse.nodered.org/t/mqtt-sparkplug-b-issue/67812/2 "2022-09-16T15:48:30Z")

</div>

> [@JhonWayne](#):
>
> We can send the Sparkplug message but when we want to check if the message is ok not come the last part of the message "Value" data.

Could you rephrase your question, because it is not entirely clear to me what the problem is, unless I am being mislead by the yellow highlight, is the second debug output the one that is missing `value` ? If yes, it probably did not receive a value and ends up empty, which gets omitted. Perhaps you meant: `msg.payload[0].metrics.value` instead ?

---

<div class="post-metadata">

### Author: ![JhonWayne](https://avatars.discourse-cdn.com/v4/letter/j/df705f/32.png) [@JhonWayne](https://discourse.nodered.org/u/JhonWayne)
#### Post date: [16 September 2022 19:26 UTC](https://discourse.nodered.org/t/mqtt-sparkplug-b-issue/67812/3 "2022-09-16T19:26:23Z")

</div>

Yeah, you are right. The question is, why the decoded value (debug 2) is not the same that the coded sent value (debug 4)? Why does the last data corresponding to the "value" doesn't appear in the decoded payload message (debug 2)?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/f/bf43affe680303dd91c735417996f1ba745fe292.png)

Thanks for your support.

---

<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: [15 November 2022 19:26 UTC](https://discourse.nodered.org/t/mqtt-sparkplug-b-issue/67812/4 "2022-11-15T19:26:54Z")

</div>

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