Multiple Payload in a single MQTT Node

Hi,

I don't want to use multiple MQTT Nodes in a single flow I want to send Status of level, date, last entered comment by using a single MQTT Node.

I am pasting my flow for 1 machine.

[
    {
        "id": "6a01a541.f7a77c",
        "type": "mqtt out",
        "z": "935db92.1ef9548",
        "name": "",
        "topic": "safety/inspection/forklift/status/fe01",
        "qos": "2",
        "retain": "true",
        "broker": "b90d0ecc.41907",
        "x": 800,
        "y": 180,
        "wires": []
    },
    {
        "id": "75a50af.9b05af4",
        "type": "comment",
        "z": "935db92.1ef9548",
        "name": "FE01",
        "info": "",
        "x": 690,
        "y": 100,
        "wires": []
    },
    {
        "id": "2a71eae6.099dc6",
        "type": "ui_date_picker",
        "z": "935db92.1ef9548",
        "name": "",
        "label": "",
        "group": "219d8573.b713ea",
        "order": 3,
        "width": "3",
        "height": 1,
        "passthru": true,
        "topic": "",
        "x": 415,
        "y": 100,
        "wires": [
            []
        ],
        "l": false
    },
    {
        "id": "5e008e58.239ec",
        "type": "ui_button",
        "z": "935db92.1ef9548",
        "name": "",
        "group": "219d8573.b713ea",
        "order": 4,
        "width": 3,
        "height": 1,
        "passthru": false,
        "label": "UPDATE",
        "tooltip": "",
        "color": "",
        "bgcolor": "GREY",
        "icon": "",
        "payload": "",
        "payloadType": "str",
        "topic": "",
        "x": 130,
        "y": 100,
        "wires": [
            [
                "54596040.fc245"
            ]
        ]
    },
    {
        "id": "54596040.fc245",
        "type": "change",
        "z": "935db92.1ef9548",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "$now()",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 300,
        "y": 100,
        "wires": [
            [
                "2a71eae6.099dc6"
            ]
        ]
    },
    {
        "id": "70bde481.0e65dc",
        "type": "ui_text_input",
        "z": "935db92.1ef9548",
        "name": "",
        "label": "Enter Comments Here",
        "tooltip": "",
        "group": "219d8573.b713ea",
        "order": 7,
        "width": 0,
        "height": 0,
        "passthru": true,
        "mode": "text",
        "delay": 300,
        "topic": "FP04",
        "x": 160,
        "y": 140,
        "wires": [
            []
        ]
    },
    {
        "id": "5767b7b0.555ca8",
        "type": "ui_svg_graphics",
        "z": "935db92.1ef9548",
        "group": "219d8573.b713ea",
        "order": 1,
        "width": 3,
        "height": 3,
        "svgString": "<svg width=\"100%\" height=\"100%\" enable-background=\"new 0 0 0 0\" xmlns=\"http://www.w3.org/2000/svg\">/svg> \n<image width=\"100%\" height=\"100%\"  xlink:href=\"http://10.20.233.241:1880/fe01.jpg\" />\n</svg>",
        "clickableShapes": [
            {
                "targetId": "#light_living",
                "action": "click",
                "payload": "light_living",
                "payloadType": "str",
                "topic": "light_living"
            },
            {
                "targetId": "r",
                "action": "click",
                "payload": "r",
                "payloadType": "str",
                "topic": "r"
            }
        ],
        "javascriptHandlers": [],
        "smilAnimations": [],
        "bindings": [],
        "showCoordinates": false,
        "autoFormatAfterEdit": false,
        "showBrowserErrors": true,
        "showBrowserEvents": false,
        "enableJsDebugging": false,
        "sendMsgWhenLoaded": false,
        "outputField": "payload",
        "editorUrl": "//drawsvg.org/drawsvg.html",
        "directory": "",
        "panning": "disabled",
        "zooming": "disabled",
        "panOnlyWhenZoomed": false,
        "doubleClickZoomEnabled": false,
        "mouseWheelZoomEnabled": false,
        "dblClickZoomPercentage": 150,
        "name": "",
        "x": 360,
        "y": 140,
        "wires": [
            []
        ]
    },
    {
        "id": "e96f7798.f090a8",
        "type": "ui_template",
        "z": "935db92.1ef9548",
        "group": "219d8573.b713ea",
        "name": "3-way switch",
        "order": 5,
        "width": 6,
        "height": 1,
        "format": "<div id=\"{{'swc_'+$id}}\" class=\"switchwrapper\">\n  <div class=\"toggle_radio\">\n    <input type=\"radio\" class=\"toggle_option toggle_3\" id=\"{{'first_'+$id}}\" ng-model=\"value\" value=\"first\">\n    <input type=\"radio\" class=\"toggle_option toggle_3\" id=\"{{'second_'+$id}}\" ng-model=\"value\" value=\"second\">\n    <input type=\"radio\" class=\"toggle_option toggle_3\" id=\"{{'third_'+$id}}\" ng-model=\"value\" value=\"third\">\n    <div id=\"{{'slider_'+$id}}\" class=\"toggle_option_slider toggle_3\"></div>\n    <label class=\" toggle_3\" for=\"{{'first_'+$id}}\"><p>Good</p></label>\n    <label class=\" toggle_3\" for=\"{{'second_'+$id}}\"><p>Need Service</p></label>\n    <label class=\" toggle_3\" for=\"{{'third_'+$id}}\"><p>Out Of Service</p></label>\n  </div>\n  \n</div>\n\n<script>\n(function(scope) {\n    scope.incomingChange = false\n    scope.$watch('value', function(value) {\n        switch(value){\n            case 'first':{\n                $(\"#slider_\"+scope.$id).css(\"left\", \"3px\")\n                break\n            }\n            case 'second':{\n                $(\"#slider_\"+scope.$id).css(\"left\", \"33%\")\n                break\n            }\n            case 'third':{\n                $(\"#slider_\"+scope.$id).css(\"left\", \"66%\")\n                break\n            }\n        }\n        if(scope.incomingChange == true){\n            scope.incomingChange = false\n            return\n        }\n        if(!value){\n            return\n        }\n        scope.send({payload: value})\n       \n    });\n    scope.$watch('msg', function(msg) {\n        if(msg){\n            if(scope.value != msg.payload){\n                scope.incomingChange = true\n                scope.value = msg.payload\n            }\n            \n        }\n    });\n})(scope);\n</script>\n  \n",
        "storeOutMessages": true,
        "fwdInMessages": true,
        "resendOnRefresh": true,
        "templateScope": "local",
        "x": 370,
        "y": 200,
        "wires": [
            [
                "43a348e6.b35c48",
                "e9bb3172.4a74a"
            ]
        ]
    },
    {
        "id": "43a348e6.b35c48",
        "type": "debug",
        "z": "935db92.1ef9548",
        "name": "Selected option",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "x": 540,
        "y": 180,
        "wires": []
    },
    {
        "id": "b1dbfe36.7d4c7",
        "type": "inject",
        "z": "935db92.1ef9548",
        "name": "Select first",
        "topic": "",
        "payload": "Out of Service",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 140,
        "y": 180,
        "wires": [
            [
                "e96f7798.f090a8"
            ]
        ]
    },
    {
        "id": "73ab2b04.341e54",
        "type": "inject",
        "z": "935db92.1ef9548",
        "name": "Select second",
        "topic": "",
        "payload": "Need service",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 130,
        "y": 220,
        "wires": [
            [
                "e96f7798.f090a8"
            ]
        ]
    },
    {
        "id": "230a25c3.d2197a",
        "type": "inject",
        "z": "935db92.1ef9548",
        "name": "Select third",
        "topic": "",
        "payload": "Good",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 140,
        "y": 260,
        "wires": [
            [
                "e96f7798.f090a8"
            ]
        ]
    },
    {
        "id": "e9bb3172.4a74a",
        "type": "change",
        "z": "935db92.1ef9548",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "first",
                "fromt": "str",
                "to": "1",
                "tot": "num"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "second",
                "fromt": "str",
                "to": "2",
                "tot": "num"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "third",
                "fromt": "str",
                "to": "3",
                "tot": "num"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 540,
        "y": 220,
        "wires": [
            [
                "6a01a541.f7a77c",
                "b28d4d7d.42cc4"
            ]
        ]
    },
    {
        "id": "b28d4d7d.42cc4",
        "type": "ui_level",
        "z": "935db92.1ef9548",
        "group": "219d8573.b713ea",
        "order": 6,
        "width": 0,
        "height": 0,
        "name": "",
        "label": "",
        "colorHi": "#f90101",
        "colorWarn": "#ff0000",
        "colorNormal": "#ffff00",
        "colorOff": "#00ff00",
        "min": "1",
        "max": "3",
        "segWarn": "",
        "segHigh": "",
        "unit": "",
        "layout": "sh",
        "channelA": "",
        "channelB": "",
        "decimals": 0,
        "animations": "soft",
        "shape": "3",
        "colorschema": "valuedriven",
        "textoptions": "default",
        "colorText": "#eeeeee",
        "fontLabel": "kklnkl",
        "fontValue": "",
        "fontSmall": "",
        "colorFromTheme": true,
        "textAnimations": false,
        "hideValue": true,
        "tickmode": "off",
        "peakmode": false,
        "property": "payload",
        "peaktime": 3000,
        "x": 710,
        "y": 240,
        "wires": []
    },
    {
        "id": "6137256a.c1127c",
        "type": "mqtt in",
        "z": "935db92.1ef9548",
        "name": "",
        "topic": "safety/inspection/forklift/status/fe01",
        "qos": "2",
        "datatype": "auto",
        "broker": "b90d0ecc.41907",
        "x": 480,
        "y": 260,
        "wires": [
            [
                "b28d4d7d.42cc4"
            ]
        ]
    },
    {
        "id": "b90d0ecc.41907",
        "type": "mqtt-broker",
        "z": "",
        "name": "",
        "broker": "test.mosquitto.org",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": false,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    },
    {
        "id": "219d8573.b713ea",
        "type": "ui_group",
        "z": "",
        "name": "FE - 01",
        "tab": "520d4e1.6420bb",
        "order": 2,
        "disp": true,
        "width": 6,
        "collapse": false
    },
    {
        "id": "520d4e1.6420bb",
        "type": "ui_tab",
        "z": "",
        "name": "FORKLIFTS",
        "icon": "dashboard",
        "order": 2,
        "disabled": false,
        "hidden": false
    }
]

If i use different Node for each massage then i have to use 4 MQTT nodes per machine and i have 50 machines, i will end us in using 200 MQTT nodes with different topics.

Any Suggestions!

Then dont set the topic, send a dynamic topic in msg.topic.

Sorry I don't get it what are you trying to say.

leave topic empty

image

^ obviously i am using injects - but you can set msg.topic in a function or a change node or whatever you like

1 Like

Can i send different kind of payloads though this method. I mean i need to send a level, a string and date through a same mqtt node. Sorry i am new and still trying to get it done.

I feel you do not fully understand how MQTT is used, I suggest you start by working this MQTT Essentials guide will will give you a lot of useful knowledge. Then the suggestions made earlier should make more sense to you I think.

Still learning this myself, but look at using wild cards, you could have it listen for all messages for that particular item.

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